[sqlalchemy-20] Replace the context writer/reader
This patch replaces the old DB contexts and removes the subtransactions. Change-Id: I9ac48eeba9f7d5d01153edb4b2f3341008ac2e01
This commit is contained in:
parent
a4284e4ee6
commit
cfa0b34476
@ -846,7 +846,6 @@ class FirewallPluginDb(object):
|
||||
exc_ports = []
|
||||
for port_id in port_id_list:
|
||||
try:
|
||||
with context.session.begin(subtransactions=True):
|
||||
fwg_port_db = FirewallGroupPortAssociation(
|
||||
firewall_group_id=fwg_db['id'],
|
||||
port_id=port_id)
|
||||
|
@ -45,7 +45,6 @@ def generate_records_for_existing(table):
|
||||
sa.Column('standard_attr_id', sa.BigInteger(),
|
||||
nullable=True))
|
||||
session = sa.orm.Session(bind=op.get_bind())
|
||||
with session.begin(subtransactions=True):
|
||||
for row in session.query(model):
|
||||
res = session.execute(
|
||||
standardattrs.insert().values(resource_type=table,
|
||||
|
@ -20,6 +20,7 @@ import copy
|
||||
from neutron_lib.callbacks import events
|
||||
from neutron_lib.callbacks import registry
|
||||
from neutron_lib import constants as nl_constants
|
||||
from neutron_lib.db import api as db_api
|
||||
from neutron_lib.plugins import directory
|
||||
from oslo_log import log as logging
|
||||
|
||||
@ -134,8 +135,8 @@ class FirewallDriverDBMixin(FirewallDriver, metaclass=abc.ABCMeta):
|
||||
self.firewall_db = firewall_db_v2.FirewallPluginDb()
|
||||
|
||||
@staticmethod
|
||||
@db_api.CONTEXT_READER
|
||||
def _update_resource_status(context, resource_type, resource_dict):
|
||||
with context.session.begin(subtransactions=True):
|
||||
context.session.query(resource_type).\
|
||||
filter_by(id=resource_dict['id']).\
|
||||
update({'status': resource_dict['status']})
|
||||
@ -143,7 +144,7 @@ class FirewallDriverDBMixin(FirewallDriver, metaclass=abc.ABCMeta):
|
||||
# Firewall Group
|
||||
def create_firewall_group(self, context, firewall_group):
|
||||
request_body = firewall_group
|
||||
with context.session.begin(subtransactions=True):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
firewall_group = self.firewall_db.create_firewall_group(
|
||||
context, firewall_group)
|
||||
self.create_firewall_group_precommit(context, firewall_group)
|
||||
@ -231,7 +232,7 @@ class FirewallDriverDBMixin(FirewallDriver, metaclass=abc.ABCMeta):
|
||||
# Firewall Policy
|
||||
def create_firewall_policy(self, context, firewall_policy):
|
||||
request_body = firewall_policy
|
||||
with context.session.begin(subtransactions=True):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
firewall_policy = self.firewall_db.create_firewall_policy(
|
||||
context, firewall_policy)
|
||||
self.create_firewall_policy_precommit(context, firewall_policy)
|
||||
@ -310,7 +311,7 @@ class FirewallDriverDBMixin(FirewallDriver, metaclass=abc.ABCMeta):
|
||||
# Firewall Rule
|
||||
def create_firewall_rule(self, context, firewall_rule):
|
||||
request_body = firewall_rule
|
||||
with context.session.begin(subtransactions=True):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
firewall_rule = self.firewall_db.create_firewall_rule(
|
||||
context, firewall_rule)
|
||||
self.create_firewall_rule_precommit(context, firewall_rule)
|
||||
|
@ -20,6 +20,7 @@ from neutron import extensions as neutron_extensions
|
||||
from neutron.tests.unit.extensions import test_l3
|
||||
from neutron_lib import constants as nl_constants
|
||||
from neutron_lib import context
|
||||
from neutron_lib.db import api as db_api
|
||||
from neutron_lib.exceptions import firewall_v2 as f_exc
|
||||
from neutron_lib.plugins import directory
|
||||
from oslo_config import cfg
|
||||
@ -163,7 +164,7 @@ class TestAgentDriver(test_fwaas_plugin_v2.FirewallPluginV2TestCase,
|
||||
do_delete=False
|
||||
) as fwg:
|
||||
fwg_id = fwg['firewall_group']['id']
|
||||
with ctx.session.begin(subtransactions=True):
|
||||
with db_api.CONTEXT_WRITER.using(ctx):
|
||||
fwg_db = self.db._get_firewall_group(ctx, fwg_id)
|
||||
fwg_db['status'] = nl_constants.PENDING_DELETE
|
||||
|
||||
@ -183,7 +184,7 @@ class TestAgentDriver(test_fwaas_plugin_v2.FirewallPluginV2TestCase,
|
||||
def getdelete(context, fwg_id):
|
||||
fwg_db = _get_firewall_group(context, fwg_id)
|
||||
# NOTE(cby): Use a different session to simulate a concurrent del
|
||||
with alt_ctx.session.begin(subtransactions=True):
|
||||
with db_api.CONTEXT_READER.using(alt_ctx):
|
||||
alt_ctx.session.query(FirewallGroup).filter_by(
|
||||
id=fwg_id).delete()
|
||||
return fwg_db
|
||||
@ -197,7 +198,7 @@ class TestAgentDriver(test_fwaas_plugin_v2.FirewallPluginV2TestCase,
|
||||
as_admin=True,
|
||||
) as fwg:
|
||||
fwg_id = fwg['firewall_group']['id']
|
||||
with ctx.session.begin(subtransactions=True):
|
||||
with db_api.CONTEXT_WRITER.using(ctx):
|
||||
fwg_db = self.db._get_firewall_group(ctx, fwg_id)
|
||||
fwg_db['status'] = nl_constants.PENDING_DELETE
|
||||
ctx.session.flush()
|
||||
|
Loading…
Reference in New Issue
Block a user