Merge "Don't lard up InternalClient with extra middleware"

This commit is contained in:
Jenkins 2014-03-05 01:09:42 +00:00 committed by Gerrit Code Review
commit d7744acde7
5 changed files with 30 additions and 11 deletions

View File

@ -134,8 +134,10 @@ class InternalClient(object):
gives up.
"""
def __init__(self, conf_path, user_agent, request_tries):
self.app = loadapp('config:' + conf_path)
def __init__(self, conf_path, user_agent, request_tries,
allow_modify_pipeline=False):
self.app = loadapp('config:' + conf_path,
allow_modify_pipeline=allow_modify_pipeline)
self.user_agent = user_agent
self.request_tries = request_tries

View File

@ -305,7 +305,7 @@ def loadcontext(object_type, uri, name=None, relative_to=None,
global_conf=global_conf)
def loadapp(conf_file, global_conf):
def loadapp(conf_file, global_conf, allow_modify_pipeline=True):
"""
Loads a context from a config file, and if the context is a pipeline
then presents the app with the opportunity to modify the pipeline.
@ -315,7 +315,7 @@ def loadapp(conf_file, global_conf):
# give app the opportunity to modify the pipeline context
app = ctx.app_context.create()
func = getattr(app, 'modify_wsgi_pipeline', None)
if func:
if func and allow_modify_pipeline:
func(PipelineWrapper(ctx))
return ctx.create()

View File

@ -185,9 +185,10 @@ class TestInternalClient(unittest.TestCase):
self.conf_path = conf_path
self.load_called = 0
def load(self, uri):
def load(self, uri, allow_modify_pipeline=True):
self.load_called += 1
self.test.assertEquals('config:' + conf_path, uri)
self.test.assertFalse(allow_modify_pipeline)
return self
conf_path = 'some_path'

View File

@ -819,6 +819,22 @@ class TestPipelineModification(unittest.TestCase):
exp = swift.proxy.server.Application
self.assertTrue(isinstance(app.app.app, exp), app.app.app)
# make sure you can turn off the pipeline modification if you want
def blow_up(*_, **__):
raise self.fail("needs more struts")
with mock.patch(
'swift.proxy.server.Application.modify_wsgi_pipeline',
blow_up):
app = wsgi.loadapp(conf_file, global_conf={},
allow_modify_pipeline=False)
# the pipeline was untouched
exp = swift.common.middleware.healthcheck.HealthCheckMiddleware
self.assertTrue(isinstance(app, exp), app)
exp = swift.proxy.server.Application
self.assertTrue(isinstance(app.app, exp), app.app)
def test_proxy_unmodified_wsgi_pipeline(self):
# Make sure things are sane even when we modify nothing
config = """

View File

@ -46,7 +46,7 @@ class TestObjectExpirer(TestCase):
self.old_loadapp = internal_client.loadapp
self.old_sleep = internal_client.sleep
internal_client.loadapp = lambda x: None
internal_client.loadapp = lambda *a, **kw: None
internal_client.sleep = not_sleep
def teardown(self):
@ -618,7 +618,7 @@ class TestObjectExpirer(TestCase):
start_response('204 No Content', [('Content-Length', '0')])
return []
internal_client.loadapp = lambda x: fake_app
internal_client.loadapp = lambda *a, **kw: fake_app
x = expirer.ObjectExpirer({})
ts = '1234'
@ -635,7 +635,7 @@ class TestObjectExpirer(TestCase):
start_response('204 No Content', [('Content-Length', '0')])
return []
internal_client.loadapp = lambda x: fake_app
internal_client.loadapp = lambda *a, **kw: fake_app
x = expirer.ObjectExpirer({})
ts = '1234'
@ -649,7 +649,7 @@ class TestObjectExpirer(TestCase):
start_response('404 Not Found', [('Content-Length', '0')])
return []
internal_client.loadapp = lambda x: fake_app
internal_client.loadapp = lambda *a, **kw: fake_app
x = expirer.ObjectExpirer({})
x.delete_actual_object('/path/to/object', '1234')
@ -661,7 +661,7 @@ class TestObjectExpirer(TestCase):
[('Content-Length', '0')])
return []
internal_client.loadapp = lambda x: fake_app
internal_client.loadapp = lambda *a, **kw: fake_app
x = expirer.ObjectExpirer({})
x.delete_actual_object('/path/to/object', '1234')
@ -674,7 +674,7 @@ class TestObjectExpirer(TestCase):
[('Content-Length', '0')])
return []
internal_client.loadapp = lambda x: fake_app
internal_client.loadapp = lambda *a, **kw: fake_app
x = expirer.ObjectExpirer({})
exc = None