]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Stop stacktracing on InvalidInput exceptions
authorJoe Gordon <joe.gordon0@gmail.com>
Thu, 2 Oct 2014 17:11:48 +0000 (10:11 -0700)
committerJoe Gordon <joe.gordon0@gmail.com>
Wed, 12 Nov 2014 21:48:30 +0000 (13:48 -0800)
InvalidInput is an expected error case, no need to stacktrace for it,
just log the error.

Change-Id: Ifcca98effd3ab153af30d21f2f23094210fe8ce3
Closes-Bug: #1376839

cinder/flow_utils.py

index d10ef4894dd69032c2e4702c369270ec1111fb8d..7f1dbac7f5f2cf8ac3934c22f37f93b74e935fac 100644 (file)
@@ -18,6 +18,7 @@ from taskflow import states
 from taskflow import task
 from taskflow.utils import misc
 
+from cinder import exception
 from cinder.i18n import _
 from cinder.openstack.common import log as logging
 
@@ -85,16 +86,27 @@ class DynamicLogListener(base_listener.ListenerBase):
     def _task_receiver(self, state, details):
         # Gets called on task state changes.
         if 'result' in details and state in base_listener.FINISH_STATES:
-            # If the task failed, it's useful to show the exception traceback
-            # and any other available exception information.
             result = details.get('result')
+            # If task failed log the exception
             if isinstance(result, misc.Failure):
-                self._logger.warn(_("Task '%(task_name)s' (%(task_uuid)s)"
-                                    " transitioned into state '%(state)s'") %
-                                  {'task_name': details['task_name'],
-                                   'task_uuid': details['task_uuid'],
-                                   'state': state},
-                                  exc_info=tuple(result.exc_info))
+                message_dict = {'task_name': details['task_name'],
+                                'task_uuid': details['task_uuid'],
+                                'state': state}
+                if result.check(exception.InvalidInput) is not None:
+                    # Exception is an excepted case, don't stacktrace
+                    message_dict['exception_str'] = result.exception_str
+                    message = (_("Task '%(task_name)s' (%(task_uuid)s)"
+                                 " transitioned into state '%(state)s'. "
+                                 "Exception: '%(exception_str)s'") %
+                               message_dict)
+                    self._logger.warn(message)
+                else:
+                    # Task failed with unexpected Exception, show stacktrace
+                    message = (_("Task '%(task_name)s' (%(task_uuid)s)"
+                               " transitioned into state '%(state)s'") %
+                               message_dict)
+                    self._logger.warn(message,
+                                      exc_info=tuple(result.exc_info))
             else:
                 # Otherwise, depending on the enabled logging level/state we
                 # will show or hide results that the task may have produced