From 6a6f49b609a50a55a71348d82a696d6976155a06 Mon Sep 17 00:00:00 2001 From: elajkat Date: Fri, 4 Dec 2020 15:47:06 +0100 Subject: [PATCH] Migrate to new engine facade Partially-Implements blueprint: enginefacade-switch Change-Id: I70636da4b3d4aa633286366f47ea997111b3bc2e --- .../services/bgp/scheduler/bgp_dragent_scheduler.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 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 b246b744..5f55188b 100644 --- a/neutron_dynamic_routing/services/bgp/scheduler/bgp_dragent_scheduler.py +++ b/neutron_dynamic_routing/services/bgp/scheduler/bgp_dragent_scheduler.py @@ -16,6 +16,7 @@ from neutron_lib.callbacks import events from neutron_lib.callbacks import registry from neutron_lib import context as nl_context +from neutron_lib.db import api as db_api from neutron_lib.objects import registry as obj_reg from oslo_db import exception as db_exc from oslo_log import log as logging @@ -49,7 +50,7 @@ class BgpDrAgentFilter(base_resource_filter.BaseResourceFilter): binding.agent_id = agent_id binding.bgp_speaker_id = bgp_speaker_id try: - with context.session.begin(subtransactions=True): + with db_api.CONTEXT_WRITER.using(context): context.session.add(binding) except db_exc.DBDuplicateEntry: # it's totally ok, someone just did our job! @@ -74,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): + with db_api.CONTEXT_READER.using(context): active_dragents = plugin.get_agent_objects( context, filters={ 'agent_type': [bgp_consts.AGENT_TYPE_BGP_ROUTING], @@ -136,7 +137,7 @@ class BgpDrAgentSchedulerBase(BgpDrAgentFilter): """Call schedule_unscheduled_bgp_speakers for all hosts. """ - with context.session.begin(subtransactions=True): + with db_api.CONTEXT_WRITER.using(context): query = context.session.query(agent_model.Agent.host).distinct() for agent in query: self.schedule_unscheduled_bgp_speakers(context, agent[0]) @@ -147,7 +148,7 @@ class BgpDrAgentSchedulerBase(BgpDrAgentFilter): """ LOG.debug('Started auto-scheduling on host %s', host) - with context.session.begin(subtransactions=True): + with db_api.CONTEXT_WRITER.using(context): bgp_dragent = obj_reg.load_class('Agent').get_object( context, agent_type=bgp_consts.AGENT_TYPE_BGP_ROUTING,