Update HA router state if agent is not active
If L3 agent is marked dead it is still show as 'active' in the HA
router states on that agent. Current change adds check for such
case and updates HA router state from 'active' to 'standby' if
agent is dead.
Closes-bug: #1461148
Change-Id: Ie02e787a5b30cbe01694081cdec924304ab2ef41
(cherry picked from commit fc514b8e71
)
This commit is contained in:
parent
30b53c9cc5
commit
b908c5521e
|
@ -531,10 +531,32 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin):
|
|||
|
||||
return query.all()
|
||||
|
||||
def _get_bindings_and_update_router_state_for_dead_agents(self, context,
|
||||
router_id):
|
||||
"""Return bindings. In case if dead agents were detected update router
|
||||
states on this agent.
|
||||
|
||||
"""
|
||||
with context.session.begin(subtransactions=True):
|
||||
bindings = self.get_ha_router_port_bindings(context, [router_id])
|
||||
dead_agents = [
|
||||
binding.agent for binding in bindings
|
||||
if binding.state == constants.HA_ROUTER_STATE_ACTIVE and
|
||||
not binding.agent.is_active]
|
||||
for dead_agent in dead_agents:
|
||||
self.update_routers_states(
|
||||
context, {router_id: constants.HA_ROUTER_STATE_STANDBY},
|
||||
dead_agent.host)
|
||||
|
||||
if dead_agents:
|
||||
return self.get_ha_router_port_bindings(context, [router_id])
|
||||
return bindings
|
||||
|
||||
def get_l3_bindings_hosting_router_with_ha_states(
|
||||
self, context, router_id):
|
||||
"""Return a list of [(agent, ha_state), ...]."""
|
||||
bindings = self.get_ha_router_port_bindings(context, [router_id])
|
||||
bindings = self._get_bindings_and_update_router_state_for_dead_agents(
|
||||
context, router_id)
|
||||
return [(binding.agent, binding.state) for binding in bindings
|
||||
if binding.agent is not None]
|
||||
|
||||
|
|
|
@ -196,6 +196,21 @@ class L3HATestCase(L3HATestFramework):
|
|||
self.admin_ctx, router['id'])
|
||||
self.assertEqual([], bindings)
|
||||
|
||||
def test_get_l3_bindings_hosting_router_with_ha_states_active_and_dead(
|
||||
self):
|
||||
router = self._create_router()
|
||||
self._bind_router(router['id'])
|
||||
with mock.patch.object(agents_db.Agent, 'is_active',
|
||||
new_callable=mock.PropertyMock,
|
||||
return_value=False):
|
||||
self.plugin.update_routers_states(
|
||||
self.admin_ctx, {router['id']: 'active'}, self.agent1['host'])
|
||||
bindings = (
|
||||
self.plugin.get_l3_bindings_hosting_router_with_ha_states(
|
||||
self.admin_ctx, router['id']))
|
||||
agent_ids = [(agent[0]['id'], agent[1]) for agent in bindings]
|
||||
self.assertIn((self.agent1['id'], 'standby'), agent_ids)
|
||||
|
||||
def test_ha_router_create(self):
|
||||
router = self._create_router()
|
||||
self.assertTrue(router['ha'])
|
||||
|
|
Loading…
Reference in New Issue