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
This commit is contained in:
parent
c677a0a89e
commit
da0e6ef9eb
@ -1746,12 +1746,12 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
|||||||
info = super(NsxPluginV2, self).remove_router_interface(
|
info = super(NsxPluginV2, self).remove_router_interface(
|
||||||
context, router_id, interface_info)
|
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:
|
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:
|
if not subnet:
|
||||||
subnet = self._get_subnet(context, subnet_id)
|
subnet = self._get_subnet(context, subnet_id)
|
||||||
router = self._get_router(context, router_id)
|
router = self._get_router(context, router_id)
|
||||||
@ -1767,10 +1767,9 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
|||||||
self.cluster, nsx_router_id, "NoSourceNatRule",
|
self.cluster, nsx_router_id, "NoSourceNatRule",
|
||||||
max_num_expected=1, min_num_expected=0,
|
max_num_expected=1, min_num_expected=0,
|
||||||
destination_ip_addresses=subnet['cidr'])
|
destination_ip_addresses=subnet['cidr'])
|
||||||
except api_exc.ResourceNotFound:
|
except n_exc.NotFound:
|
||||||
raise nsx_exc.NsxPluginException(
|
LOG.error(_("Logical router resource %s not found "
|
||||||
err_msg=(_("Logical router resource %s not found "
|
"on NSX platform") % router_id)
|
||||||
"on NSX platform") % router_id))
|
|
||||||
except api_exc.NsxApiException:
|
except api_exc.NsxApiException:
|
||||||
raise nsx_exc.NsxPluginException(
|
raise nsx_exc.NsxPluginException(
|
||||||
err_msg=(_("Unable to update logical router"
|
err_msg=(_("Unable to update logical router"
|
||||||
|
@ -1111,6 +1111,28 @@ class NeutronNsxOutOfSync(NsxPluginV2TestCase,
|
|||||||
res = req.get_response(self.ext_api)
|
res = req.get_response(self.ext_api)
|
||||||
self.assertEqual(res.status_int, 200)
|
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):
|
def test_update_router_not_in_nsx(self):
|
||||||
res = self._create_router('json', 'tenant')
|
res = self._create_router('json', 'tenant')
|
||||||
router = self.deserialize('json', res)
|
router = self.deserialize('json', res)
|
||||||
|
Loading…
Reference in New Issue
Block a user