From: Zane Bitter Date: Mon, 17 Jun 2013 15:42:04 +0000 (+0200) Subject: scheduler: Improve task descriptions in debug logs X-Git-Tag: 2014.1~473^2 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=26812e34bd9460a63aebdcbdc1ca27b243f91660;p=openstack-build%2Fheat-build.git scheduler: Improve task descriptions in debug logs Tasks that were simply defined as ordinary functions (not methods) were identified by their repr() in the logs, which is only really desirable as a last resort and for objects (where the __call__() method is the task). Use the function name instead. Change-Id: Ie34a3602deb968979118b0961bcddf226cf5983f --- diff --git a/heat/engine/scheduler.py b/heat/engine/scheduler.py index b4f75069..6857c9bb 100644 --- a/heat/engine/scheduler.py +++ b/heat/engine/scheduler.py @@ -31,11 +31,14 @@ def task_description(task): Return a human-readable string description of a task suitable for logging the status of the task. """ + name = getattr(task, '__name__', None) if isinstance(task, types.MethodType): - name = getattr(task, '__name__') - obj = getattr(task, '__self__') + obj = getattr(task, '__self__', None) if name is not None and obj is not None: return '%s from %s' % (name, obj) + elif isinstance(task, types.FunctionType): + if name is not None: + return str(name) return repr(task) diff --git a/heat/tests/test_scheduler.py b/heat/tests/test_scheduler.py index 95b0caeb..b7c54f6e 100644 --- a/heat/tests/test_scheduler.py +++ b/heat/tests/test_scheduler.py @@ -595,6 +595,45 @@ class TaskTest(mox.MoxTestBase): self.mox.VerifyAll() +class DescriptionTest(mox.MoxTestBase): + def test_func(self): + def f(): + pass + + self.assertEqual(scheduler.task_description(f), 'f') + + def test_lambda(self): + l = lambda: None + + self.assertEqual(scheduler.task_description(l), '') + + def test_method(self): + class C(object): + def __str__(self): + return 'C "o"' + + def __repr__(self): + return 'o' + + def m(self): + pass + + self.assertEqual(scheduler.task_description(C().m), 'm from C "o"') + + def test_object(self): + class C(object): + def __str__(self): + return 'C "o"' + + def __repr__(self): + return 'o' + + def __call__(self): + pass + + self.assertEqual(scheduler.task_description(C()), 'o') + + class WrapperTaskTest(mox.MoxTestBase): def test_wrap(self):