From 8f2fc1ee5ee0d5cf8f412fa510adb87f3ed5f4b2 Mon Sep 17 00:00:00 2001 From: LIU Yulong Date: Thu, 18 Apr 2019 15:47:38 +0800 Subject: [PATCH] List ha router count should not include dvr local router Due to the class inheriting order the dvr local router will be counted to the l3 agent restart query. This will cause l3 agent run the ha port down action. This patch renames the function to avoid that. Closes-Bug: #1825787 Change-Id: Id965a6140ae9a06e0b6707800933cbc14bf5bf3f --- neutron/db/l3_agentschedulers_db.py | 12 ++++++++---- neutron/db/l3_dvrscheduler_db.py | 7 +++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/neutron/db/l3_agentschedulers_db.py b/neutron/db/l3_agentschedulers_db.py index d05aef01224..3c91dbaf9d3 100644 --- a/neutron/db/l3_agentschedulers_db.py +++ b/neutron/db/l3_agentschedulers_db.py @@ -303,7 +303,8 @@ class L3AgentSchedulerDbMixin(l3agentscheduler.L3AgentSchedulerPluginBase, return self.get_sync_data(context, router_ids=router_ids, active=True) - def list_router_ids_on_host(self, context, host, router_ids=None): + def list_router_ids_on_host(self, context, host, router_ids=None, + with_dvr=True): try: agent = self._get_agent_by_type_and_host( context, constants.AGENT_TYPE_L3, host) @@ -311,16 +312,19 @@ class L3AgentSchedulerDbMixin(l3agentscheduler.L3AgentSchedulerPluginBase, return [] if not agentschedulers_db.services_available(agent.admin_state_up): return [] - return self._get_router_ids_for_agent(context, agent, router_ids) + return self._get_router_ids_for_agent(context, agent, + router_ids, with_dvr) def get_host_ha_router_count(self, context, host): - router_ids = self.list_router_ids_on_host(context, host) + router_ids = self.list_router_ids_on_host(context, host, + with_dvr=False) up_routers = l3_objs.Router.get_objects(context, id=router_ids, admin_state_up=True) return len(l3_objs.RouterExtraAttributes.get_objects( context, router_id=[obj.id for obj in up_routers], ha=True)) - def _get_router_ids_for_agent(self, context, agent, router_ids): + def _get_router_ids_for_agent(self, context, agent, router_ids, + with_dvr=True): """Get IDs of routers that the agent should host Overridden for DVR to handle agents in 'dvr' mode which have diff --git a/neutron/db/l3_dvrscheduler_db.py b/neutron/db/l3_dvrscheduler_db.py index cf7a3e98ef1..eb0d6173471 100644 --- a/neutron/db/l3_dvrscheduler_db.py +++ b/neutron/db/l3_dvrscheduler_db.py @@ -398,10 +398,13 @@ class L3_DVRsch_db_mixin(l3agent_sch_db.L3AgentSchedulerDbMixin): query = query.filter(RouterPort.router_id != router_id) return [item[0] for item in query] - def _get_router_ids_for_agent(self, context, agent_db, router_ids): + def _get_router_ids_for_agent(self, context, agent_db, router_ids, + with_dvr=True): result_set = set(super(L3_DVRsch_db_mixin, self)._get_router_ids_for_agent( - context, agent_db, router_ids)) + context, agent_db, router_ids, with_dvr)) + if not with_dvr: + return result_set router_ids = set(router_ids or []) if router_ids and result_set == router_ids: # no need for extra dvr checks if requested routers are