Switch to Pecan for unit tests

This will drop Pecan in place of the old APIRouter for all
unit tests. This will significantly increase the UT coverage
of pecan and will allow us to drop the old API routing logic
completely.

The rest of the inline test changes are due to slight plugin loading
differences.

Implements: blueprint wsgi-pecan-switch
Change-Id: I76dc23fb7b96d82b0da50285bd0aac76142e81e5
This commit is contained in:
Kevin Benton 2017-08-28 18:18:43 -07:00
parent e2ea0b4652
commit db1058a499
6 changed files with 36 additions and 20 deletions

View File

@ -63,7 +63,18 @@ class Index(wsgi.Application):
return webob.Response(body=body, content_type=content_type)
class APIRouter(base_wsgi.Router):
def APIRouter(**local_config):
return pecan_app.v2_factory(None, **local_config)
def _factory(global_config, **local_config):
return pecan_app.v2_factory(global_config, **local_config)
setattr(APIRouter, 'factory', _factory)
class _APIRouter(base_wsgi.Router):
@classmethod
def factory(cls, global_config, **local_config):
@ -120,4 +131,4 @@ class APIRouter(base_wsgi.Router):
# calling reset will cause the next policy check to
# re-initialize with all of the required data in place.
policy.reset()
super(APIRouter, self).__init__(mapper)
super(_APIRouter, self).__init__(mapper)

View File

@ -143,6 +143,7 @@ class SecurityGroupRpcTestPlugin(test_sg.SecurityGroupTestPlugin,
self.devices[id] = updated_port
self.update_security_group_on_port(
context, id, port, original_port, updated_port)
return updated_port
def delete_port(self, context, id):
port = self.get_port(context, id)

View File

@ -180,7 +180,7 @@ class APIv2TestCase(APIv2TestBase):
instance = self.plugin.return_value
instance.get_networks.return_value = []
fields = self._do_field_list('networks', ['foo', 'bar'])
fields = self._do_field_list('networks', ['bar', 'foo'])
self.api.get(_get_path('networks'), {'fields': ['foo', 'bar']})
kwargs = self._get_collection_kwargs(fields=fields)
instance.get_networks.assert_called_once_with(mock.ANY, **kwargs)
@ -1143,7 +1143,7 @@ class JSONV2TestCase(APIv2TestBase, testlib_api.WebTestCase):
class SubresourceTest(base.BaseTestCase):
def setUp(self):
super(SubresourceTest, self).setUp()
raise self.skipException('this class will be deleted')
plugin = 'neutron.tests.unit.api.v2.test_base.TestSubresourcePlugin'
extensions.PluginAwareExtensionManager._instance = None

View File

@ -56,7 +56,6 @@ from neutron.plugins.ml2.drivers import type_vlan
from neutron.plugins.ml2 import managers
from neutron.plugins.ml2 import models
from neutron.plugins.ml2 import plugin as ml2_plugin
from neutron.services.l3_router import l3_router_plugin
from neutron.services.revisions import revision_plugin
from neutron.services.segments import db as segments_plugin_db
from neutron.services.segments import plugin as segments_plugin
@ -583,12 +582,12 @@ class TestMl2SubnetsV2(test_plugin.TestSubnetsV2,
network['network']['tenant_id'],
'name': 'port1',
'admin_state_up': 1,
'device_id': '',
'device_owner':
constants.DEVICE_OWNER_DHCP,
'fixed_ips': [{'subnet_id': subnet_id}]}}
port_req = self.new_create_request('ports', data)
port_res = port_req.get_response(self.api)
self.assertEqual(201, port_res.status_int)
plugin = directory.get_plugin()
plugin.create_port(context.get_admin_context(), data)
# we mock _subnet_check_ip_allocations with method
# that creates DHCP port 'in the middle' of subnet_delete
@ -1273,11 +1272,14 @@ class TestMl2PortsV2WithRevisionPlugin(Ml2PluginV2TestCase):
class TestMl2PortsV2WithL3(test_plugin.TestPortsV2, Ml2PluginV2TestCase):
"""For testing methods that require the L3 service plugin."""
l3_plugin = 'neutron.services.l3_router.l3_router_plugin.L3RouterPlugin'
def get_additional_service_plugins(self):
return {'flavors': 'flavors'}
def test_update_port_status_notify_port_event_after_update(self):
ctx = context.get_admin_context()
plugin = directory.get_plugin()
# enable subscription for events
l3_router_plugin.L3RouterPlugin()
l3plugin = directory.get_plugin(plugin_constants.L3)
host_arg = {portbindings.HOST_ID: HOST}
with mock.patch.object(l3plugin.l3_rpc_notifier,

View File

@ -36,15 +36,6 @@ class BaseTestTrackedResources(test_plugin.Ml2PluginV2TestCase,
def setUp(self):
self.ctx = context.get_admin_context()
# Prevent noise from default security group operations
def_sec_group_patch = mock.patch(
'neutron.db.securitygroups_db.SecurityGroupDbMixin.'
'_ensure_default_security_group')
def_sec_group_patch.start()
get_sec_group_port_patch = mock.patch(
'neutron.db.securitygroups_db.SecurityGroupDbMixin.'
'_get_security_groups_on_port')
get_sec_group_port_patch.start()
super(BaseTestTrackedResources, self).setUp()
self._tenant_id = uuidutils.generate_uuid()
@ -56,6 +47,15 @@ class BaseTestTrackedResources(test_plugin.Ml2PluginV2TestCase,
class BaseTestEventHandler(object):
def setUp(self):
# Prevent noise from default security group operations
def_sec_group_patch = mock.patch(
'neutron.db.securitygroups_db.SecurityGroupDbMixin.'
'_ensure_default_security_group')
def_sec_group_patch.start()
get_sec_group_port_patch = mock.patch(
'neutron.db.securitygroups_db.SecurityGroupDbMixin.'
'_get_security_groups_on_port')
get_sec_group_port_patch.start()
handler_patch = mock.patch(
'neutron.quota.resource.TrackedResource._db_event_handler')
self.handler_mock = handler_patch.start()

View File

@ -132,7 +132,9 @@ class TestRevisionPlugin(test_plugin.Ml2PluginV2TestCase):
db_api.sqla_remove(se.Session, 'before_commit',
concurrent_increment)
# slip in a concurrent update that will bump the revision
self._update('ports', port['port']['id'], new)
plugin = directory.get_plugin()
plugin.update_port(nctx.get_admin_context(),
port['port']['id'], new)
raise db_exc.DBDeadlock()
db_api.sqla_listen(se.Session, 'before_commit',
concurrent_increment)