summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--neutron/db/l3_hamode_db.py3
-rw-r--r--neutron/tests/unit/db/test_l3_hamode_db.py19
2 files changed, 21 insertions, 1 deletions
diff --git a/neutron/db/l3_hamode_db.py b/neutron/db/l3_hamode_db.py
index e25eea014e..076ccc1f0e 100644
--- a/neutron/db/l3_hamode_db.py
+++ b/neutron/db/l3_hamode_db.py
@@ -502,7 +502,8 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin):
self, context, router_id):
"""Return a list of [(agent, ha_state), ...]."""
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):
bindings = self.get_l3_bindings_hosting_router_with_ha_states(
diff --git a/neutron/tests/unit/db/test_l3_hamode_db.py b/neutron/tests/unit/db/test_l3_hamode_db.py
index 3daab316a9..af05a0c8e1 100644
--- a/neutron/tests/unit/db/test_l3_hamode_db.py
+++ b/neutron/tests/unit/db/test_l3_hamode_db.py
@@ -161,8 +161,27 @@ class L3HATestCase(L3HATestFramework):
self.assertIn((self.agent1['id'], 'active'), 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):
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(
self.admin_ctx, router['id'])
self.assertEqual([], bindings)