Switch to new engine facade in ML2 unit tests modules

Partially-Implements blueprint: enginefacade-switch

Change-Id: I4aff27fba6e8dd2e3574ed54dc79f8c75000125d
This commit is contained in:
Slawek Kaplonski 2020-03-26 04:28:16 +01:00
parent 890392a388
commit f11707e180
5 changed files with 27 additions and 24 deletions

View File

@ -16,6 +16,7 @@ import netaddr
from neutron_lib.api.definitions import portbindings
from neutron_lib import constants
from neutron_lib import context
from neutron_lib.db import api as db_api
from neutron_lib.tests import tools
from neutron_lib.utils import net
from oslo_utils import uuidutils
@ -53,7 +54,7 @@ class TestL2PopulationDBTestCase(testlib_api.SqlTestCase):
network_obj.Network(self.ctx, id=network_id).create()
def _create_router(self, distributed=True, ha=False):
with self.ctx.session.begin(subtransactions=True):
with db_api.CONTEXT_WRITER.using(self.ctx):
self.ctx.session.add(l3_models.Router(id=TEST_ROUTER_ID))
l3_objs.RouterExtraAttributes(
self.ctx,
@ -67,7 +68,7 @@ class TestL2PopulationDBTestCase(testlib_api.SqlTestCase):
# Tests should test that host3 is not a HA agent host.
helpers.register_l3_agent(HOST_3)
helpers.register_ovs_agent(HOST_3, tunneling_ip=HOST_3_TUNNELING_IP)
with self.ctx.session.begin(subtransactions=True):
with db_api.CONTEXT_WRITER.using(self.ctx):
network_obj.Network(self.ctx, id=TEST_HA_NETWORK_ID).create()
self._create_router(distributed=distributed, ha=True)
for state, host in [(constants.HA_ROUTER_STATE_ACTIVE, HOST),
@ -100,7 +101,7 @@ class TestL2PopulationDBTestCase(testlib_api.SqlTestCase):
self.assertIsNone(agent)
def _setup_port_binding(self, **kwargs):
with self.ctx.session.begin(subtransactions=True):
with db_api.CONTEXT_WRITER.using(self.ctx):
mac = netaddr.EUI(
net.get_random_mac('fa:16:3e:00:00:00'.split(':')),
dialect=netaddr.mac_unix_expanded)

View File

@ -328,7 +328,7 @@ class Ml2DvrDBTestCase(testlib_api.SqlTestCase):
return ports
def _setup_neutron_router(self):
with self.ctx.session.begin(subtransactions=True):
with db_api.CONTEXT_WRITER.using(self.ctx):
router = l3_models.Router()
self.ctx.session.add(router)
return router

View File

@ -13,6 +13,7 @@
import mock
from neutron_lib import context
from neutron_lib.db import api as db_api
from neutron_lib.plugins import directory
from neutron.objects import network
@ -93,7 +94,7 @@ class OVOServerRpcInterfaceTestCase(test_plugin.Ml2PluginV2TestCase):
def test_transaction_state_error_doesnt_notify(self):
# running in a transaction should cause it to skip notification since
# fresh reads aren't possible.
with self.ctx.session.begin():
with db_api.CONTEXT_WRITER.using(self.ctx):
self.plugin.create_security_group(
self.ctx, {'security_group': {'tenant_id': 'test',
'description': 'desc',

View File

@ -2394,26 +2394,26 @@ class TestMl2PortBinding(Ml2PluginV2TestCase,
self._check_port_binding_profile(port, profile)
def test_update_port_binding_host_id_none(self):
with self.port() as port:
plugin = directory.get_plugin()
binding = p_utils.get_port_binding_by_status_and_host(
plugin._get_port(self.context,
port['port']['id']).port_bindings,
constants.ACTIVE)
with self.context.session.begin(subtransactions=True):
with db_api.CONTEXT_WRITER.using(self.context):
with self.port() as port:
plugin = directory.get_plugin()
binding = p_utils.get_port_binding_by_status_and_host(
plugin._get_port(self.context,
port['port']['id']).port_bindings,
constants.ACTIVE)
binding.host = 'test'
mech_context = driver_context.PortContext(
plugin, self.context, port['port'],
plugin.get_network(self.context, port['port']['network_id']),
binding, None)
with mock.patch('neutron.plugins.ml2.plugin.Ml2Plugin.'
'_update_port_dict_binding') as update_mock:
attrs = {portbindings.HOST_ID: None}
self.assertEqual('test', binding.host)
with self.context.session.begin(subtransactions=True):
mech_context = driver_context.PortContext(
plugin, self.context, port['port'],
plugin.get_network(
self.context, port['port']['network_id']),
binding, None)
with mock.patch('neutron.plugins.ml2.plugin.Ml2Plugin.'
'_update_port_dict_binding') as update_mock:
attrs = {portbindings.HOST_ID: None}
self.assertEqual('test', binding.host)
plugin._process_port_binding(mech_context, attrs)
self.assertTrue(update_mock.mock_calls)
self.assertEqual('', binding.host)
self.assertTrue(update_mock.mock_calls)
self.assertEqual('', binding.host)
def test_update_port_binding_host_id_not_changed(self):
with self.port() as port:

View File

@ -18,6 +18,7 @@ from neutron_lib.api.definitions import portbindings
from neutron_lib.api.definitions import portbindings_extended as pbe_ext
from neutron_lib import constants as const
from neutron_lib import context
from neutron_lib.db import api as db_api
from neutron_lib import exceptions
from neutron_lib.plugins import directory
from neutron_lib.plugins import utils
@ -118,7 +119,7 @@ class PortBindingTestCase(test_plugin.NeutronDbPluginV2TestCase):
ctx = context.get_admin_context()
with self.port(name='name') as port:
# emulating concurrent binding deletion
with ctx.session.begin():
with db_api.CONTEXT_WRITER.using(ctx):
for item in (ctx.session.query(ml2_models.PortBinding).
filter_by(port_id=port['port']['id'])):
ctx.session.delete(item)