From 39699184d83962f17bb1935aecd68bb0711c15e4 Mon Sep 17 00:00:00 2001 From: Nguyen Phuong An Date: Thu, 16 Nov 2017 16:31:23 +0700 Subject: [PATCH] Use agent OVO for bgp_dragent_scheduler Neutron agent scheduler has been switched to use Agent OVO[1]. So this patch uses agent OVO for bgp_dragent_scheduler. [1] https://review.openstack.org/#/c/495810 Change-Id: I7e5da95ab3c28c00f3be9eca2c92a772492cfa69 Closes-Bug: #1732603 --- .../bgp/scheduler/bgp_dragent_scheduler.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/neutron_dynamic_routing/services/bgp/scheduler/bgp_dragent_scheduler.py b/neutron_dynamic_routing/services/bgp/scheduler/bgp_dragent_scheduler.py index 15512934..226bfaa8 100644 --- a/neutron_dynamic_routing/services/bgp/scheduler/bgp_dragent_scheduler.py +++ b/neutron_dynamic_routing/services/bgp/scheduler/bgp_dragent_scheduler.py @@ -18,11 +18,11 @@ from neutron_lib.callbacks import registry from neutron_lib import context as nl_context from oslo_db import exception as db_exc from oslo_log import log as logging -from sqlalchemy.orm import exc from sqlalchemy import sql from neutron.agent.common import utils from neutron.db.models import agent as agent_model +from neutron.objects import agent as agent_object from neutron.scheduler import base_resource_filter from neutron.scheduler import base_scheduler @@ -75,7 +75,7 @@ class BgpDrAgentFilter(base_resource_filter.BaseResourceFilter): def _get_active_dragents(self, plugin, context): """Return a list of active BgpDrAgents.""" with context.session.begin(subtransactions=True): - active_dragents = plugin.get_agents_db( + active_dragents = plugin.get_agent_objects( context, filters={ 'agent_type': [bgp_consts.AGENT_TYPE_BGP_ROUTING], 'admin_state_up': [True]}) @@ -148,14 +148,12 @@ class BgpDrAgentSchedulerBase(BgpDrAgentFilter): LOG.debug('Started auto-scheduling on host %s', host) with context.session.begin(subtransactions=True): - query = context.session.query(agent_model.Agent) - query = query.filter_by( + bgp_dragent = agent_object.Agent.get_object( + context, agent_type=bgp_consts.AGENT_TYPE_BGP_ROUTING, host=host, - admin_state_up=sql.true()) - try: - bgp_dragent = query.one() - except (exc.NoResultFound): + admin_state_up=True) + if not bgp_dragent: LOG.debug('No enabled BgpDrAgent on host %s', host) return False