From d9bcd597c67900472709cd11604afe1616e0af4e Mon Sep 17 00:00:00 2001 From: Eugene Nikanorov Date: Thu, 9 Jan 2014 13:23:02 +0400 Subject: [PATCH] Fix race condition on ml2 delete and update port methods Synchronize access to ports table when deleting and updating a port. Otherwise concurrent update/delete request for the same port may cause neutron server to throw an exception and return '500 Internal server error' for such requests. Change-Id: I868002643147ce6baace5671cffb38b4f5e66729 Closes-Bug: #1266537 --- neutron/plugins/ml2/plugin.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/neutron/plugins/ml2/plugin.py b/neutron/plugins/ml2/plugin.py index 82a93fb4b..7b78ac1f0 100644 --- a/neutron/plugins/ml2/plugin.py +++ b/neutron/plugins/ml2/plugin.py @@ -589,7 +589,10 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2, session = context.session changed_fixed_ips = 'fixed_ips' in port['port'] with session.begin(subtransactions=True): - original_port = super(Ml2Plugin, self).get_port(context, id) + port_db = (session.query(models_v2.Port). + enable_eagerloads(False). + filter_by(id=id).with_lockmode('update').one()) + original_port = self._make_port_dict(port_db) updated_port = super(Ml2Plugin, self).update_port(context, id, port) if self.is_address_pairs_attribute_updated(original_port, port): @@ -641,7 +644,11 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2, with session.begin(subtransactions=True): if l3plugin: l3plugin.disassociate_floatingips(context, id) - port = self.get_port(context, id) + port_db = (session.query(models_v2.Port). + enable_eagerloads(False). + filter_by(id=id).with_lockmode('update').one()) + port = self._make_port_dict(port_db) + network = self.get_network(context, port['network_id']) mech_context = driver_context.PortContext(self, context, port, network) -- 2.45.2