Improve log messages from scheduler
Ensure that an unbound method is never logged as "<method name> from None". Also report the actual action name when doing stack_action(). Change-Id: Iff37860525d182e6eee01a7cc52c6599f05bff8c Related-Bug: #1339759
This commit is contained in:
parent
db7ab8de2c
commit
242b06664f
|
@ -37,11 +37,11 @@ def task_description(task):
|
|||
The description is used to identify the task when logging its status.
|
||||
"""
|
||||
name = task.__name__ if hasattr(task, '__name__') else None
|
||||
if isinstance(task, types.MethodType):
|
||||
if name is not None and hasattr(task, '__self__'):
|
||||
if name is not None and isinstance(task, (types.MethodType,
|
||||
types.FunctionType)):
|
||||
if getattr(task, '__self__', None) is not None:
|
||||
return '%s from %s' % (name, task.__self__)
|
||||
elif isinstance(task, types.FunctionType):
|
||||
if name is not None:
|
||||
else:
|
||||
return six.text_type(name)
|
||||
return repr(task)
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
import collections
|
||||
import copy
|
||||
import datetime
|
||||
import functools
|
||||
import itertools
|
||||
import re
|
||||
|
||||
|
@ -909,15 +910,18 @@ class Stack(collections.Mapping):
|
|||
stack_status = self.COMPLETE
|
||||
reason = 'Stack %s completed successfully' % action
|
||||
|
||||
action_method = action.lower()
|
||||
# If a local _$action_kwargs function exists, call it to get the
|
||||
# action specific argument list, otherwise an empty arg list
|
||||
handle_kwargs = getattr(self,
|
||||
'_%s_kwargs' % action_method,
|
||||
lambda x: {})
|
||||
|
||||
@functools.wraps(getattr(resource.Resource, action_method))
|
||||
def resource_action(r):
|
||||
# Find e.g resource.create and call it
|
||||
action_l = action.lower()
|
||||
handle = getattr(r, '%s' % action_l)
|
||||
handle = getattr(r, action_method)
|
||||
|
||||
# If a local _$action_kwargs function exists, call it to get the
|
||||
# action specific argument list, otherwise an empty arg list
|
||||
handle_kwargs = getattr(self,
|
||||
'_%s_kwargs' % action_l, lambda x: {})
|
||||
return handle(**handle_kwargs(r))
|
||||
|
||||
action_task = scheduler.DependencyTaskGroup(
|
||||
|
@ -1558,11 +1562,8 @@ class Stack(collections.Mapping):
|
|||
'Failed stack pre-ops: %s' % six.text_type(e))
|
||||
return
|
||||
|
||||
def destroy_resource(stack_resource):
|
||||
return stack_resource.destroy()
|
||||
|
||||
action_task = scheduler.DependencyTaskGroup(self.dependencies,
|
||||
destroy_resource,
|
||||
resource.Resource.destroy,
|
||||
reverse=True)
|
||||
try:
|
||||
scheduler.TaskRunner(action_task)(timeout=self.timeout_secs())
|
||||
|
|
Loading…
Reference in New Issue