Merge "Don't lard up InternalClient with extra middleware"
This commit is contained in:
@@ -134,8 +134,10 @@ class InternalClient(object):
|
|||||||
gives up.
|
gives up.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, conf_path, user_agent, request_tries):
|
def __init__(self, conf_path, user_agent, request_tries,
|
||||||
self.app = loadapp('config:' + conf_path)
|
allow_modify_pipeline=False):
|
||||||
|
self.app = loadapp('config:' + conf_path,
|
||||||
|
allow_modify_pipeline=allow_modify_pipeline)
|
||||||
self.user_agent = user_agent
|
self.user_agent = user_agent
|
||||||
self.request_tries = request_tries
|
self.request_tries = request_tries
|
||||||
|
|
||||||
|
|||||||
@@ -305,7 +305,7 @@ def loadcontext(object_type, uri, name=None, relative_to=None,
|
|||||||
global_conf=global_conf)
|
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
|
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.
|
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
|
# give app the opportunity to modify the pipeline context
|
||||||
app = ctx.app_context.create()
|
app = ctx.app_context.create()
|
||||||
func = getattr(app, 'modify_wsgi_pipeline', None)
|
func = getattr(app, 'modify_wsgi_pipeline', None)
|
||||||
if func:
|
if func and allow_modify_pipeline:
|
||||||
func(PipelineWrapper(ctx))
|
func(PipelineWrapper(ctx))
|
||||||
return ctx.create()
|
return ctx.create()
|
||||||
|
|
||||||
|
|||||||
@@ -185,9 +185,10 @@ class TestInternalClient(unittest.TestCase):
|
|||||||
self.conf_path = conf_path
|
self.conf_path = conf_path
|
||||||
self.load_called = 0
|
self.load_called = 0
|
||||||
|
|
||||||
def load(self, uri):
|
def load(self, uri, allow_modify_pipeline=True):
|
||||||
self.load_called += 1
|
self.load_called += 1
|
||||||
self.test.assertEquals('config:' + conf_path, uri)
|
self.test.assertEquals('config:' + conf_path, uri)
|
||||||
|
self.test.assertFalse(allow_modify_pipeline)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
conf_path = 'some_path'
|
conf_path = 'some_path'
|
||||||
|
|||||||
@@ -819,6 +819,22 @@ class TestPipelineModification(unittest.TestCase):
|
|||||||
exp = swift.proxy.server.Application
|
exp = swift.proxy.server.Application
|
||||||
self.assertTrue(isinstance(app.app.app, exp), app.app.app)
|
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):
|
def test_proxy_unmodified_wsgi_pipeline(self):
|
||||||
# Make sure things are sane even when we modify nothing
|
# Make sure things are sane even when we modify nothing
|
||||||
config = """
|
config = """
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ class TestObjectExpirer(TestCase):
|
|||||||
self.old_loadapp = internal_client.loadapp
|
self.old_loadapp = internal_client.loadapp
|
||||||
self.old_sleep = internal_client.sleep
|
self.old_sleep = internal_client.sleep
|
||||||
|
|
||||||
internal_client.loadapp = lambda x: None
|
internal_client.loadapp = lambda *a, **kw: None
|
||||||
internal_client.sleep = not_sleep
|
internal_client.sleep = not_sleep
|
||||||
|
|
||||||
def teardown(self):
|
def teardown(self):
|
||||||
@@ -618,7 +618,7 @@ class TestObjectExpirer(TestCase):
|
|||||||
start_response('204 No Content', [('Content-Length', '0')])
|
start_response('204 No Content', [('Content-Length', '0')])
|
||||||
return []
|
return []
|
||||||
|
|
||||||
internal_client.loadapp = lambda x: fake_app
|
internal_client.loadapp = lambda *a, **kw: fake_app
|
||||||
|
|
||||||
x = expirer.ObjectExpirer({})
|
x = expirer.ObjectExpirer({})
|
||||||
ts = '1234'
|
ts = '1234'
|
||||||
@@ -635,7 +635,7 @@ class TestObjectExpirer(TestCase):
|
|||||||
start_response('204 No Content', [('Content-Length', '0')])
|
start_response('204 No Content', [('Content-Length', '0')])
|
||||||
return []
|
return []
|
||||||
|
|
||||||
internal_client.loadapp = lambda x: fake_app
|
internal_client.loadapp = lambda *a, **kw: fake_app
|
||||||
|
|
||||||
x = expirer.ObjectExpirer({})
|
x = expirer.ObjectExpirer({})
|
||||||
ts = '1234'
|
ts = '1234'
|
||||||
@@ -649,7 +649,7 @@ class TestObjectExpirer(TestCase):
|
|||||||
start_response('404 Not Found', [('Content-Length', '0')])
|
start_response('404 Not Found', [('Content-Length', '0')])
|
||||||
return []
|
return []
|
||||||
|
|
||||||
internal_client.loadapp = lambda x: fake_app
|
internal_client.loadapp = lambda *a, **kw: fake_app
|
||||||
|
|
||||||
x = expirer.ObjectExpirer({})
|
x = expirer.ObjectExpirer({})
|
||||||
x.delete_actual_object('/path/to/object', '1234')
|
x.delete_actual_object('/path/to/object', '1234')
|
||||||
@@ -661,7 +661,7 @@ class TestObjectExpirer(TestCase):
|
|||||||
[('Content-Length', '0')])
|
[('Content-Length', '0')])
|
||||||
return []
|
return []
|
||||||
|
|
||||||
internal_client.loadapp = lambda x: fake_app
|
internal_client.loadapp = lambda *a, **kw: fake_app
|
||||||
|
|
||||||
x = expirer.ObjectExpirer({})
|
x = expirer.ObjectExpirer({})
|
||||||
x.delete_actual_object('/path/to/object', '1234')
|
x.delete_actual_object('/path/to/object', '1234')
|
||||||
@@ -674,7 +674,7 @@ class TestObjectExpirer(TestCase):
|
|||||||
[('Content-Length', '0')])
|
[('Content-Length', '0')])
|
||||||
return []
|
return []
|
||||||
|
|
||||||
internal_client.loadapp = lambda x: fake_app
|
internal_client.loadapp = lambda *a, **kw: fake_app
|
||||||
|
|
||||||
x = expirer.ObjectExpirer({})
|
x = expirer.ObjectExpirer({})
|
||||||
exc = None
|
exc = None
|
||||||
|
|||||||
Reference in New Issue
Block a user