Switch to new engine facade for L3_HA_NAT_db_mixin

Partially-Implements blueprint: enginefacade-switch

Change-Id: I39026ede7ff57542f35a5a95735ec640f090c19b
This commit is contained in:
Rodolfo Alonso Hernandez 2019-06-05 09:58:00 +00:00
parent 4467741d32
commit d6f659e0b1
2 changed files with 13 additions and 12 deletions

View File

@ -126,7 +126,7 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin,
try:
# NOTE(kevinbenton): we disallow subtransactions because the
# retry logic will bust any parent transactions
with context.session.begin():
with db_api.CONTEXT_WRITER.using(context):
if router_db.extra_attributes.ha_vr_id:
LOG.debug(
"Router %(router_id)s has already been "
@ -259,15 +259,14 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin,
@db_api.retry_if_session_inactive()
def _create_ha_port_binding(self, context, router_id, port_id):
try:
with context.session.begin():
l3_obj.RouterPort(
context,
port_id=port_id,
router_id=router_id,
port_type=constants.DEVICE_OWNER_ROUTER_HA_INTF).create()
portbinding = l3_hamode.L3HARouterAgentPortBinding(
context, port_id=port_id, router_id=router_id)
portbinding.create()
l3_obj.RouterPort(
context,
port_id=port_id,
router_id=router_id,
port_type=constants.DEVICE_OWNER_ROUTER_HA_INTF).create()
portbinding = l3_hamode.L3HARouterAgentPortBinding(
context, port_id=port_id, router_id=router_id)
portbinding.create()
return portbinding
except db_exc.DBReferenceError as e:
@ -571,7 +570,7 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin,
states on this agent.
"""
with context.session.begin(subtransactions=True):
with db_api.CONTEXT_WRITER.using(context):
bindings = self.get_ha_router_port_bindings(context, [router_id])
router_active_agents_dead = []
router_standby_agents_dead = []
@ -688,6 +687,7 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin,
def _set_router_states(cls, context, bindings, states):
for binding in bindings:
try:
# NOTE(ralonsoh): to be migrated to the new facade.
with context.session.begin(subtransactions=True):
binding.state = states[binding.router_id]
except (orm.exc.StaleDataError, orm.exc.ObjectDeletedError):

View File

@ -26,6 +26,7 @@ from neutron_lib.callbacks import registry
from neutron_lib.callbacks import resources
from neutron_lib import constants
from neutron_lib import context
from neutron_lib.db import api as db_api
from neutron_lib import exceptions as n_exc
from neutron_lib.exceptions import l3 as l3_exc
from neutron_lib.exceptions import l3_ext_ha_mode as l3ha_exc
@ -595,7 +596,7 @@ class L3HATestCase(L3HATestFramework):
def test_add_ha_port_subtransactions_blocked(self):
ctx = self.admin_ctx
with ctx.session.begin():
with db_api.CONTEXT_WRITER.using(ctx):
self.assertRaises(RuntimeError, self.plugin.add_ha_port,
ctx, 'id', 'id', 'id')