From 4f5b01c18b66e9f456150ceed08e8f0264499d7e Mon Sep 17 00:00:00 2001 From: Kevin Benton Date: Fri, 30 Jan 2015 12:53:57 -0800 Subject: [PATCH] Make prevent_l3_port_deletion handle missing port This adjusts the prevent_l3_port_deletion function to handle the case where the port ID that is passed to it does not have an entry in the database. Previously it was raising an exception in this case, which is inconsistent to how ML2 was handling concurrent port_delete requests further in the port delete function (log them but don't fail). Closes-Bug: #1416554 Change-Id: I6da021bdf0c79f72336416d02ab989407f352904 --- neutron/db/l3_db.py | 6 +++++- neutron/plugins/ml2/plugin.py | 2 -- neutron/tests/unit/test_l3_plugin.py | 8 +++++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/neutron/db/l3_db.py b/neutron/db/l3_db.py index 569bc8f6a..3176d89bb 100644 --- a/neutron/db/l3_db.py +++ b/neutron/db/l3_db.py @@ -943,7 +943,11 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase): to /ports, but rather via other API calls that perform the proper deletion checks. """ - port_db = self._core_plugin._get_port(context, port_id) + try: + port_db = self._core_plugin._get_port(context, port_id) + except n_exc.PortNotFound: + # non-existent ports don't need to be protected from deletion + return if port_db['device_owner'] in self.router_device_owners: # Raise port in use only if the port has IP addresses # Otherwise it's a stale port that can be removed diff --git a/neutron/plugins/ml2/plugin.py b/neutron/plugins/ml2/plugin.py index 4a352b61e..8fe59dedb 100644 --- a/neutron/plugins/ml2/plugin.py +++ b/neutron/plugins/ml2/plugin.py @@ -1111,8 +1111,6 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2, session.begin(subtransactions=True)): port_db, binding = db.get_locked_port_and_binding(session, id) if not port_db: - # the port existed when l3plugin.prevent_l3_port_deletion - # was called but now is already gone LOG.debug("The port '%s' was deleted", id) return port = self._make_port_dict(port_db) diff --git a/neutron/tests/unit/test_l3_plugin.py b/neutron/tests/unit/test_l3_plugin.py index 33a77eae6..2f74c87bd 100644 --- a/neutron/tests/unit/test_l3_plugin.py +++ b/neutron/tests/unit/test_l3_plugin.py @@ -2409,4 +2409,10 @@ class L3NatDBIntTestCase(L3BaseForIntTests, L3NatTestCaseBase): class L3NatDBSepTestCase(L3BaseForSepTests, L3NatTestCaseBase): """Unit tests for a separate L3 routing service plugin.""" - pass + + def test_port_deletion_prevention_handles_missing_port(self): + pl = manager.NeutronManager.get_service_plugins().get( + service_constants.L3_ROUTER_NAT) + self.assertIsNone( + pl.prevent_l3_port_deletion(context.get_admin_context(), 'fakeid') + ) -- 2.45.2