diff --git a/neutron/db/l3_hamode_db.py b/neutron/db/l3_hamode_db.py index 435178420ae..bff388e1668 100644 --- a/neutron/db/l3_hamode_db.py +++ b/neutron/db/l3_hamode_db.py @@ -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): diff --git a/neutron/tests/unit/db/test_l3_hamode_db.py b/neutron/tests/unit/db/test_l3_hamode_db.py index 3635ebe2541..84cba8c5ec7 100644 --- a/neutron/tests/unit/db/test_l3_hamode_db.py +++ b/neutron/tests/unit/db/test_l3_hamode_db.py @@ -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')