`Session.autocommit
` parameter is removed
Since [1] (in oslo.db>9.1.0), the ``Session.autocommit`` member is removed and should not be considered. This patch removes this dependency while keeping backwards compatibility. This code will be removed in future releases. Due to the neutron-lib dependency, this patch bumps the needed library version to 3.1.0. [1]https://review.opendev.org/c/openstack/oslo.db/+/804775 Depends-On: https://review.opendev.org/c/openstack/neutron-lib/+/851193 Closes-Bug: #1982818 Change-Id: Ibfcf9d5f6cd805f2d64fcd88049e2b43fedc3497
This commit is contained in:
parent
1b9e9a6c2c
commit
812ef0306f
@ -1040,7 +1040,8 @@ def is_session_active(session):
|
||||
behaviour, this method checks if there is a transaction created and if
|
||||
the transaction has any active connection against the database server.
|
||||
"""
|
||||
if session.autocommit: # old behaviour, to be removed with sqlalchemy 2.0
|
||||
if getattr(session, 'autocommit', None):
|
||||
# old behaviour, to be removed with sqlalchemy 2.0
|
||||
return session.is_active
|
||||
if not session.transaction:
|
||||
return False
|
||||
|
@ -17,7 +17,6 @@ from unittest import mock
|
||||
|
||||
from neutron_lib import context
|
||||
|
||||
from neutron.common import utils
|
||||
from neutron.db import _utils as db_utils
|
||||
from neutron.tests.unit import testlib_api
|
||||
|
||||
@ -31,14 +30,11 @@ class TestCommonHelpFunctions(testlib_api.SqlTestCase):
|
||||
def test__safe_creation_create_bindings_fails(self):
|
||||
create_fn = mock.Mock(return_value={'id': 1234})
|
||||
create_bindings = mock.Mock(side_effect=ValueError)
|
||||
tx_check = lambda i: setattr(
|
||||
self, '_active', utils.is_session_active(self.admin_ctx.session))
|
||||
delete_fn = mock.Mock(side_effect=tx_check)
|
||||
delete_fn = mock.Mock()
|
||||
self.assertRaises(ValueError, db_utils.safe_creation,
|
||||
self.admin_ctx, create_fn, delete_fn,
|
||||
create_bindings)
|
||||
delete_fn.assert_called_once_with(1234)
|
||||
self.assertTrue(self._active)
|
||||
|
||||
def test__safe_creation_deletion_fails(self):
|
||||
create_fn = mock.Mock(return_value={'id': 1234})
|
||||
|
@ -46,6 +46,7 @@ from neutron.db import agents_db
|
||||
from neutron.db import l3_agentschedulers_db
|
||||
from neutron.db import l3_hamode_db
|
||||
from neutron.objects import l3_hamode
|
||||
from neutron.objects import network as network_obj
|
||||
from neutron import quota
|
||||
from neutron.scheduler import l3_agent_scheduler
|
||||
from neutron.services.revisions import revision_plugin
|
||||
@ -601,6 +602,7 @@ class L3HATestCase(L3HATestFramework):
|
||||
def test_add_ha_port_subtransactions_blocked(self):
|
||||
ctx = self.admin_ctx
|
||||
with db_api.CONTEXT_WRITER.using(ctx):
|
||||
network_obj.Network(ctx).create()
|
||||
self.assertRaises(RuntimeError, self.plugin.add_ha_port,
|
||||
ctx, 'id', 'id', 'id')
|
||||
|
||||
|
@ -53,6 +53,7 @@ from neutron.db import provisioning_blocks
|
||||
from neutron.db import securitygroups_db as sg_db
|
||||
from neutron.db import segments_db
|
||||
from neutron.objects import base as base_obj
|
||||
from neutron.objects import network as network_obj
|
||||
from neutron.objects import ports as port_obj
|
||||
from neutron.objects import router as l3_obj
|
||||
from neutron.plugins.ml2.common import constants as ml2_consts
|
||||
@ -3483,6 +3484,7 @@ class TestTransactionGuard(Ml2PluginV2TestCase):
|
||||
plugin = directory.get_plugin()
|
||||
ctx = context.get_admin_context()
|
||||
with db_api.CONTEXT_WRITER.using(ctx):
|
||||
network_obj.Network(ctx).create()
|
||||
with testtools.ExpectedException(RuntimeError):
|
||||
plugin.delete_network(ctx, 'id')
|
||||
|
||||
@ -3490,6 +3492,7 @@ class TestTransactionGuard(Ml2PluginV2TestCase):
|
||||
plugin = directory.get_plugin()
|
||||
ctx = context.get_admin_context()
|
||||
with db_api.CONTEXT_WRITER.using(ctx):
|
||||
network_obj.Network(ctx).create()
|
||||
with testtools.ExpectedException(RuntimeError):
|
||||
plugin.delete_subnet(ctx, 'id')
|
||||
|
||||
|
@ -560,6 +560,12 @@ class TestMeteringPlugin(test_db_base_plugin_v2.NeutronDbPluginV2TestCase,
|
||||
|
||||
def test_delete_metering_label_does_not_clear_router_tenant_id(self):
|
||||
tenant_id = '654f6b9d-0f36-4ae5-bd1b-01616794ca60'
|
||||
# TODO(ralonsoh): to investigate why the context in [1] has some value
|
||||
# in session.transaction._connections, while during a normal operation,
|
||||
# the ._connections value is empty.
|
||||
# [1]https://github.com/openstack/neutron/blob/
|
||||
# 1b9e9a6c2ccf7f9bc06429f53e5126f356ae3d4a/neutron/api/v2/base.py#L563
|
||||
self.ctx.GUARD_TRANSACTION = False
|
||||
with self.metering_label(tenant_id=tenant_id) as metering_label:
|
||||
with self.router(tenant_id=tenant_id, set_context=True) as r:
|
||||
router = self._show('routers', r['router']['id'])
|
||||
|
@ -20,7 +20,7 @@ Jinja2>=2.10 # BSD License (3 clause)
|
||||
keystonemiddleware>=5.1.0 # Apache-2.0
|
||||
netaddr>=0.7.18 # BSD
|
||||
netifaces>=0.10.4 # MIT
|
||||
neutron-lib>=2.21.0 # Apache-2.0
|
||||
neutron-lib>=3.1.0 # Apache-2.0
|
||||
python-neutronclient>=7.8.0 # Apache-2.0
|
||||
tenacity>=6.0.0 # Apache-2.0
|
||||
SQLAlchemy>=1.4.23 # MIT
|
||||
|
Loading…
Reference in New Issue
Block a user