NSX: Fix KeyError in sync if nsx_router_id not found
Previously, a KeyError would occur in the sync code which would cause the sync thread to stop running. This would occur if there was a router entry in the database but no nsx_router_mapping and the router was not found in nsx. Note: this should never happen unless one did not run the db migration which introduced and migrated the data for the NeutronNsxRouterMapping table. Change-Id: I44f3e7de9323f594501db63d3ad33e80e617bfdc Closes-bug: #1304647
This commit is contained in:
committed by
Gerrit Code Review
parent
4c915b03fd
commit
3037c4b5c2
@@ -334,6 +334,7 @@ class NsxSynchronizer():
|
|||||||
# This query will return the logical router status too
|
# This query will return the logical router status too
|
||||||
nsx_router_id = nsx_utils.get_nsx_router_id(
|
nsx_router_id = nsx_utils.get_nsx_router_id(
|
||||||
context.session, self._cluster, neutron_router_data['id'])
|
context.session, self._cluster, neutron_router_data['id'])
|
||||||
|
if nsx_router_id:
|
||||||
lrouter = routerlib.get_lrouter(
|
lrouter = routerlib.get_lrouter(
|
||||||
self._cluster, nsx_router_id)
|
self._cluster, nsx_router_id)
|
||||||
except exceptions.NotFound:
|
except exceptions.NotFound:
|
||||||
@@ -342,8 +343,7 @@ class NsxSynchronizer():
|
|||||||
# The logical router was not found
|
# The logical router was not found
|
||||||
LOG.warning(_("Logical router for neutron router %s not "
|
LOG.warning(_("Logical router for neutron router %s not "
|
||||||
"found on NSX."), neutron_router_data['id'])
|
"found on NSX."), neutron_router_data['id'])
|
||||||
lrouter = None
|
if lrouter:
|
||||||
else:
|
|
||||||
# Update the cache
|
# Update the cache
|
||||||
self._nsx_cache.update_lrouter(lrouter)
|
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 exception as api_exc
|
||||||
from neutron.plugins.vmware.api_client import version
|
from neutron.plugins.vmware.api_client import version
|
||||||
from neutron.plugins.vmware.common import sync
|
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 nsx_cluster as cluster
|
||||||
from neutron.plugins.vmware import nsxlib
|
from neutron.plugins.vmware import nsxlib
|
||||||
from neutron.plugins.vmware import plugin
|
from neutron.plugins.vmware import plugin
|
||||||
@@ -621,6 +622,34 @@ class SyncTestCase(base.BaseTestCase):
|
|||||||
exp_status = constants.NET_STATUS_ACTIVE
|
exp_status = constants.NET_STATUS_ACTIVE
|
||||||
self.assertEqual(exp_status, q_rtr['status'])
|
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):
|
def test_synchronize_router_on_get(self):
|
||||||
cfg.CONF.set_override('always_read_status', True, 'NSX_SYNC')
|
cfg.CONF.set_override('always_read_status', True, 'NSX_SYNC')
|
||||||
ctx = context.get_admin_context()
|
ctx = context.get_admin_context()
|
||||||
|
|||||||
Reference in New Issue
Block a user