Merge "Fix the issues found with local conf"

This commit is contained in:
Jenkins 2015-10-30 05:33:35 +00:00 committed by Gerrit Code Review
commit 89c5276b78
3 changed files with 19 additions and 35 deletions

View File

@ -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):

View File

@ -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):

View File

@ -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()