]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
NSX: Fix router-interface-delete returns 404 when router not in nsx
authorAaron Rosen <aaronorosen@gmail.com>
Thu, 13 Mar 2014 05:22:53 +0000 (22:22 -0700)
committerAaron Rosen <aaronorosen@gmail.com>
Mon, 17 Mar 2014 22:35:06 +0000 (15:35 -0700)
Previously, if one would run router-interface-delete and the router
was not found in NSX. Neutron would raise a 404 error and remove the interface
from the database. In this case it would be better if we did not raise
a 404 error as the caller shouldn't be aware that the backend is out of sync.

Closes-bug: #1291690

Change-Id: I2400f8b31817e6dd4bc8aa08f07e1613fc2deeae

neutron/plugins/vmware/plugins/base.py
neutron/tests/unit/vmware/test_nsx_plugin.py

index d066ba0634691c58dc0e5f98ff2b29792ed627b2..0ad0fc3086fe6672e4fd7ecab97b3976f697bb7d 100644 (file)
@@ -1746,12 +1746,12 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
         info = super(NsxPluginV2, self).remove_router_interface(
             context, router_id, interface_info)
 
-        # Ensure the connection to the 'metadata access network'
-        # is removed  (with the network) if this the last subnet
-        # on the router
-        self.handle_router_metadata_access(
-            context, router_id, interface=info)
         try:
+            # Ensure the connection to the 'metadata access network'
+            # is removed  (with the network) if this the last subnet
+            # on the router
+            self.handle_router_metadata_access(
+                context, router_id, interface=info)
             if not subnet:
                 subnet = self._get_subnet(context, subnet_id)
             router = self._get_router(context, router_id)
@@ -1767,10 +1767,9 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
                 self.cluster, nsx_router_id, "NoSourceNatRule",
                 max_num_expected=1, min_num_expected=0,
                 destination_ip_addresses=subnet['cidr'])
-        except api_exc.ResourceNotFound:
-            raise nsx_exc.NsxPluginException(
-                err_msg=(_("Logical router resource %s not found "
-                           "on NSX platform") % router_id))
+        except n_exc.NotFound:
+            LOG.error(_("Logical router resource %s not found "
+                        "on NSX platform") % router_id)
         except api_exc.NsxApiException:
             raise nsx_exc.NsxPluginException(
                 err_msg=(_("Unable to update logical router"
index 6c0cecc609fedb9f4f6b1d36c98049a1dac1c0ad..412034590212f100e892c944aae0835170c003cb 100644 (file)
@@ -1111,6 +1111,28 @@ class NeutronNsxOutOfSync(NsxPluginV2TestCase,
         res = req.get_response(self.ext_api)
         self.assertEqual(res.status_int, 200)
 
+    def test_remove_router_interface_not_in_nsx(self):
+        # Create internal network and subnet
+        int_sub_id = self._create_network_and_subnet('10.0.0.0/24')[1]
+        res = self._create_router('json', 'tenant')
+        router = self.deserialize('json', res)
+        # Add interface to router (needed to generate NAT rule)
+        req = self.new_action_request(
+            'routers',
+            {'subnet_id': int_sub_id},
+            router['router']['id'],
+            "add_router_interface")
+        res = req.get_response(self.ext_api)
+        self.assertEqual(res.status_int, 200)
+        self.fc._fake_lrouter_dict.clear()
+        req = self.new_action_request(
+            'routers',
+            {'subnet_id': int_sub_id},
+            router['router']['id'],
+            "remove_router_interface")
+        res = req.get_response(self.ext_api)
+        self.assertEqual(res.status_int, 200)
+
     def test_update_router_not_in_nsx(self):
         res = self._create_router('json', 'tenant')
         router = self.deserialize('json', res)