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."""
|
||||
|
||||
import errno
|
||||
import inspect
|
||||
import os
|
||||
import signal
|
||||
import time
|
||||
@@ -234,26 +233,11 @@ class PipelineWrapper(object):
|
||||
return first_ctx.entry_point_name == entry_point_name
|
||||
|
||||
def _format_for_display(self, ctx):
|
||||
if ctx.entry_point_name:
|
||||
return ctx.entry_point_name
|
||||
elif inspect.isfunction(ctx.object):
|
||||
# ctx.object is a reference to the actual filter_factory
|
||||
# function, so we pretty-print that. It's not the nice short
|
||||
# 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>"
|
||||
# Contexts specified by pipeline= have .name set in NamedConfigLoader.
|
||||
if hasattr(ctx, 'name'):
|
||||
return ctx.name
|
||||
# This should not happen: a foreign context. Let's not crash.
|
||||
return "<unknown>"
|
||||
|
||||
def __str__(self):
|
||||
parts = [self._format_for_display(ctx)
|
||||
@@ -274,6 +258,7 @@ class PipelineWrapper(object):
|
||||
ctx = loadwsgi.loadcontext(loadwsgi.FILTER, spec,
|
||||
global_conf=self.context.global_conf)
|
||||
ctx.protocol = 'paste.filter_factory'
|
||||
ctx.name = entry_point_name
|
||||
return ctx
|
||||
|
||||
def index(self, entry_point_name):
|
||||
|
@@ -755,16 +755,14 @@ class TestPipelineWrapper(unittest.TestCase):
|
||||
def test_str(self):
|
||||
self.assertEqual(
|
||||
str(self.pipe),
|
||||
"healthcheck catch_errors " +
|
||||
"swift.common.middleware.tempurl:filter_factory proxy")
|
||||
"healthcheck catch_errors tempurl proxy-server")
|
||||
|
||||
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.assertEqual(
|
||||
str(self.pipe),
|
||||
"<unknown context> catch_errors " +
|
||||
"swift.common.middleware.tempurl:filter_factory proxy")
|
||||
"<unknown> catch_errors tempurl proxy-server")
|
||||
|
||||
|
||||
class TestPipelineModification(unittest.TestCase):
|
||||
|
Reference in New Issue
Block a user