Merge "Handle ObjectDeletedError when deleting network ports/subnets"

This commit is contained in:
Jenkins 2015-09-13 07:22:34 +00:00 committed by Gerrit Code Review
commit ce41cc5deb
2 changed files with 11 additions and 2 deletions

View 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:

View 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