Print pipeline names in the reported pipeline
When current code modifies the pipeline, it prints the entry point names instead of the names used to construct the pipeline. This is inconvenient because a sysadmin cannot copy and paste from the log. We already save the pipeline name into contexts in most cases, so the fix simply reuses that to provide friendly names. Fixes bug: 1311802 Change-Id: Ic76baf1360cd521f140fa1980029ccbce58f1717
This commit is contained in:
@@ -16,7 +16,6 @@
|
|||||||
"""WSGI tools for use with swift."""
|
"""WSGI tools for use with swift."""
|
||||||
|
|
||||||
import errno
|
import errno
|
||||||
import inspect
|
|
||||||
import os
|
import os
|
||||||
import signal
|
import signal
|
||||||
import time
|
import time
|
||||||
@@ -234,26 +233,11 @@ class PipelineWrapper(object):
|
|||||||
return first_ctx.entry_point_name == entry_point_name
|
return first_ctx.entry_point_name == entry_point_name
|
||||||
|
|
||||||
def _format_for_display(self, ctx):
|
def _format_for_display(self, ctx):
|
||||||
if ctx.entry_point_name:
|
# Contexts specified by pipeline= have .name set in NamedConfigLoader.
|
||||||
return ctx.entry_point_name
|
if hasattr(ctx, 'name'):
|
||||||
elif inspect.isfunction(ctx.object):
|
return ctx.name
|
||||||
# ctx.object is a reference to the actual filter_factory
|
# This should not happen: a foreign context. Let's not crash.
|
||||||
# function, so we pretty-print that. It's not the nice short
|
return "<unknown>"
|
||||||
# entry point, but it beats "<unknown>".
|
|
||||||
#
|
|
||||||
# These happen when, instead of something like
|
|
||||||
#
|
|
||||||
# use = egg:swift#healthcheck
|
|
||||||
#
|
|
||||||
# you have something like this:
|
|
||||||
#
|
|
||||||
# paste.filter_factory = \
|
|
||||||
# swift.common.middleware.healthcheck:filter_factory
|
|
||||||
return "%s:%s" % (inspect.getmodule(ctx.object).__name__,
|
|
||||||
ctx.object.__name__)
|
|
||||||
else:
|
|
||||||
# No idea what this is
|
|
||||||
return "<unknown context>"
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
parts = [self._format_for_display(ctx)
|
parts = [self._format_for_display(ctx)
|
||||||
@@ -274,6 +258,7 @@ class PipelineWrapper(object):
|
|||||||
ctx = loadwsgi.loadcontext(loadwsgi.FILTER, spec,
|
ctx = loadwsgi.loadcontext(loadwsgi.FILTER, spec,
|
||||||
global_conf=self.context.global_conf)
|
global_conf=self.context.global_conf)
|
||||||
ctx.protocol = 'paste.filter_factory'
|
ctx.protocol = 'paste.filter_factory'
|
||||||
|
ctx.name = entry_point_name
|
||||||
return ctx
|
return ctx
|
||||||
|
|
||||||
def index(self, entry_point_name):
|
def index(self, entry_point_name):
|
||||||
|
@@ -755,16 +755,14 @@ class TestPipelineWrapper(unittest.TestCase):
|
|||||||
def test_str(self):
|
def test_str(self):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
str(self.pipe),
|
str(self.pipe),
|
||||||
"healthcheck catch_errors " +
|
"healthcheck catch_errors tempurl proxy-server")
|
||||||
"swift.common.middleware.tempurl:filter_factory proxy")
|
|
||||||
|
|
||||||
def test_str_unknown_filter(self):
|
def test_str_unknown_filter(self):
|
||||||
self.pipe.context.filter_contexts[0].entry_point_name = None
|
del self.pipe.context.filter_contexts[0].__dict__['name']
|
||||||
self.pipe.context.filter_contexts[0].object = 'mysterious'
|
self.pipe.context.filter_contexts[0].object = 'mysterious'
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
str(self.pipe),
|
str(self.pipe),
|
||||||
"<unknown context> catch_errors " +
|
"<unknown> catch_errors tempurl proxy-server")
|
||||||
"swift.common.middleware.tempurl:filter_factory proxy")
|
|
||||||
|
|
||||||
|
|
||||||
class TestPipelineModification(unittest.TestCase):
|
class TestPipelineModification(unittest.TestCase):
|
||||||
|
Reference in New Issue
Block a user