Adds a backend test fixture

Moves the existing backend setup logic into a fixture. Future commits
will make it possible to just specify the backends needed for a
particular commit.

Change-Id: Ic4a9637a34d9523e6da46e3ea705676b34cf67a5
This commit is contained in:
David Stanek 2016-06-24 13:00:24 +00:00
parent c52425428b
commit e03cfcda4d
3 changed files with 57 additions and 24 deletions

View File

@ -41,16 +41,13 @@ from sqlalchemy import exc
import testtools
from testtools import testcase
from keystone import auth
from keystone.common import dependency
from keystone.common.kvs import core as kvs_core
from keystone.common import request
from keystone.common import sql
import keystone.conf
from keystone import exception
from keystone.identity.backends.ldap import common as ks_ldap
from keystone import notifications
from keystone.server import common
from keystone.tests.unit import ksfixtures
from keystone.version import controllers
from keystone.version import service
@ -694,23 +691,7 @@ class TestCase(BaseTestCase):
def load_backends(self):
"""Initialize each manager and assigns them to an attribute."""
# TODO(blk-u): Shouldn't need to clear the registry here, but some
# tests call load_backends multiple times. These should be fixed to
# only call load_backends once.
dependency.reset()
# TODO(morganfainberg): Shouldn't need to clear the registry here, but
# some tests call load_backends multiple times. Since it is not
# possible to re-configure a backend, we need to clear the list. This
# should eventually be removed once testing has been cleaned up.
kvs_core.KEY_VALUE_STORE_REGISTRY.clear()
self.clear_auth_plugin_registry()
drivers, _unused = common.setup_backends()
for manager_name, manager in drivers.items():
setattr(self, manager_name, manager)
self.addCleanup(self.cleanup_instance(*list(drivers.keys())))
self.useFixture(ksfixtures.BackendLoader(self))
def load_fixtures(self, fixtures):
"""Hacky basic and naive fixture loading based on a python module.
@ -817,10 +798,6 @@ class TestCase(BaseTestCase):
def loadapp(self, config, name='main'):
return service.loadapp(self._paste_config(config), name=name)
def clear_auth_plugin_registry(self):
auth.controllers.AUTH_METHODS.clear()
auth.controllers.AUTH_PLUGINS_LOADED = False
def assertCloseEnoughForGovernmentWork(self, a, b, delta=3):
"""Assert that two datetimes are nearly equal within a small delta.

View File

@ -12,6 +12,7 @@
# limitations under the License.
from keystone.tests.unit.ksfixtures.auth_plugins import ConfigAuthPlugins # noqa
from keystone.tests.unit.ksfixtures.backendloader import BackendLoader # noqa
from keystone.tests.unit.ksfixtures.cache import Cache # noqa
from keystone.tests.unit.ksfixtures.key_repository import KeyRepository # noqa
from keystone.tests.unit.ksfixtures.policy import Policy # noqa

View File

@ -0,0 +1,55 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import fixtures
from keystone import auth
from keystone.common import dependency
from keystone.common.kvs import core as kvs_core
from keystone.server import common
class BackendLoader(fixtures.Fixture):
"""Initialize each manager and assigns them to an attribute."""
def __init__(self, testcase):
super(BackendLoader, self).__init__()
self._testcase = testcase
def setUp(self):
super(BackendLoader, self).setUp()
# TODO(blk-u): Shouldn't need to clear the registry here, but some
# tests call load_backends multiple times. These should be fixed to
# only call load_backends once.
dependency.reset()
# TODO(morganfainberg): Shouldn't need to clear the registry here, but
# some tests call load_backends multiple times. Since it is not
# possible to re-configure a backend, we need to clear the list. This
# should eventually be removed once testing has been cleaned up.
kvs_core.KEY_VALUE_STORE_REGISTRY.clear()
self.clear_auth_plugin_registry()
drivers, _unused = common.setup_backends()
for manager_name, manager in drivers.items():
setattr(self._testcase, manager_name, manager)
self.addCleanup(self._testcase.cleanup_instance(*list(drivers.keys())))
del self._testcase # break circular reference
def clear_auth_plugin_registry(self):
auth.controllers.AUTH_METHODS.clear()
auth.controllers.AUTH_PLUGINS_LOADED = False