From 8bb7c6cbe57110ed997d824a2205304fd5cce3ef Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Thu, 22 Nov 2007 11:25:45 +0000 Subject: [PATCH] Add hook for logging. This may help to debug problems in QA tests. Reviewed-by: schreiberal --- qa/hooks/Makefile.am | 2 +- qa/hooks/loghook.py | 61 ++++++++++++++++++++++++++++++++++++++++++++ qa/qa-sample.yaml | 3 +++ 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 qa/hooks/loghook.py diff --git a/qa/hooks/Makefile.am b/qa/hooks/Makefile.am index 7f0c8a355..2d9c75a72 100644 --- a/qa/hooks/Makefile.am +++ b/qa/hooks/Makefile.am @@ -1,2 +1,2 @@ -EXTRA_DIST = datehook.py +EXTRA_DIST = datehook.py loghook.py CLEANFILES = *.py[co] diff --git a/qa/hooks/loghook.py b/qa/hooks/loghook.py new file mode 100644 index 000000000..4b86542ff --- /dev/null +++ b/qa/hooks/loghook.py @@ -0,0 +1,61 @@ +# Copyright (C) 2007 Google Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. + + +"""QA hook to log all function calls. + +""" + +from ganeti import utils + +import qa_utils +import qa_config + +from qa_utils import AssertEqual, StartSSH + + +class LogHook: + def __init__(self): + file_name = qa_config.get('options', {}).get('hook-logfile', None) + if file_name: + self.log = open(file_name, "a+") + else: + self.log = None + + def __del__(self): + if self.log: + self.log.close() + + def run(self, ctx): + if not self.log: + return + + msg = "%s-%s" % (ctx.phase, ctx.name) + if ctx.phase == 'post': + msg += " success=%s" % ctx.success + if ctx.args: + msg += " %s" % repr(ctx.args) + if ctx.kwargs: + msg += " %s" % repr(ctx.kwargs) + if ctx.phase == 'pre': + self.log.write("---\n") + self.log.write(msg) + self.log.write("\n") + self.log.flush() + + +hook = LogHook diff --git a/qa/qa-sample.yaml b/qa/qa-sample.yaml index e196d1e97..3901d962b 100644 --- a/qa/qa-sample.yaml +++ b/qa/qa-sample.yaml @@ -76,3 +76,6 @@ options: # Directory containing QA hooks #hooks-dir: hooks/ + + # Logfile for loghook.py + hook-logfile: /tmp/qa.log -- GitLab