Extract the logging decorator used in kernel.py into a common library
and add it to Autotest.install to provide logging of autotest
installation failure (and success).
Signed-off-by: John Admanski <jadmanski@google.com>
git-svn-id: http://test.kernel.org/svn/autotest/trunk@937 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/client/common_lib/logging.py b/client/common_lib/logging.py
new file mode 100644
index 0000000..ded9abc
--- /dev/null
+++ b/client/common_lib/logging.py
@@ -0,0 +1,35 @@
+def record(fn):
+ """
+ Generic method decorator for logging calls under the
+ assumption that return=GOOD, exception=FAIL. The method
+ determines parameters as:
+ subdir = self.subdir if it exists, or None
+ operation = "class name"."method name"
+ status = None on GOOD, str(exception) on FAIL
+ The object using this method must have a job attribute
+ for the logging to actually occur, otherwise the logging
+ will silently fail.
+
+ Logging can explicitly be disabled for a call by passing
+ a logged=False parameter
+ """
+ def recorded_func(self, *args, **dargs):
+ logged = dargs.pop('logged', True)
+ job = getattr(self, 'job', None)
+ # if logging is disabled/unavailable, just
+ # call the method
+ if not logged or job is None:
+ return fn(self, *args, **dargs)
+ # logging is available, so wrap the method call
+ # in success/failure logging
+ subdir = getattr(self, 'subdir', None)
+ operation = '%s.%s' % (self.__class__.__name__,
+ fn.__name__)
+ try:
+ result = fn(self, *args, **dargs)
+ job.record('GOOD', subdir, operation)
+ except Exception, detail:
+ job.record('FAIL', subdir, operation, str(detail))
+ raise
+ return result
+ return recorded_func