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