Enhance getting valid router bindings
When we get all router ids bound to edge, we now just search in nsxv_router_bindings. But sometime there maybe inconsistency and we have ghost router bindings left whose router db has actually been deleted. Following shared router backend ops would unexpectly break with these ghost router ids, worse itself also become a ghost after router db is deleted. The patch avoids it happend by double getting router ids also from Router db. Change-Id: If111ab8355102120d509c91e547fcde4cd309f16
This commit is contained in:
parent
16200ab377
commit
64d32be67d
@ -1474,13 +1474,25 @@ class EdgeManager(object):
|
||||
def get_routers_on_same_edge(self, context, router_id):
|
||||
edge_binding = nsxv_db.get_nsxv_router_binding(
|
||||
context.session, router_id)
|
||||
router_ids = []
|
||||
valid_router_ids = []
|
||||
if edge_binding:
|
||||
return [
|
||||
router_ids = [
|
||||
binding['router_id']
|
||||
for binding in nsxv_db.get_nsxv_router_bindings_by_edge(
|
||||
context.session, edge_binding['edge_id'])]
|
||||
else:
|
||||
return []
|
||||
if router_ids:
|
||||
valid_router_ids = self.plugin.get_routers(
|
||||
context.elevated(),
|
||||
filters={'id': router_ids},
|
||||
fields=['id'])
|
||||
valid_router_ids = [ele['id'] for ele in valid_router_ids]
|
||||
|
||||
if set(valid_router_ids) != set(router_ids):
|
||||
LOG.error(_LE("Get invalid router bindings with "
|
||||
"router ids: %s"),
|
||||
str(set(router_ids) - set(valid_router_ids)))
|
||||
return valid_router_ids
|
||||
|
||||
def bind_router_on_available_edge(
|
||||
self, context, target_router_id,
|
||||
|
@ -3755,12 +3755,12 @@ class TestSharedRouterTestCase(L3NatTest, L3NatTestCaseBase,
|
||||
get_routers_on_same_edge(
|
||||
context.get_admin_context(),
|
||||
r1['router']['id']))
|
||||
self.assertEqual(routers_expected, routers_1)
|
||||
self.assertEqual(set(routers_expected), set(routers_1))
|
||||
routers_2 = (self.plugin_instance.edge_manager.
|
||||
get_routers_on_same_edge(
|
||||
context.get_admin_context(),
|
||||
r2['router']['id']))
|
||||
self.assertEqual(routers_expected, routers_2)
|
||||
self.assertEqual(set(routers_expected), set(routers_2))
|
||||
self._router_interface_action('remove',
|
||||
r1['router']['id'],
|
||||
s11['subnet']['id'],
|
||||
@ -3821,7 +3821,7 @@ class TestSharedRouterTestCase(L3NatTest, L3NatTestCaseBase,
|
||||
get_routers_on_same_edge(
|
||||
context.get_admin_context(),
|
||||
r1['router']['id']))
|
||||
self.assertEqual(r1_expected, routers_1)
|
||||
self.assertEqual(set(r1_expected), set(routers_1))
|
||||
self._router_interface_action('add',
|
||||
r2['router']['id'],
|
||||
s13['subnet']['id'],
|
||||
|
Loading…
Reference in New Issue
Block a user