Switch to new engine facade in extensions unit tests
Partially-Implements blueprint: enginefacade-switch Change-Id: I582848bc8deec98a5e78f9e4b5c7f219a924aa47
This commit is contained in:
parent
a4d63e18cf
commit
1e970f1aa0
|
@ -17,6 +17,7 @@ from webob import exc as web_exc
|
|||
from neutron_lib.api.definitions import data_plane_status as dps_lib
|
||||
from neutron_lib.api.definitions import port as port_def
|
||||
from neutron_lib import constants
|
||||
from neutron_lib.db import api as db_api
|
||||
from neutron_lib.db import resource_extend
|
||||
from neutron_lib.tests.unit import fake_notifier
|
||||
|
||||
|
@ -54,7 +55,7 @@ class DataPlaneStatusExtensionTestPlugin(db_base_plugin_v2.NeutronDbPluginV2,
|
|||
port_res, port_db)
|
||||
|
||||
def update_port(self, context, id, port):
|
||||
with context.session.begin(subtransactions=True):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
ret_port = super(DataPlaneStatusExtensionTestPlugin,
|
||||
self).update_port(context, id, port)
|
||||
if dps_lib.DATA_PLANE_STATUS in port['port']:
|
||||
|
|
|
@ -17,6 +17,7 @@ import copy
|
|||
|
||||
from neutron_lib.api.definitions import extra_dhcp_opt as edo_ext
|
||||
from neutron_lib import constants
|
||||
from neutron_lib.db import api as db_api
|
||||
import webob.exc
|
||||
|
||||
from neutron.db import db_base_plugin_v2
|
||||
|
@ -37,7 +38,7 @@ class ExtraDhcpOptTestPlugin(db_base_plugin_v2.NeutronDbPluginV2,
|
|||
supported_extension_aliases = [edo_ext.ALIAS]
|
||||
|
||||
def create_port(self, context, port):
|
||||
with context.session.begin(subtransactions=True):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
edos = port['port'].get(edo_ext.EXTRADHCPOPTS, [])
|
||||
new_port = super(ExtraDhcpOptTestPlugin, self).create_port(
|
||||
context, port)
|
||||
|
@ -45,7 +46,7 @@ class ExtraDhcpOptTestPlugin(db_base_plugin_v2.NeutronDbPluginV2,
|
|||
return new_port
|
||||
|
||||
def update_port(self, context, id, port):
|
||||
with context.session.begin(subtransactions=True):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
rtn_port = super(ExtraDhcpOptTestPlugin, self).update_port(
|
||||
context, id, port)
|
||||
self._update_extra_dhcp_opts_on_port(context, id, port, rtn_port)
|
||||
|
|
|
@ -668,7 +668,7 @@ class FlavorPluginTestCase(test_db_base_plugin_v2.NeutronDbPluginV2TestCase,
|
|||
def test_delete_flavor_in_use(self):
|
||||
# make use of router since it has a flavor id
|
||||
fl, data = self._create_flavor()
|
||||
with self.ctx.session.begin():
|
||||
with db_api.CONTEXT_WRITER.using(self.ctx):
|
||||
self.ctx.session.add(l3_models.Router(flavor_id=fl['id']))
|
||||
self.assertRaises(
|
||||
flav_exc.FlavorInUse,
|
||||
|
|
|
@ -29,6 +29,7 @@ from neutron_lib.callbacks import registry
|
|||
from neutron_lib.callbacks import resources
|
||||
from neutron_lib import constants as lib_constants
|
||||
from neutron_lib import context
|
||||
from neutron_lib.db import api as db_api
|
||||
from neutron_lib.db import resource_extend
|
||||
from neutron_lib import exceptions as n_exc
|
||||
from neutron_lib.exceptions import l3 as l3_exc
|
||||
|
@ -258,8 +259,7 @@ class TestL3NatBasePlugin(TestL3PluginBaseAttributes,
|
|||
__native_sorting_support = True
|
||||
|
||||
def create_network(self, context, network):
|
||||
session = context.session
|
||||
with session.begin(subtransactions=True):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
net = super(TestL3NatBasePlugin, self).create_network(context,
|
||||
network)
|
||||
self._process_l3_create(context, net, network['network'])
|
||||
|
@ -267,8 +267,7 @@ class TestL3NatBasePlugin(TestL3PluginBaseAttributes,
|
|||
|
||||
def update_network(self, context, id, network):
|
||||
|
||||
session = context.session
|
||||
with session.begin(subtransactions=True):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
net = super(TestL3NatBasePlugin, self).update_network(context, id,
|
||||
network)
|
||||
self._process_l3_update(context, net, network['network'])
|
||||
|
@ -617,7 +616,7 @@ class ExtraAttributesMixinTestCase(testlib_api.SqlTestCase):
|
|||
directory.add_plugin(plugin_constants.L3, self.mixin)
|
||||
self.ctx = context.get_admin_context()
|
||||
self.router = l3_models.Router()
|
||||
with self.ctx.session.begin():
|
||||
with db_api.CONTEXT_WRITER.using(self.ctx):
|
||||
self.ctx.session.add(self.router)
|
||||
|
||||
def _get_default_api_values(self):
|
||||
|
@ -626,7 +625,7 @@ class ExtraAttributesMixinTestCase(testlib_api.SqlTestCase):
|
|||
|
||||
def test_set_extra_attr_key_bad(self):
|
||||
with testtools.ExpectedException(RuntimeError):
|
||||
with self.ctx.session.begin():
|
||||
with db_api.CONTEXT_WRITER.using(self.ctx):
|
||||
self.mixin.set_extra_attr_value(self.ctx, self.router,
|
||||
'bad', 'value')
|
||||
|
||||
|
@ -641,25 +640,25 @@ class ExtraAttributesMixinTestCase(testlib_api.SqlTestCase):
|
|||
self.assertEqual(self._get_default_api_values(), rdict)
|
||||
|
||||
def test_set_attrs_and_extend(self):
|
||||
with self.ctx.session.begin():
|
||||
with db_api.CONTEXT_WRITER.using(self.ctx):
|
||||
self.mixin.set_extra_attr_value(self.ctx, self.router,
|
||||
'ha_vr_id', 99)
|
||||
self.mixin.set_extra_attr_value(self.ctx, self.router,
|
||||
'availability_zone_hints',
|
||||
['x', 'y', 'z'])
|
||||
expected = self._get_default_api_values()
|
||||
expected.update({'ha_vr_id': 99,
|
||||
'availability_zone_hints': ['x', 'y', 'z']})
|
||||
rdict = {}
|
||||
self.mixin._extend_extra_router_dict(rdict, self.router)
|
||||
self.assertEqual(expected, rdict)
|
||||
with self.ctx.session.begin():
|
||||
expected = self._get_default_api_values()
|
||||
expected.update({'ha_vr_id': 99,
|
||||
'availability_zone_hints': ['x', 'y', 'z']})
|
||||
rdict = {}
|
||||
self.mixin._extend_extra_router_dict(rdict, self.router)
|
||||
self.assertEqual(expected, rdict)
|
||||
|
||||
self.mixin.set_extra_attr_value(self.ctx, self.router,
|
||||
'availability_zone_hints',
|
||||
['z', 'y', 'z'])
|
||||
expected['availability_zone_hints'] = ['z', 'y', 'z']
|
||||
self.mixin._extend_extra_router_dict(rdict, self.router)
|
||||
self.assertEqual(expected, rdict)
|
||||
expected['availability_zone_hints'] = ['z', 'y', 'z']
|
||||
self.mixin._extend_extra_router_dict(rdict, self.router)
|
||||
self.assertEqual(expected, rdict)
|
||||
|
||||
|
||||
class L3NatTestCaseBase(L3NatTestCaseMixin):
|
||||
|
@ -3407,7 +3406,7 @@ class L3NatTestCaseBase(L3NatTestCaseMixin):
|
|||
def mock_fail__update_router_gw_info(ctx, router_id, info,
|
||||
router=None):
|
||||
# Fail with breaking transaction
|
||||
with ctx.session.begin(subtransactions=True):
|
||||
with db_api.CONTEXT_WRITER.using(self.ctx):
|
||||
raise n_exc.NeutronException
|
||||
|
||||
mock.patch.object(plugin, '_update_router_gw_info',
|
||||
|
@ -3415,7 +3414,7 @@ class L3NatTestCaseBase(L3NatTestCaseMixin):
|
|||
|
||||
def create_router_with_transaction(ctx, data):
|
||||
# Emulates what many plugins do
|
||||
with ctx.session.begin(subtransactions=True):
|
||||
with db_api.CONTEXT_WRITER.using(ctx):
|
||||
plugin.create_router(ctx, data)
|
||||
|
||||
# Verify router doesn't persist on failure
|
||||
|
@ -3438,11 +3437,11 @@ class L3NatTestCaseBase(L3NatTestCaseMixin):
|
|||
def mock_fail__update_router_gw_info(ctx, router_id, info,
|
||||
router=None):
|
||||
# Fail with breaking transaction
|
||||
with ctx.session.begin(subtransactions=True):
|
||||
with db_api.CONTEXT_WRITER.using(ctx):
|
||||
raise n_exc.NeutronException
|
||||
|
||||
def mock_fail_delete_router(ctx, router_id):
|
||||
with ctx.session.begin(subtransactions=True):
|
||||
with db_api.CONTEXT_WRITER.using(ctx):
|
||||
raise Exception()
|
||||
|
||||
mock.patch.object(plugin, '_update_router_gw_info',
|
||||
|
@ -3452,7 +3451,7 @@ class L3NatTestCaseBase(L3NatTestCaseMixin):
|
|||
|
||||
def create_router_with_transaction(ctx, data):
|
||||
# Emulates what many plugins do
|
||||
with ctx.session.begin(subtransactions=True):
|
||||
with db_api.CONTEXT_WRITER.using(ctx):
|
||||
plugin.create_router(ctx, data)
|
||||
|
||||
# Verify router doesn't persist on failure
|
||||
|
@ -3475,13 +3474,13 @@ class L3NatTestCaseBase(L3NatTestCaseMixin):
|
|||
|
||||
def mock_update_port_with_transaction(ctx, id, port):
|
||||
# Update port within a sub-transaction
|
||||
with ctx.session.begin(subtransactions=True):
|
||||
with db_api.CONTEXT_WRITER.using(ctx):
|
||||
orig_update_port(ctx, id, port)
|
||||
|
||||
def add_router_interface_with_transaction(ctx, router_id,
|
||||
interface_info):
|
||||
# Call add_router_interface() within a sub-transaction
|
||||
with ctx.session.begin():
|
||||
with db_api.CONTEXT_WRITER.using(ctx):
|
||||
plugin.add_router_interface(ctx, router_id, interface_info)
|
||||
|
||||
tenant_id = _uuid()
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
# under the License.
|
||||
|
||||
from neutron_lib.api.definitions import vlantransparent as vlan_apidef
|
||||
from neutron_lib.db import api as db_api
|
||||
from oslo_config import cfg
|
||||
from webob import exc as web_exc
|
||||
|
||||
|
@ -46,7 +47,7 @@ class VlanTransparentExtensionTestPlugin(db_base_plugin_v2.NeutronDbPluginV2,
|
|||
supported_extension_aliases = [vlan_apidef.ALIAS]
|
||||
|
||||
def create_network(self, context, network):
|
||||
with context.session.begin(subtransactions=True):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
new_net = super(VlanTransparentExtensionTestPlugin,
|
||||
self).create_network(context, network)
|
||||
# Update the vlan_transparent in the database
|
||||
|
|
Loading…
Reference in New Issue