From 29ac69ebe365b597ad5d1510381d3f02643edb3e Mon Sep 17 00:00:00 2001 From: Oleg Bondarev Date: Thu, 10 Sep 2015 10:51:10 +0300 Subject: [PATCH] Handle ObjectDeletedError when deleting network ports/subnets It appeared there is still a race on port deletion when deleting networks. So commit a55e10cfd6369533f0cc22edd6611c9549b8f1b4 introduced a regression. It's a bit of ironic that commit message was "Avoid DB errors when deleting network's ports and subnets". Shame on me! Closes-Bug: #1494157 Change-Id: I37727eca5d68e6440f0f93e0f6bbe63b2f18b443 --- neutron/plugins/ml2/plugin.py | 4 ++-- neutron/tests/unit/plugins/ml2/test_plugin.py | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/neutron/plugins/ml2/plugin.py b/neutron/plugins/ml2/plugin.py index d9e567ed3..a8736567b 100644 --- a/neutron/plugins/ml2/plugin.py +++ b/neutron/plugins/ml2/plugin.py @@ -712,7 +712,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2, for port_id in port_ids: try: self.delete_port(context, port_id) - except exc.PortNotFound: + except (exc.PortNotFound, sa_exc.ObjectDeletedError): # concurrent port deletion can be performed by # release_dhcp_port caused by concurrent subnet_delete LOG.info(_LI("Port %s was deleted concurrently"), port_id) @@ -725,7 +725,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2, for subnet_id in subnet_ids: try: self.delete_subnet(context, subnet_id) - except exc.SubnetNotFound: + except (exc.SubnetNotFound, sa_exc.ObjectDeletedError): LOG.info(_LI("Subnet %s was deleted concurrently"), subnet_id) except Exception: diff --git a/neutron/tests/unit/plugins/ml2/test_plugin.py b/neutron/tests/unit/plugins/ml2/test_plugin.py index 7dc84b50c..7fd1299d8 100644 --- a/neutron/tests/unit/plugins/ml2/test_plugin.py +++ b/neutron/tests/unit/plugins/ml2/test_plugin.py @@ -24,6 +24,7 @@ import webob from oslo_db import exception as db_exc from oslo_utils import uuidutils +from sqlalchemy.orm import exc as sqla_exc from neutron.callbacks import registry from neutron.common import constants @@ -220,12 +221,20 @@ class TestMl2NetworksV2(test_plugin.TestNetworksV2, side_effect=exc.PortNotFound(port_id="123")): plugin._delete_ports(mock.MagicMock(), [mock.MagicMock()]) + with mock.patch.object(plugin, "delete_port", + side_effect=sqla_exc.ObjectDeletedError(None)): + plugin._delete_ports(mock.MagicMock(), [mock.MagicMock()]) + def test_subnet_delete_helper_tolerates_failure(self): plugin = manager.NeutronManager.get_plugin() with mock.patch.object(plugin, "delete_subnet", side_effect=exc.SubnetNotFound(subnet_id="1")): plugin._delete_subnets(mock.MagicMock(), [mock.MagicMock()]) + with mock.patch.object(plugin, "delete_subnet", + side_effect=sqla_exc.ObjectDeletedError(None)): + plugin._delete_subnets(mock.MagicMock(), [mock.MagicMock()]) + def _create_and_verify_networks(self, networks): for net_idx, net in enumerate(networks): # create -- 2.45.2