Migrate to new engine facade

Partially-Implements blueprint: enginefacade-switch

Change-Id: I70636da4b3d4aa633286366f47ea997111b3bc2e
This commit is contained in:
elajkat 2020-12-04 15:47:06 +01:00 committed by Dr. Jens Harbott
parent 878e89607d
commit 6a6f49b609
1 changed files with 5 additions and 4 deletions

View File

@ -16,6 +16,7 @@
from neutron_lib.callbacks import events from neutron_lib.callbacks import events
from neutron_lib.callbacks import registry from neutron_lib.callbacks import registry
from neutron_lib import context as nl_context 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 neutron_lib.objects import registry as obj_reg
from oslo_db import exception as db_exc from oslo_db import exception as db_exc
from oslo_log import log as logging from oslo_log import log as logging
@ -49,7 +50,7 @@ class BgpDrAgentFilter(base_resource_filter.BaseResourceFilter):
binding.agent_id = agent_id binding.agent_id = agent_id
binding.bgp_speaker_id = bgp_speaker_id binding.bgp_speaker_id = bgp_speaker_id
try: try:
with context.session.begin(subtransactions=True): with db_api.CONTEXT_WRITER.using(context):
context.session.add(binding) context.session.add(binding)
except db_exc.DBDuplicateEntry: except db_exc.DBDuplicateEntry:
# it's totally ok, someone just did our job! # 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): def _get_active_dragents(self, plugin, context):
"""Return a list of active BgpDrAgents.""" """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( active_dragents = plugin.get_agent_objects(
context, filters={ context, filters={
'agent_type': [bgp_consts.AGENT_TYPE_BGP_ROUTING], 'agent_type': [bgp_consts.AGENT_TYPE_BGP_ROUTING],
@ -136,7 +137,7 @@ class BgpDrAgentSchedulerBase(BgpDrAgentFilter):
"""Call schedule_unscheduled_bgp_speakers for all hosts. """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() query = context.session.query(agent_model.Agent.host).distinct()
for agent in query: for agent in query:
self.schedule_unscheduled_bgp_speakers(context, agent[0]) self.schedule_unscheduled_bgp_speakers(context, agent[0])
@ -147,7 +148,7 @@ class BgpDrAgentSchedulerBase(BgpDrAgentFilter):
""" """
LOG.debug('Started auto-scheduling on host %s', host) 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( bgp_dragent = obj_reg.load_class('Agent').get_object(
context, context,
agent_type=bgp_consts.AGENT_TYPE_BGP_ROUTING, agent_type=bgp_consts.AGENT_TYPE_BGP_ROUTING,