From 22b734fa60ccc25749e318be4ced478fcdb8d23c Mon Sep 17 00:00:00 2001 From: Jamie Lennox Date: Tue, 18 Feb 2014 16:47:59 +1000 Subject: [PATCH] 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 --- bin/keystone-all | 4 ++-- httpd/keystone.py | 4 ++-- keystone/backends.py | 48 ++++++++++++++++++++++++++++++++++++++++++ keystone/service.py | 28 ------------------------ keystone/tests/core.py | 4 ++-- 5 files changed, 54 insertions(+), 34 deletions(-) create mode 100644 keystone/backends.py diff --git a/bin/keystone-all b/bin/keystone-all index 8d7c4b3dc7..fa14bbb819 100755 --- a/bin/keystone-all +++ b/bin/keystone-all @@ -41,6 +41,7 @@ from keystone.openstack.common import gettextutils # gettextutils._() is called at import time. gettextutils.enable_lazy() +from keystone import backends from keystone.common import dependency from keystone.common import environment from keystone.common import sql @@ -48,7 +49,6 @@ from keystone.common import utils from keystone import config from keystone.openstack.common.gettextutils import _ from keystone.openstack.common import importutils -from keystone import service CONF = config.CONF @@ -131,7 +131,7 @@ if __name__ == '__main__': monkeypatch_thread = False environment.use_eventlet(monkeypatch_thread) - service.load_backends() + backends.load_backends() servers = [] servers.append(create_server(paste_config, diff --git a/httpd/keystone.py b/httpd/keystone.py index 21761fd6bb..140a6978ee 100644 --- a/httpd/keystone.py +++ b/httpd/keystone.py @@ -24,12 +24,12 @@ from keystone.openstack.common import gettextutils # gettextutils._() is called at import time. gettextutils.enable_lazy() +from keystone import backends from keystone.common import dependency from keystone.common import environment from keystone.common import sql from keystone import config from keystone.openstack.common import log -from keystone import service CONF = config.CONF @@ -48,7 +48,7 @@ if CONF.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. # The following is a reference to Python Paste Deploy documentation diff --git a/keystone/backends.py b/keystone/backends.py new file mode 100644 index 0000000000..8380cdfcca --- /dev/null +++ b/keystone/backends.py @@ -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 diff --git a/keystone/service.py b/keystone/service.py index a996804b8f..f5514c0e89 100644 --- a/keystone/service.py +++ b/keystone/service.py @@ -20,10 +20,8 @@ import routes from keystone import assignment from keystone import auth from keystone import catalog -from keystone.common import cache from keystone.common import wsgi from keystone import config -from keystone.contrib import endpoint_filter from keystone import controllers from keystone import credential from keystone import identity @@ -38,32 +36,6 @@ CONF = config.CONF 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): """Logs exceptions and aborts.""" @functools.wraps(f) diff --git a/keystone/tests/core.py b/keystone/tests/core.py index bbc9bde692..c836307646 100644 --- a/keystone/tests/core.py +++ b/keystone/tests/core.py @@ -42,6 +42,7 @@ from keystone.common import environment environment.use_eventlet() from keystone import auth +from keystone import backends from keystone.common import dependency from keystone.common import kvs 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.gettextutils import _ from keystone.openstack.common import log -from keystone import service from keystone.tests import ksfixtures # NOTE(dstanek): Tests inheriting from TestCase depend on having the @@ -436,7 +436,7 @@ class TestCase(BaseTestCase): kvs_core.KEY_VALUE_STORE_REGISTRY.clear() self.clear_auth_plugin_registry() - drivers = service.load_backends() + drivers = backends.load_backends() drivers.update(dependency.resolve_future_dependencies())