diff --git a/neutron/plugins/common/utils.py b/neutron/plugins/common/utils.py index 2da1d47b144..87f69f03477 100644 --- a/neutron/plugins/common/utils.py +++ b/neutron/plugins/common/utils.py @@ -192,6 +192,8 @@ def delete_port_on_error(core_plugin, context, port_id): try: core_plugin.delete_port(context, port_id, l3_port_check=False) + except exceptions.PortNotFound: + LOG.debug("Port %s not found", port_id) except Exception: LOG.exception(_LE("Failed to delete port: %s"), port_id) diff --git a/neutron/tests/unit/plugins/common/test_utils.py b/neutron/tests/unit/plugins/common/test_utils.py index 222e23a271a..4ce6faffe14 100644 --- a/neutron/tests/unit/plugins/common/test_utils.py +++ b/neutron/tests/unit/plugins/common/test_utils.py @@ -16,6 +16,7 @@ import hashlib import mock from neutron_lib import constants +from neutron_lib import exceptions import testtools from neutron.db import l3_db @@ -92,6 +93,17 @@ class TestUtils(base.BaseTestCase): core_plugin.delete_port.assert_called_once_with(context, port_id, l3_port_check=False) + def test_delete_port_on_error_port_does_not_exist(self): + core_plugin, context = mock.Mock(), mock.Mock() + port_id = 'pid' + core_plugin.delete_port.side_effect = exceptions.PortNotFound( + port_id=port_id) + with testtools.ExpectedException(exceptions.PortNotFound): + with utils.delete_port_on_error(core_plugin, context, port_id): + raise exceptions.PortNotFound(port_id=port_id) + core_plugin.delete_port.assert_called_once_with(context, port_id, + l3_port_check=False) + @mock.patch.object(l3_db.L3_NAT_dbonly_mixin, '_check_router_port') def test_update_port_on_error(self, mock_check): core_plugin, context = mock.Mock(), mock.Mock()