From c57f11321220a21af10d884c87ab989dc7dc2e69 Mon Sep 17 00:00:00 2001 From: Aaron Rosen Date: Wed, 12 Mar 2014 22:22:53 -0700 Subject: [PATCH] NSX: Fix router-interface-delete returns 404 when router not in nsx 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 | 17 +++++++-------- neutron/tests/unit/vmware/test_nsx_plugin.py | 22 ++++++++++++++++++++ 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/neutron/plugins/vmware/plugins/base.py b/neutron/plugins/vmware/plugins/base.py index d066ba063..0ad0fc308 100644 --- a/neutron/plugins/vmware/plugins/base.py +++ b/neutron/plugins/vmware/plugins/base.py @@ -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" diff --git a/neutron/tests/unit/vmware/test_nsx_plugin.py b/neutron/tests/unit/vmware/test_nsx_plugin.py index 6c0cecc60..412034590 100644 --- a/neutron/tests/unit/vmware/test_nsx_plugin.py +++ b/neutron/tests/unit/vmware/test_nsx_plugin.py @@ -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) -- 2.45.2