From 33994ed2c4202dc879ee69fe47e2e1321c74ba0c Mon Sep 17 00:00:00 2001 From: Dave Chen Date: Thu, 13 Nov 2014 23:04:51 +0800 Subject: [PATCH] Fix the issues found with local conf Since keystone's paste.deploy configuration file has been separated from the main keystone configuration file (keystone.conf), all local configuration or driver-specific configuration parameters must be in the main keystone configuration file instead of PasteDeploy conf file. This patch changes to log a warning if there's any local_conf defined in PasteDeploy INI and remove `local_config` argument from wsgi middleware since it doesn't work. DocImpact Closes-Bug: #1369388 Change-Id: Iaf6ad869b61e4330a4ea48e606fd9eda69b9cd12 --- keystone/common/wsgi.py | 28 +++------------------------- keystone/tests/unit/test_wsgi.py | 10 ---------- keystone/version/service.py | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 35 deletions(-) diff --git a/keystone/common/wsgi.py b/keystone/common/wsgi.py index 48509637e2..8429e8e892 100644 --- a/keystone/common/wsgi.py +++ b/keystone/common/wsgi.py @@ -398,32 +398,10 @@ class Middleware(Application): """ @classmethod - def factory(cls, global_config, **local_config): - """Used for paste app factories in paste.deploy config files. - - Any local configuration (that is, values under the [filter:APPNAME] - section of the paste config) will be passed into the `__init__` method - as kwargs. - - A hypothetical configuration would look like: - - [filter:analytics] - redis_host = 127.0.0.1 - paste.filter_factory = keystone.analytics:Analytics.factory - - which would result in a call to the `Analytics` class as - - import keystone.analytics - keystone.analytics.Analytics(app, redis_host='127.0.0.1') - - You could of course re-implement the `factory` method in subclasses, - but using the kwarg passing it shouldn't be necessary. - - """ + def factory(cls, global_config): + """Used for paste app factories in paste.deploy config files.""" def _factory(app): - conf = global_config.copy() - conf.update(local_config) - return cls(app, **local_config) + return cls(app) return _factory def __init__(self, application): diff --git a/keystone/tests/unit/test_wsgi.py b/keystone/tests/unit/test_wsgi.py index be92ddfbaf..e295210bf9 100644 --- a/keystone/tests/unit/test_wsgi.py +++ b/keystone/tests/unit/test_wsgi.py @@ -302,16 +302,6 @@ class MiddlewareTest(BaseWSGITest): self.config_fixture.config(debug=True) self.assertIn(exception_str, do_request().body) - def test_middleware_local_config(self): - class FakeMiddleware(wsgi.Middleware): - def __init__(self, *args, **kwargs): - self.kwargs = kwargs - - factory = FakeMiddleware.factory({}, testkey="test") - app = factory(self.app) - self.assertIn("testkey", app.kwargs) - self.assertEqual("test", app.kwargs["testkey"]) - class LocalizedResponseTest(unit.TestCase): def test_request_match_default(self): diff --git a/keystone/version/service.py b/keystone/version/service.py index 40256522d9..2ae900a4b6 100644 --- a/keystone/version/service.py +++ b/keystone/version/service.py @@ -26,6 +26,7 @@ from keystone import catalog from keystone.common import wsgi from keystone import credential from keystone import endpoint_policy +from keystone.i18n import _LW from keystone import identity from keystone import policy from keystone import resource @@ -63,7 +64,18 @@ def fail_gracefully(f): return wrapper +def warn_local_conf(f): + @functools.wraps(f) + def wrapper(*args, **local_conf): + if local_conf: + LOG.warning(_LW('\'local conf\' from PasteDeploy INI is being ' + 'ignored.')) + return f(*args, **local_conf) + return wrapper + + @fail_gracefully +@warn_local_conf def public_app_factory(global_conf, **local_conf): controllers.register_version('v2.0') return wsgi.ComposingRouter(routes.Mapper(), @@ -74,6 +86,7 @@ def public_app_factory(global_conf, **local_conf): @fail_gracefully +@warn_local_conf def admin_app_factory(global_conf, **local_conf): controllers.register_version('v2.0') return wsgi.ComposingRouter(routes.Mapper(), @@ -86,18 +99,21 @@ def admin_app_factory(global_conf, **local_conf): @fail_gracefully +@warn_local_conf def public_version_app_factory(global_conf, **local_conf): return wsgi.ComposingRouter(routes.Mapper(), [routers.Versions('public')]) @fail_gracefully +@warn_local_conf def admin_version_app_factory(global_conf, **local_conf): return wsgi.ComposingRouter(routes.Mapper(), [routers.Versions('admin')]) @fail_gracefully +@warn_local_conf def v3_app_factory(global_conf, **local_conf): controllers.register_version('v3') mapper = routes.Mapper()