Merge "NSX: Fix KeyError in sync if nsx_router_id not found" into milestone-proposed
This commit is contained in:
commit
288432e3d1
|
@ -334,16 +334,16 @@ class NsxSynchronizer():
|
|||
# This query will return the logical router status too
|
||||
nsx_router_id = nsx_utils.get_nsx_router_id(
|
||||
context.session, self._cluster, neutron_router_data['id'])
|
||||
lrouter = routerlib.get_lrouter(
|
||||
self._cluster, nsx_router_id)
|
||||
if nsx_router_id:
|
||||
lrouter = routerlib.get_lrouter(
|
||||
self._cluster, nsx_router_id)
|
||||
except exceptions.NotFound:
|
||||
# NOTE(salv-orlando): We should be catching
|
||||
# api_exc.ResourceNotFound here
|
||||
# The logical router was not found
|
||||
LOG.warning(_("Logical router for neutron router %s not "
|
||||
"found on NSX."), neutron_router_data['id'])
|
||||
lrouter = None
|
||||
else:
|
||||
if lrouter:
|
||||
# Update the cache
|
||||
self._nsx_cache.update_lrouter(lrouter)
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ from neutron.plugins.vmware.api_client import client
|
|||
from neutron.plugins.vmware.api_client import exception as api_exc
|
||||
from neutron.plugins.vmware.api_client import version
|
||||
from neutron.plugins.vmware.common import sync
|
||||
from neutron.plugins.vmware.dbexts import db
|
||||
from neutron.plugins.vmware import nsx_cluster as cluster
|
||||
from neutron.plugins.vmware import nsxlib
|
||||
from neutron.plugins.vmware import plugin
|
||||
|
@ -621,6 +622,34 @@ class SyncTestCase(base.BaseTestCase):
|
|||
exp_status = constants.NET_STATUS_ACTIVE
|
||||
self.assertEqual(exp_status, q_rtr['status'])
|
||||
|
||||
def test_synchronize_router_nsx_mapping_not_found(self):
|
||||
ctx = context.get_admin_context()
|
||||
with self._populate_data(ctx):
|
||||
# Put a router down to verify synchronization
|
||||
lr_uuid = self.fc._fake_lrouter_dict.keys()[0]
|
||||
q_rtr_id = self._get_tag_dict(
|
||||
self.fc._fake_lrouter_dict[lr_uuid]['tags'])['q_router_id']
|
||||
self.fc._fake_lrouter_dict[lr_uuid]['status'] = 'false'
|
||||
q_rtr_data = self._plugin._get_router(ctx, q_rtr_id)
|
||||
|
||||
# delete router mapping from db.
|
||||
db.delete_neutron_nsx_router_mapping(ctx.session, q_rtr_id)
|
||||
# pop router from fake nsx client
|
||||
router_data = self.fc._fake_lrouter_dict.pop(lr_uuid)
|
||||
|
||||
self._plugin._synchronizer.synchronize_router(ctx, q_rtr_data)
|
||||
# Reload from db
|
||||
q_routers = self._plugin.get_routers(ctx)
|
||||
for q_rtr in q_routers:
|
||||
if q_rtr['id'] == q_rtr_id:
|
||||
exp_status = constants.NET_STATUS_ERROR
|
||||
else:
|
||||
exp_status = constants.NET_STATUS_ACTIVE
|
||||
self.assertEqual(exp_status, q_rtr['status'])
|
||||
# put the router database since we don't handle missing
|
||||
# router data in the fake nsx api_client
|
||||
self.fc._fake_lrouter_dict[lr_uuid] = router_data
|
||||
|
||||
def test_synchronize_router_on_get(self):
|
||||
cfg.CONF.set_override('always_read_status', True, 'NSX_SYNC')
|
||||
ctx = context.get_admin_context()
|
||||
|
|
Loading…
Reference in New Issue