Merge "Skip bindings with agent_id=None" into stable/liberty

This commit is contained in:
Jenkins 2015-12-04 17:14:36 +00:00 committed by Gerrit Code Review
commit 28961debfb
2 changed files with 21 additions and 1 deletions

View File

@ -502,7 +502,8 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin):
self, context, router_id): self, context, router_id):
"""Return a list of [(agent, ha_state), ...].""" """Return a list of [(agent, ha_state), ...]."""
bindings = self.get_ha_router_port_bindings(context, [router_id]) bindings = self.get_ha_router_port_bindings(context, [router_id])
return [(binding.agent, binding.state) for binding in bindings] return [(binding.agent, binding.state) for binding in bindings
if binding.agent is not None]
def get_active_host_for_ha_router(self, context, router_id): def get_active_host_for_ha_router(self, context, router_id):
bindings = self.get_l3_bindings_hosting_router_with_ha_states( bindings = self.get_l3_bindings_hosting_router_with_ha_states(

View File

@ -161,8 +161,27 @@ class L3HATestCase(L3HATestFramework):
self.assertIn((self.agent1['id'], 'active'), agent_ids) self.assertIn((self.agent1['id'], 'active'), agent_ids)
self.assertIn((self.agent2['id'], 'standby'), agent_ids) self.assertIn((self.agent2['id'], 'standby'), agent_ids)
def test_get_l3_bindings_hosting_router_with_ha_states_agent_none(self):
router = self._create_router()
# Do not bind router to leave agents as None
res = self.admin_ctx.session.query(
l3_hamode_db.L3HARouterAgentPortBinding).filter(
l3_hamode_db.L3HARouterAgentPortBinding.router_id == router['id']
).all()
# Check that agents are None
self.assertEqual([None, None], [r.agent for r in res])
bindings = self.plugin.get_l3_bindings_hosting_router_with_ha_states(
self.admin_ctx, router['id'])
self.assertEqual([], bindings)
def test_get_l3_bindings_hosting_router_with_ha_states_not_scheduled(self): def test_get_l3_bindings_hosting_router_with_ha_states_not_scheduled(self):
router = self._create_router(ha=False) router = self._create_router(ha=False)
# Check that there no L3 agents scheduled for this router
res = self.admin_ctx.session.query(
l3_hamode_db.L3HARouterAgentPortBinding).filter(
l3_hamode_db.L3HARouterAgentPortBinding.router_id == router['id']
).all()
self.assertEqual([], [r.agent for r in res])
bindings = self.plugin.get_l3_bindings_hosting_router_with_ha_states( bindings = self.plugin.get_l3_bindings_hosting_router_with_ha_states(
self.admin_ctx, router['id']) self.admin_ctx, router['id'])
self.assertEqual([], bindings) self.assertEqual([], bindings)