Skip to content

Commit

Permalink
Manager instead of direct driver
Browse files Browse the repository at this point in the history
Make calls via the manager as opposed to the drivers
in order to support refactoring of common code

Bug 1193420

Change-Id: I69117ea755ed7ef3f7d3732fee83cc758927d296
  • Loading branch information
Adam Young committed Jun 28, 2013
1 parent 911c315 commit 431cecb
Show file tree
Hide file tree
Showing 8 changed files with 228 additions and 264 deletions.
19 changes: 4 additions & 15 deletions keystone/test.py
Expand Up @@ -56,8 +56,6 @@
TESTSDIR = os.path.join(ROOTDIR, 'tests')
ETCDIR = os.path.join(ROOTDIR, 'etc')
CONF = config.CONF
DRIVERS = {}


cd = os.chdir

Expand All @@ -77,16 +75,6 @@ def testsdir(*p):
return os.path.join(TESTSDIR, *p)


def initialize_drivers():
DRIVERS['catalog_api'] = catalog.Manager()
DRIVERS['credential_api'] = credential.Manager()
DRIVERS['identity_api'] = identity.Manager()
DRIVERS['policy_api'] = policy.Manager()
DRIVERS['token_api'] = token.Manager()
DRIVERS['trust_api'] = trust.Manager()
return DRIVERS


def checkout_vendor(repo, rev):
# TODO(termie): this function is a good target for some optimizations :PERF
name = repo.split('/')[-1]
Expand Down Expand Up @@ -234,9 +222,10 @@ def opt(self, **kw):
CONF.set_override(k, v)

def load_backends(self):
"""Create shortcut references to each driver for data manipulation."""
for name, manager in initialize_drivers().iteritems():
setattr(self, name, manager.driver)
"""Initializes each manager and assigns them to an attribute."""
for manager in [catalog, credential, identity, policy, token, trust]:
manager_name = '%s_api' % manager.__name__.split('.')[-1]
setattr(self, manager_name, manager.Manager())

def load_fixtures(self, fixtures):
"""Hacky basic and naive fixture loading based on a python module.
Expand Down
290 changes: 145 additions & 145 deletions tests/test_backend.py

Large diffs are not rendered by default.

40 changes: 21 additions & 19 deletions tests/test_backend_kvs.py
Expand Up @@ -19,12 +19,8 @@

from keystone import test

from keystone import catalog
from keystone.catalog.backends import kvs as catalog_kvs
from keystone import exception
from keystone import identity
from keystone.token.backends import kvs as token_kvs
from keystone.trust.backends import kvs as trust_kvs

import default_fixtures
import test_backend
Expand All @@ -33,10 +29,9 @@
class KvsIdentity(test.TestCase, test_backend.IdentityTests):
def setUp(self):
super(KvsIdentity, self).setUp()
identity.CONF.identity.driver = \
'keystone.identity.backends.kvs.Identity'
self.identity_man = identity.Manager()
self.identity_api = self.identity_man.driver
identity.CONF.identity.driver = (
'keystone.identity.backends.kvs.Identity')
self.load_backends()
self.load_fixtures(default_fixtures)

def test_list_user_projects(self):
Expand Down Expand Up @@ -74,31 +69,38 @@ def test_move_project_between_domains_with_clashing_names_fails(self):
class KvsToken(test.TestCase, test_backend.TokenTests):
def setUp(self):
super(KvsToken, self).setUp()
self.token_api = token_kvs.Token(db={})
identity.CONF.identity.driver = (
'keystone.identity.backends.kvs.Identity')
self.load_backends()


class KvsTrust(test.TestCase, test_backend.TrustTests):
def setUp(self):
super(KvsTrust, self).setUp()
identity.CONF.identity.driver = \
'keystone.identity.backends.kvs.Identity'
self.identity_man = identity.Manager()
self.identity_api = self.identity_man.driver
self.trust_api = trust_kvs.Trust(db={})
self.catalog_api = catalog_kvs.Catalog(db={})
identity.CONF.identity.driver = (
'keystone.identity.backends.kvs.Identity')
identity.CONF.trust.driver = (
'keystone.trust.backends.kvs.Trust')
identity.CONF.catalog.driver = (
'keystone.catalog.backends.kvs.Catalog')
self.load_backends()
self.load_fixtures(default_fixtures)


class KvsCatalog(test.TestCase, test_backend.CatalogTests):
def setUp(self):
super(KvsCatalog, self).setUp()
self.catalog_api = catalog_kvs.Catalog(db={})
self.catalog_man = catalog.Manager()
self.load_fixtures(default_fixtures)
identity.CONF.identity.driver = (
'keystone.identity.backends.kvs.Identity')
identity.CONF.trust.driver = (
'keystone.trust.backends.kvs.Trust')
identity.CONF.catalog.driver = (
'keystone.catalog.backends.kvs.Catalog')
self.load_backends()
self._load_fake_catalog()

def _load_fake_catalog(self):
self.catalog_foobar = self.catalog_api._create_catalog(
self.catalog_foobar = self.catalog_api.driver._create_catalog(
'foo', 'bar',
{'RegionFoo': {'service_bar': {'foo': 'bar'}}})

Expand Down

0 comments on commit 431cecb

Please sign in to comment.