TestTrackedResource: register core plugin in directory

This is achieved by switching the test class to BaseTestCase and using
setup_coreplugin. This makes later calls to neutron.objects.db.api
functions that extract the plugin from plugins directory to work.

The test class registers some sqlalchemy events for models not
registered in BASEV2, which later makes unregister_events fail because
of failure to compare those model classes with other registered model
classes (those that belong to proper model classes like Port). Before
the patch, the core plugin was not correctly registered in plugins
directory, and no code was actually loading the plugin, so no other
sqla events were in _REGISTERED_SQLA_EVENTS, which explains why
previously calls to unregister_events hasn't failed.

Good news is that the new parent class does clean up all events itself,
so we don't need to set the cleanup hook ourselves.

This switch also facilitated removal of some other preparatory steps
from the class that are already implemented in the new parent.

Closes-Bug: #1677636
Change-Id: Id462e532066ac3cd5e2f76c3670da7f7820c6581
This commit is contained in:
Ihar Hrachyshka 2017-03-30 15:56:29 +00:00
parent f58904e669
commit 8a0faef877
1 changed files with 5 additions and 12 deletions

View File

@ -60,7 +60,7 @@ class TestResource(base.DietTestCase):
self.assertEqual(-1, res.default)
class TestTrackedResource(testlib_api.SqlTestCaseLight):
class TestTrackedResource(testlib_api.SqlTestCase):
def _add_data(self, tenant_id=None):
session = db_api.get_writer_session()
@ -91,31 +91,24 @@ class TestTrackedResource(testlib_api.SqlTestCaseLight):
session.add(item)
def setUp(self):
base.BaseTestCase.config_parse()
cfg.CONF.register_opts(meh_quota_opts, 'QUOTAS')
cfg.CONF.set_override("core_plugin", DB_PLUGIN_KLASS)
self.addCleanup(cfg.CONF.reset)
super(TestTrackedResource, self).setUp()
self.setup_coreplugin(DB_PLUGIN_KLASS)
self.resource = 'meh'
self.other_resource = 'othermeh'
self.tenant_id = 'meh'
self.context = context.Context(
user_id='', tenant_id=self.tenant_id, is_admin=False)
super(TestTrackedResource, self).setUp()
def _register_events(self, res):
res.register_events()
self.addCleanup(res.unregister_events)
def _create_resource(self):
res = resource.TrackedResource(
self.resource, test_quota.MehModel, meh_quota_flag)
self._register_events(res)
res.register_events()
return res
def _create_other_resource(self):
res = resource.TrackedResource(
self.other_resource, test_quota.OtherMehModel, meh_quota_flag)
self._register_events(res)
res.register_events()
return res
def test_bulk_delete_protection(self):