]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix race condition on ml2 delete and update port methods
authorEugene Nikanorov <enikanorov@mirantis.com>
Thu, 9 Jan 2014 09:23:02 +0000 (13:23 +0400)
committerEugene Nikanorov <enikanorov@mirantis.com>
Fri, 10 Jan 2014 06:18:17 +0000 (10:18 +0400)
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

index 82a93fb4bcf9f3d04066fba2ca5f3da6e6c8d05e..7b78ac1f031fe034f461863a56ce21522cd8e4a2 100644 (file)
@@ -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)