Merge "Ignore PortNotFound exceptions on lockless delete"
This commit is contained in:
commit
ec03ef7010
@ -1424,7 +1424,13 @@ class NeutronDbPluginV2(neutron_plugin_base_v2.NeutronPluginBaseV2,
|
|||||||
query = query.filter(models_v2.Port.network_id == network_id)
|
query = query.filter(models_v2.Port.network_id == network_id)
|
||||||
port_ids = [p[0] for p in query]
|
port_ids = [p[0] for p in query]
|
||||||
for port_id in port_ids:
|
for port_id in port_ids:
|
||||||
self.delete_port(context, port_id)
|
try:
|
||||||
|
self.delete_port(context, port_id)
|
||||||
|
except n_exc.PortNotFound:
|
||||||
|
# Don't raise if something else concurrently deleted the port
|
||||||
|
LOG.debug(_("Ignoring PortNotFound when deleting port '%s'. "
|
||||||
|
"The port has already been deleted."),
|
||||||
|
port_id)
|
||||||
|
|
||||||
def _delete_port(self, context, id):
|
def _delete_port(self, context, id):
|
||||||
query = (context.session.query(models_v2.Port).
|
query = (context.session.query(models_v2.Port).
|
||||||
|
@ -862,6 +862,10 @@ class TestCiscoPortsV2(CiscoNetworkPluginV2TestCase,
|
|||||||
plugin_ref = self._get_plugin_ref()
|
plugin_ref = self._get_plugin_ref()
|
||||||
self._test_delete_ports_by_device_id_second_call_failure(plugin_ref)
|
self._test_delete_ports_by_device_id_second_call_failure(plugin_ref)
|
||||||
|
|
||||||
|
def test_delete_ports_ignores_port_not_found(self):
|
||||||
|
plugin_ref = self._get_plugin_ref()
|
||||||
|
self._test_delete_ports_ignores_port_not_found(plugin_ref)
|
||||||
|
|
||||||
|
|
||||||
class TestCiscoNetworksV2(CiscoNetworkPluginV2TestCase,
|
class TestCiscoNetworksV2(CiscoNetworkPluginV2TestCase,
|
||||||
test_db_plugin.TestNetworksV2):
|
test_db_plugin.TestNetworksV2):
|
||||||
|
@ -1711,6 +1711,31 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s
|
|||||||
plugin = NeutronManager.get_plugin()
|
plugin = NeutronManager.get_plugin()
|
||||||
self._test_delete_ports_by_device_id_second_call_failure(plugin)
|
self._test_delete_ports_by_device_id_second_call_failure(plugin)
|
||||||
|
|
||||||
|
def _test_delete_ports_ignores_port_not_found(self, plugin):
|
||||||
|
ctx = context.get_admin_context()
|
||||||
|
with self.subnet() as subnet:
|
||||||
|
with contextlib.nested(
|
||||||
|
self.port(subnet=subnet, device_id='owner1'),
|
||||||
|
mock.patch.object(plugin, 'delete_port')
|
||||||
|
) as (p, del_port):
|
||||||
|
del_port.side_effect = n_exc.PortNotFound(
|
||||||
|
port_id=p['port']['id']
|
||||||
|
)
|
||||||
|
network_id = subnet['subnet']['network_id']
|
||||||
|
try:
|
||||||
|
plugin.delete_ports_by_device_id(ctx, 'owner1',
|
||||||
|
network_id)
|
||||||
|
except n_exc.PortNotFound:
|
||||||
|
self.fail("delete_ports_by_device_id unexpectedly raised "
|
||||||
|
"a PortNotFound exception. It should ignore "
|
||||||
|
"this exception because it is often called at "
|
||||||
|
"the same time other concurrent operations are "
|
||||||
|
"deleting some of the same ports.")
|
||||||
|
|
||||||
|
def test_delete_ports_ignores_port_not_found(self):
|
||||||
|
plugin = NeutronManager.get_plugin()
|
||||||
|
self._test_delete_ports_ignores_port_not_found(plugin)
|
||||||
|
|
||||||
|
|
||||||
class TestNetworksV2(NeutronDbPluginV2TestCase):
|
class TestNetworksV2(NeutronDbPluginV2TestCase):
|
||||||
# NOTE(cerberus): successful network update and delete are
|
# NOTE(cerberus): successful network update and delete are
|
||||||
|
Loading…
x
Reference in New Issue
Block a user