From 242b06664f6170d000dccc2f3eb3b4e19a5c3f1a Mon Sep 17 00:00:00 2001 From: Zane Bitter Date: Fri, 4 Dec 2015 20:58:18 -0500 Subject: [PATCH] Improve log messages from scheduler Ensure that an unbound method is never logged as " from None". Also report the actual action name when doing stack_action(). Change-Id: Iff37860525d182e6eee01a7cc52c6599f05bff8c Related-Bug: #1339759 --- heat/engine/scheduler.py | 8 ++++---- heat/engine/stack.py | 21 +++++++++++---------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/heat/engine/scheduler.py b/heat/engine/scheduler.py index 68c201a21b..76eaf715aa 100644 --- a/heat/engine/scheduler.py +++ b/heat/engine/scheduler.py @@ -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) diff --git a/heat/engine/stack.py b/heat/engine/stack.py index 4adb2152b7..82f13e1d6f 100644 --- a/heat/engine/stack.py +++ b/heat/engine/stack.py @@ -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())