Merge "Revert "Use writer for trunk database operations""

This commit is contained in:
Zuul 2018-01-15 16:15:44 +00:00 committed by Gerrit Code Review
commit d6ed41f63b
2 changed files with 6 additions and 6 deletions

View File

@ -221,7 +221,7 @@ class TrunkPlugin(service_base.ServicePluginBase,
port_id=trunk['port_id'], port_id=trunk['port_id'],
status=constants.DOWN_STATUS, status=constants.DOWN_STATUS,
sub_ports=sub_ports) sub_ports=sub_ports)
with db_api.context_manager.writer.using(context): with db_api.autonested_transaction(context.session):
trunk_obj.create() trunk_obj.create()
payload = callbacks.TrunkPayload(context, trunk_obj.id, payload = callbacks.TrunkPayload(context, trunk_obj.id,
current_trunk=trunk_obj) current_trunk=trunk_obj)
@ -236,7 +236,7 @@ class TrunkPlugin(service_base.ServicePluginBase,
def update_trunk(self, context, trunk_id, trunk): def update_trunk(self, context, trunk_id, trunk):
"""Update information for the specified trunk.""" """Update information for the specified trunk."""
trunk_data = trunk['trunk'] trunk_data = trunk['trunk']
with db_api.context_manager.writer.using(context): with db_api.autonested_transaction(context.session):
trunk_obj = self._get_trunk(context, trunk_id) trunk_obj = self._get_trunk(context, trunk_id)
original_trunk = copy.deepcopy(trunk_obj) original_trunk = copy.deepcopy(trunk_obj)
# NOTE(status_police): a trunk status should not change during an # NOTE(status_police): a trunk status should not change during an
@ -256,7 +256,7 @@ class TrunkPlugin(service_base.ServicePluginBase,
def delete_trunk(self, context, trunk_id): def delete_trunk(self, context, trunk_id):
"""Delete the specified trunk.""" """Delete the specified trunk."""
with db_api.context_manager.writer.using(context): with db_api.autonested_transaction(context.session):
trunk = self._get_trunk(context, trunk_id) trunk = self._get_trunk(context, trunk_id)
rules.trunk_can_be_managed(context, trunk) rules.trunk_can_be_managed(context, trunk)
trunk_port_validator = rules.TrunkPortValidator(trunk.port_id) trunk_port_validator = rules.TrunkPortValidator(trunk.port_id)
@ -278,7 +278,7 @@ class TrunkPlugin(service_base.ServicePluginBase,
@db_base_plugin_common.convert_result_to_dict @db_base_plugin_common.convert_result_to_dict
def add_subports(self, context, trunk_id, subports): def add_subports(self, context, trunk_id, subports):
"""Add one or more subports to trunk.""" """Add one or more subports to trunk."""
with db_api.context_manager.writer.using(context): with db_api.autonested_transaction(context.session):
trunk = self._get_trunk(context, trunk_id) trunk = self._get_trunk(context, trunk_id)
# Check for basic validation since the request body here is not # Check for basic validation since the request body here is not
@ -332,7 +332,7 @@ class TrunkPlugin(service_base.ServicePluginBase,
def remove_subports(self, context, trunk_id, subports): def remove_subports(self, context, trunk_id, subports):
"""Remove one or more subports from trunk.""" """Remove one or more subports from trunk."""
subports = subports['sub_ports'] subports = subports['sub_ports']
with db_api.context_manager.writer.using(context): with db_api.autonested_transaction(context.session):
trunk = self._get_trunk(context, trunk_id) trunk = self._get_trunk(context, trunk_id)
original_trunk = copy.deepcopy(trunk) original_trunk = copy.deepcopy(trunk)
rules.trunk_can_be_managed(context, trunk) rules.trunk_can_be_managed(context, trunk)

View File

@ -103,7 +103,7 @@ class TrunkSkeleton(object):
def update_trunk_status(self, context, trunk_id, status): def update_trunk_status(self, context, trunk_id, status):
"""Update the trunk status to reflect outcome of data plane wiring.""" """Update the trunk status to reflect outcome of data plane wiring."""
with db_api.context_manager.writer.using(context): with db_api.autonested_transaction(context.session):
trunk = trunk_objects.Trunk.get_object(context, id=trunk_id) trunk = trunk_objects.Trunk.get_object(context, id=trunk_id)
if trunk: if trunk:
trunk.update(status=status) trunk.update(status=status)