From: Eugene Nikanorov Date: Mon, 13 Jan 2014 14:58:59 +0000 (+0400) Subject: Fix race condition in delete_port method. Fix update_port method X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=635e9b10da439dec36d99d911472e9196392a3ff;p=openstack-build%2Fneutron-build.git Fix race condition in delete_port method. Fix update_port method Port can be gone between l3plugin.prevent_l3_port_deletion(context, id) and port query. Need to handle it properly. ALso need to handle non-existing port in update_port properly. Closes-Bug: #1266537 Change-Id: Ic203f21db277f83c604a8757a8c421b3fb9ae709 --- diff --git a/neutron/plugins/ml2/plugin.py b/neutron/plugins/ml2/plugin.py index 7b78ac1f0..fe3dfb44f 100644 --- a/neutron/plugins/ml2/plugin.py +++ b/neutron/plugins/ml2/plugin.py @@ -589,9 +589,12 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2, session = context.session changed_fixed_ips = 'fixed_ips' in port['port'] with session.begin(subtransactions=True): - port_db = (session.query(models_v2.Port). - enable_eagerloads(False). - filter_by(id=id).with_lockmode('update').one()) + try: + port_db = (session.query(models_v2.Port). + enable_eagerloads(False). + filter_by(id=id).with_lockmode('update').one()) + except sql_exc.NoResultFound: + raise exc.PortNotFound(port_id=id) original_port = self._make_port_dict(port_db) updated_port = super(Ml2Plugin, self).update_port(context, id, port) @@ -644,9 +647,15 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2, with session.begin(subtransactions=True): if l3plugin: l3plugin.disassociate_floatingips(context, id) - port_db = (session.query(models_v2.Port). - enable_eagerloads(False). - filter_by(id=id).with_lockmode('update').one()) + try: + port_db = (session.query(models_v2.Port). + enable_eagerloads(False). + filter_by(id=id).with_lockmode('update').one()) + except sql_exc.NoResultFound: + # the port existed when l3plugin.prevent_l3_port_deletion + # was called but now is already gone + LOG.debug(_("The port '%s' was deleted"), id) + return port = self._make_port_dict(port_db) network = self.get_network(context, port['network_id'])