Merge "Add retries to update trunk port" into stable/queens

This commit is contained in:
Zuul 2020-01-30 04:20:01 +00:00 committed by Gerrit Code Review
commit 961c3f2120
1 changed files with 28 additions and 22 deletions

View File

@ -102,28 +102,10 @@ class TrunkSkeleton(object):
return updated_ports return updated_ports
def update_trunk_status(self, context, trunk_id, status): def _safe_update_trunk(self, trunk, **kwargs):
"""Update the trunk status to reflect outcome of data plane wiring."""
with db_api.autonested_transaction(context.session):
trunk = trunk_objects.Trunk.get_object(context, id=trunk_id)
if trunk:
trunk.update(status=status)
def _process_trunk_subport_bindings(self, context, trunk, port_ids):
"""Process port bindings for subports on the given trunk."""
updated_ports = []
trunk_port_id = trunk.port_id
trunk_port = self.core_plugin.get_port(context, trunk_port_id)
trunk_host = trunk_port.get(portbindings.HOST_ID)
for try_cnt in range(db_api.MAX_RETRIES): for try_cnt in range(db_api.MAX_RETRIES):
try: try:
# NOTE(status_police) Set the trunk in BUILD state before trunk.update(**kwargs)
# processing subport bindings. The trunk will stay in BUILD
# state until an attempt has been made to bind all subports
# passed here and the agent acknowledges the operation was
# successful.
trunk.update(status=trunk_consts.BUILD_STATUS)
break break
except exc.StaleDataError as e: except exc.StaleDataError as e:
if try_cnt < db_api.MAX_RETRIES - 1: if try_cnt < db_api.MAX_RETRIES - 1:
@ -133,6 +115,28 @@ class TrunkSkeleton(object):
# re-raise when all tries failed # re-raise when all tries failed
raise raise
def update_trunk_status(self, context, trunk_id, status):
"""Update the trunk status to reflect outcome of data plane wiring."""
with db_api.autonested_transaction(context.session):
trunk = trunk_objects.Trunk.get_object(context, id=trunk_id)
if trunk:
self._safe_update_trunk(trunk, status=status)
def _process_trunk_subport_bindings(self, context, trunk, port_ids):
"""Process port bindings for subports on the given trunk."""
updated_ports = []
trunk_port_id = trunk.port_id
trunk_port = self.core_plugin.get_port(context, trunk_port_id)
trunk_host = trunk_port.get(portbindings.HOST_ID)
# NOTE(status_police) Set the trunk in BUILD state before
# processing subport bindings. The trunk will stay in BUILD
# state until an attempt has been made to bind all subports
# passed here and the agent acknowledges the operation was
# successful.
self._safe_update_trunk(
trunk, status=trunk_consts.BUILD_STATUS)
for port_id in port_ids: for port_id in port_ids:
try: try:
updated_port = self._handle_port_binding(context, port_id, updated_port = self._handle_port_binding(context, port_id,
@ -146,7 +150,8 @@ class TrunkSkeleton(object):
# NOTE(status_police) The subport binding has failed in a # NOTE(status_police) The subport binding has failed in a
# manner in which we cannot proceed and the user must take # manner in which we cannot proceed and the user must take
# action to bring the trunk back to a sane state. # action to bring the trunk back to a sane state.
trunk.update(status=trunk_consts.ERROR_STATUS) self._safe_update_trunk(
trunk, status=trunk_consts.ERROR_STATUS)
return [] return []
except Exception as e: except Exception as e:
msg = ("Failed to bind subport port %(port)s on trunk " msg = ("Failed to bind subport port %(port)s on trunk "
@ -154,7 +159,8 @@ class TrunkSkeleton(object):
LOG.error(msg, {'port': port_id, 'trunk': trunk.id, 'exc': e}) LOG.error(msg, {'port': port_id, 'trunk': trunk.id, 'exc': e})
if len(port_ids) != len(updated_ports): if len(port_ids) != len(updated_ports):
trunk.update(status=trunk_consts.DEGRADED_STATUS) self._safe_update_trunk(
trunk, status=trunk_consts.DEGRADED_STATUS)
return updated_ports return updated_ports