From: Eugene Nikanorov Date: Thu, 9 Jan 2014 09:23:02 +0000 (+0400) Subject: Fix race condition on ml2 delete and update port methods X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=d9bcd597c67900472709cd11604afe1616e0af4e;p=openstack-build%2Fneutron-build.git 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 --- 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)