From ca43430680bacbba7a17d5fde88aa253a7229c68 Mon Sep 17 00:00:00 2001 From: dineshbhor Date: Tue, 13 Dec 2016 19:30:25 +0530 Subject: [PATCH] Fix logging traceback in service logs The '_format_failure' method of DynamicLoggingListener class from taskflow is overridden to suppress traceback for special exceptions (InvalidInput, QuotaError). You can still see traceback in logs for these exceptions as _format_failure method was replaced with fail_formatter parameter in taskflow version 1.22.0 [1] but the code was not modified to accommodate these changes. This patch uses fail_formatter parameter to suppress traceback log messages. [1] https://github.com/openstack/taskflow/tree/1.22.0 Closes-Bug: #1649850 Change-Id: I9bb4a690759974206bbd95ae53339ab302b1db5a --- cinder/flow_utils.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/cinder/flow_utils.py b/cinder/flow_utils.py index 711f5d3017e..afa3beb91e7 100644 --- a/cinder/flow_utils.py +++ b/cinder/flow_utils.py @@ -14,6 +14,7 @@ import os from oslo_log import log as logging # For more information please visit: https://wiki.openstack.org/wiki/TaskFlow +from taskflow import formatters from taskflow.listeners import base from taskflow.listeners import logging as logging_listener from taskflow import task @@ -47,6 +48,23 @@ class CinderTask(task.Task): return _make_task_name(cls, addons) +class SpecialFormatter(formatters.FailureFormatter): + + #: Exception is an excepted case, don't include traceback in log if fails. + _NO_TRACE_EXCEPTIONS = (exception.InvalidInput, exception.QuotaError) + + def __init__(self, engine): + super(SpecialFormatter, self).__init__(engine) + + def format(self, fail, atom_matcher): + if fail.check(*self._NO_TRACE_EXCEPTIONS) is not None: + exc_info = None + exc_details = '%s%s' % (os.linesep, fail.pformat(traceback=False)) + return (exc_info, exc_details) + else: + return super(SpecialFormatter, self).format(fail, atom_matcher) + + class DynamicLogListener(logging_listener.DynamicLoggingListener): """This is used to attach to taskflow engines while they are running. @@ -56,9 +74,6 @@ class DynamicLogListener(logging_listener.DynamicLoggingListener): and more... """ - #: Exception is an excepted case, don't include traceback in log if fails. - _NO_TRACE_EXCEPTIONS = (exception.InvalidInput, exception.QuotaError) - def __init__(self, engine, task_listen_for=base.DEFAULT_LISTEN_FOR, flow_listen_for=base.DEFAULT_LISTEN_FOR, @@ -69,12 +84,4 @@ class DynamicLogListener(logging_listener.DynamicLoggingListener): task_listen_for=task_listen_for, flow_listen_for=flow_listen_for, retry_listen_for=retry_listen_for, - log=logger) - - def _format_failure(self, fail): - if fail.check(*self._NO_TRACE_EXCEPTIONS) is not None: - exc_info = None - exc_details = '%s%s' % (os.linesep, fail.pformat(traceback=False)) - return (exc_info, exc_details) - else: - return super(DynamicLogListener, self)._format_failure(fail) + log=logger, fail_formatter=SpecialFormatter(engine))