for port in ports:
try:
self.delete_port(context, port.id)
- except exc.PortNotFound:
+ except (exc.PortNotFound, sa_exc.ObjectDeletedError):
+ context.session.expunge(port)
# 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)
for subnet in subnets:
try:
self.delete_subnet(context, subnet.id)
- except exc.SubnetNotFound:
+ except (exc.SubnetNotFound, sa_exc.ObjectDeletedError):
+ context.session.expunge(subnet)
LOG.info(_LI("Subnet %s was deleted concurrently"),
subnet.id)
except Exception:
import fixtures
from oslo_db import exception as db_exc
+from sqlalchemy.orm import exc as sqla_exc
from neutron.callbacks import registry
from neutron.common import constants
plugin = manager.NeutronManager.get_plugin()
with mock.patch.object(plugin, "delete_port",
side_effect=exc.PortNotFound(port_id="123")):
- plugin._delete_ports(None, [mock.MagicMock()])
+ 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(None, [mock.MagicMock()])
+ 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):