]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Make prevent_l3_port_deletion handle missing port
authorKevin Benton <blak111@gmail.com>
Fri, 30 Jan 2015 20:53:57 +0000 (12:53 -0800)
committerKevin Benton <blak111@gmail.com>
Mon, 2 Feb 2015 22:07:01 +0000 (14:07 -0800)
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
neutron/plugins/ml2/plugin.py
neutron/tests/unit/test_l3_plugin.py

index 569bc8f6a0579356b969568f95cd97eb647055de..3176d89bb4dc4eb022df316d2e26ad807c9a1958 100644 (file)
@@ -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
index 4a352b61eb1b858c95703d3b34bfe03803d1baf4..8fe59dedb1d1fbfd5e85e4243fe1a016e003bb80 100644 (file)
@@ -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)
index 33a77eae67c5dc10945da23a0066d8e0f926a6c0..2f74c87bdb8f533c1519b48aa2b4986eb47b0358 100644 (file)
@@ -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')
+        )