From 30c219f6823b80934a0c0562b048fd33b2e76c76 Mon Sep 17 00:00:00 2001 From: Kevin Benton Date: Tue, 19 Aug 2014 15:15:09 -0700 Subject: [PATCH] Join tables in query for down L3 agents Join the agent table together with the L3 agent scheduler table. This fixes an issue where the query would return all admin_state_up L3 agents with router bindings when any agent in the database was dead (missed heartbeats) instead of just returning the dead L3 agents with bindings. Closes-Bug: #1359460 Change-Id: I29215f81be7e3513155faaad015e24dbf1a1ad5d --- neutron/db/l3_agentschedulers_db.py | 1 + .../tests/unit/openvswitch/test_agent_scheduler.py | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/neutron/db/l3_agentschedulers_db.py b/neutron/db/l3_agentschedulers_db.py index 478c23571..8dd2739cb 100644 --- a/neutron/db/l3_agentschedulers_db.py +++ b/neutron/db/l3_agentschedulers_db.py @@ -110,6 +110,7 @@ class L3AgentSchedulerDbMixin(l3agentscheduler.L3AgentSchedulerPluginBase, seconds=agent_dead_limit) down_bindings = ( context.session.query(RouterL3AgentBinding). + join(agents_db.Agent). filter(agents_db.Agent.heartbeat_timestamp < cutoff, agents_db.Agent.admin_state_up)) for binding in down_bindings: diff --git a/neutron/tests/unit/openvswitch/test_agent_scheduler.py b/neutron/tests/unit/openvswitch/test_agent_scheduler.py index ab855b61c..cce5552fe 100644 --- a/neutron/tests/unit/openvswitch/test_agent_scheduler.py +++ b/neutron/tests/unit/openvswitch/test_agent_scheduler.py @@ -643,6 +643,19 @@ class OvsAgentSchedulerTestCase(OvsAgentSchedulerTestCaseBase): agt_db.admin_state_up = state self.adminContext.session.commit() + def test_router_is_not_rescheduled_from_alive_agent(self): + with self.router(): + l3_rpc = l3_rpc_base.L3RpcCallbackMixin() + self._register_agent_states() + + # schedule the router to host A + l3_rpc.sync_routers(self.adminContext, host=L3_HOSTA) + with mock.patch('neutron.db.l3_agentschedulers_db.' + 'L3AgentSchedulerDbMixin.reschedule_router') as rr: + # take down some unrelated agent and run reschedule check + self._take_down_agent_and_run_reschedule(DHCP_HOSTC) + self.assertFalse(rr.called) + def test_router_reschedule_from_dead_agent(self): with self.router(): l3_rpc = l3_rpc_base.L3RpcCallbackMixin() -- 2.45.2