Isolate backend loading

Pecan uses thread local storage and so if we combine pecan and eventlet
we need to make sure that eventlet is monkey patched before pecan is
first loaded.

To keep the paste.ini file untouched we need to keep the app creation in
service.py but we can't load that from keystone-all because it has pecan
in it.

So we create a new file that can be safely imported before pecan is
loaded.

Change-Id: If7abf1db9859d66c06f7f223056c106292f256fa
blueprint: keystone-pecan
This commit is contained in:
Jamie Lennox 2014-02-18 16:47:59 +10:00
parent 40ee25fb81
commit 22b734fa60
5 changed files with 54 additions and 34 deletions

View File

@ -41,6 +41,7 @@ from keystone.openstack.common import gettextutils
# gettextutils._() is called at import time. # gettextutils._() is called at import time.
gettextutils.enable_lazy() gettextutils.enable_lazy()
from keystone import backends
from keystone.common import dependency from keystone.common import dependency
from keystone.common import environment from keystone.common import environment
from keystone.common import sql from keystone.common import sql
@ -48,7 +49,6 @@ from keystone.common import utils
from keystone import config from keystone import config
from keystone.openstack.common.gettextutils import _ from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import importutils from keystone.openstack.common import importutils
from keystone import service
CONF = config.CONF CONF = config.CONF
@ -131,7 +131,7 @@ if __name__ == '__main__':
monkeypatch_thread = False monkeypatch_thread = False
environment.use_eventlet(monkeypatch_thread) environment.use_eventlet(monkeypatch_thread)
service.load_backends() backends.load_backends()
servers = [] servers = []
servers.append(create_server(paste_config, servers.append(create_server(paste_config,

View File

@ -24,12 +24,12 @@ from keystone.openstack.common import gettextutils
# gettextutils._() is called at import time. # gettextutils._() is called at import time.
gettextutils.enable_lazy() gettextutils.enable_lazy()
from keystone import backends
from keystone.common import dependency from keystone.common import dependency
from keystone.common import environment from keystone.common import environment
from keystone.common import sql from keystone.common import sql
from keystone import config from keystone import config
from keystone.openstack.common import log from keystone.openstack.common import log
from keystone import service
CONF = config.CONF CONF = config.CONF
@ -48,7 +48,7 @@ if CONF.debug:
CONF.log_opt_values(log.getLogger(CONF.prog), logging.DEBUG) CONF.log_opt_values(log.getLogger(CONF.prog), logging.DEBUG)
drivers = service.load_backends() drivers = backends.load_backends()
# NOTE(ldbragst): 'application' is required in this context by WSGI spec. # NOTE(ldbragst): 'application' is required in this context by WSGI spec.
# The following is a reference to Python Paste Deploy documentation # The following is a reference to Python Paste Deploy documentation

48
keystone/backends.py Normal file
View File

@ -0,0 +1,48 @@
# 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.
from keystone import assignment
from keystone import auth
from keystone import catalog
from keystone.common import cache
from keystone.contrib import endpoint_filter
from keystone import credential
from keystone import identity
from keystone import policy
from keystone import token
from keystone import trust
def load_backends():
# Configure and build the cache
cache.configure_cache_region(cache.REGION)
# Ensure that the identity driver is created before the assignment manager.
# The default assignment driver is determined by the identity driver, so
# the identity driver must be available to the assignment manager.
_IDENTITY_API = identity.Manager()
DRIVERS = dict(
assignment_api=assignment.Manager(),
catalog_api=catalog.Manager(),
credential_api=credential.Manager(),
endpoint_filter_api=endpoint_filter.Manager(),
identity_api=_IDENTITY_API,
policy_api=policy.Manager(),
token_api=token.Manager(),
trust_api=trust.Manager(),
token_provider_api=token.provider.Manager())
auth.controllers.load_auth_methods()
return DRIVERS

View File

@ -20,10 +20,8 @@ import routes
from keystone import assignment from keystone import assignment
from keystone import auth from keystone import auth
from keystone import catalog from keystone import catalog
from keystone.common import cache
from keystone.common import wsgi from keystone.common import wsgi
from keystone import config from keystone import config
from keystone.contrib import endpoint_filter
from keystone import controllers from keystone import controllers
from keystone import credential from keystone import credential
from keystone import identity from keystone import identity
@ -38,32 +36,6 @@ CONF = config.CONF
LOG = log.getLogger(__name__) LOG = log.getLogger(__name__)
def load_backends():
# Configure and build the cache
cache.configure_cache_region(cache.REGION)
# Ensure that the identity driver is created before the assignment manager.
# The default assignment driver is determined by the identity driver, so
# the identity driver must be available to the assignment manager.
_IDENTITY_API = identity.Manager()
DRIVERS = dict(
assignment_api=assignment.Manager(),
catalog_api=catalog.Manager(),
credential_api=credential.Manager(),
endpoint_filter_api=endpoint_filter.Manager(),
identity_api=_IDENTITY_API,
policy_api=policy.Manager(),
token_api=token.Manager(),
trust_api=trust.Manager(),
token_provider_api=token.provider.Manager())
auth.controllers.load_auth_methods()
return DRIVERS
def fail_gracefully(f): def fail_gracefully(f):
"""Logs exceptions and aborts.""" """Logs exceptions and aborts."""
@functools.wraps(f) @functools.wraps(f)

View File

@ -42,6 +42,7 @@ from keystone.common import environment
environment.use_eventlet() environment.use_eventlet()
from keystone import auth from keystone import auth
from keystone import backends
from keystone.common import dependency from keystone.common import dependency
from keystone.common import kvs from keystone.common import kvs
from keystone.common.kvs import core as kvs_core from keystone.common.kvs import core as kvs_core
@ -52,7 +53,6 @@ from keystone import notifications
from keystone.openstack.common.fixture import config as config_fixture from keystone.openstack.common.fixture import config as config_fixture
from keystone.openstack.common.gettextutils import _ from keystone.openstack.common.gettextutils import _
from keystone.openstack.common import log from keystone.openstack.common import log
from keystone import service
from keystone.tests import ksfixtures from keystone.tests import ksfixtures
# NOTE(dstanek): Tests inheriting from TestCase depend on having the # NOTE(dstanek): Tests inheriting from TestCase depend on having the
@ -436,7 +436,7 @@ class TestCase(BaseTestCase):
kvs_core.KEY_VALUE_STORE_REGISTRY.clear() kvs_core.KEY_VALUE_STORE_REGISTRY.clear()
self.clear_auth_plugin_registry() self.clear_auth_plugin_registry()
drivers = service.load_backends() drivers = backends.load_backends()
drivers.update(dependency.resolve_future_dependencies()) drivers.update(dependency.resolve_future_dependencies())