]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Handle ObjectDeletedError when deleting network ports/subnets
authorOleg Bondarev <obondarev@mirantis.com>
Thu, 10 Sep 2015 07:51:10 +0000 (10:51 +0300)
committerOleg Bondarev <obondarev@mirantis.com>
Thu, 10 Sep 2015 07:52:35 +0000 (10:52 +0300)
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
neutron/tests/unit/plugins/ml2/test_plugin.py

index d9e567ed317cb6f4d54dfed7c50558eee00111f4..a8736567bb15d748cdba7f8e44e793605552d943 100644 (file)
@@ -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:
index 7dc84b50c412f563a667098578f503ccf8b3564f..7fd1299d84cbb8c918bb20a384917b159fd8d883 100644 (file)
@@ -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