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
(cherry picked from commit 8f2fc1ee5e)
This commit is contained in:
LIU Yulong 2019-04-18 15:47:38 +08:00
parent 02cfc3dd56
commit 70e3790210
2 changed files with 13 additions and 6 deletions

View File

@ -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

View File

@ -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