Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion neutron/db/l3_hamode_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,8 @@ def _get_bindings_and_update_router_state_for_dead_agents(self, context,
# List agents where router is active and agent is dead
# and agents where router is standby and agent is dead
for binding in bindings:
if not (binding.agent.is_active and
if not (binding.agent and
binding.agent.is_active and
binding.agent.admin_state_up):
if binding.state == constants.HA_ROUTER_STATE_ACTIVE:
router_active_agents_dead.append(binding.agent)
Expand Down
23 changes: 23 additions & 0 deletions neutron/tests/unit/db/test_l3_hamode_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,29 @@ def test_get_l3_bindings_hosting_router_with_ha_states_ha_router(self):
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_null_agent(self):
router = self._create_router()
self.plugin.update_routers_states(
self.admin_ctx, {router['id']: 'active'}, self.agent1['host'])
mock_bindings = self.plugin.get_ha_router_port_bindings(
self.admin_ctx, [router['id']])
mock_bindings[0].state = constants.HA_ROUTER_STATE_STANDBY
target = (
'neutron.db.l3_hamode_db.L3_HA_NAT_db_mixin'
'.get_ha_router_port_bindings'
)
with (
mock.patch(
target,
return_value=mock_bindings),
mock.patch.object(mock_bindings[0], 'agent', new=None)
):
bindings = (
self.plugin.get_l3_bindings_hosting_router_with_ha_states(
self.admin_ctx, router['id'])
)
self.assertEqual(len(bindings), 1)

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
Expand Down