Merge "Enhance getting valid router bindings"

This commit is contained in:
Jenkins 2016-05-19 20:16:01 +00:00 committed by Gerrit Code Review
commit 4b8e4a29e5
2 changed files with 18 additions and 6 deletions

View File

@ -1474,13 +1474,25 @@ class EdgeManager(object):
def get_routers_on_same_edge(self, context, router_id): def get_routers_on_same_edge(self, context, router_id):
edge_binding = nsxv_db.get_nsxv_router_binding( edge_binding = nsxv_db.get_nsxv_router_binding(
context.session, router_id) context.session, router_id)
router_ids = []
valid_router_ids = []
if edge_binding: if edge_binding:
return [ router_ids = [
binding['router_id'] binding['router_id']
for binding in nsxv_db.get_nsxv_router_bindings_by_edge( for binding in nsxv_db.get_nsxv_router_bindings_by_edge(
context.session, edge_binding['edge_id'])] context.session, edge_binding['edge_id'])]
else: if router_ids:
return [] 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( def bind_router_on_available_edge(
self, context, target_router_id, self, context, target_router_id,

View File

@ -3755,12 +3755,12 @@ class TestSharedRouterTestCase(L3NatTest, L3NatTestCaseBase,
get_routers_on_same_edge( get_routers_on_same_edge(
context.get_admin_context(), context.get_admin_context(),
r1['router']['id'])) r1['router']['id']))
self.assertEqual(routers_expected, routers_1) self.assertEqual(set(routers_expected), set(routers_1))
routers_2 = (self.plugin_instance.edge_manager. routers_2 = (self.plugin_instance.edge_manager.
get_routers_on_same_edge( get_routers_on_same_edge(
context.get_admin_context(), context.get_admin_context(),
r2['router']['id'])) r2['router']['id']))
self.assertEqual(routers_expected, routers_2) self.assertEqual(set(routers_expected), set(routers_2))
self._router_interface_action('remove', self._router_interface_action('remove',
r1['router']['id'], r1['router']['id'],
s11['subnet']['id'], s11['subnet']['id'],
@ -3821,7 +3821,7 @@ class TestSharedRouterTestCase(L3NatTest, L3NatTestCaseBase,
get_routers_on_same_edge( get_routers_on_same_edge(
context.get_admin_context(), context.get_admin_context(),
r1['router']['id'])) r1['router']['id']))
self.assertEqual(r1_expected, routers_1) self.assertEqual(set(r1_expected), set(routers_1))
self._router_interface_action('add', self._router_interface_action('add',
r2['router']['id'], r2['router']['id'],
s13['subnet']['id'], s13['subnet']['id'],