root / qa / hooks / loghook.py @ 973d7867
History | View | Annotate | Download (1.5 kB)
1 | 8bb7c6cb | Michael Hanselmann | # Copyright (C) 2007 Google Inc.
|
---|---|---|---|
2 | 8bb7c6cb | Michael Hanselmann | #
|
3 | 8bb7c6cb | Michael Hanselmann | # This program is free software; you can redistribute it and/or modify
|
4 | 8bb7c6cb | Michael Hanselmann | # it under the terms of the GNU General Public License as published by
|
5 | 8bb7c6cb | Michael Hanselmann | # the Free Software Foundation; either version 2 of the License, or
|
6 | 8bb7c6cb | Michael Hanselmann | # (at your option) any later version.
|
7 | 8bb7c6cb | Michael Hanselmann | #
|
8 | 8bb7c6cb | Michael Hanselmann | # This program is distributed in the hope that it will be useful, but
|
9 | 8bb7c6cb | Michael Hanselmann | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
10 | 8bb7c6cb | Michael Hanselmann | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11 | 8bb7c6cb | Michael Hanselmann | # General Public License for more details.
|
12 | 8bb7c6cb | Michael Hanselmann | #
|
13 | 8bb7c6cb | Michael Hanselmann | # You should have received a copy of the GNU General Public License
|
14 | 8bb7c6cb | Michael Hanselmann | # along with this program; if not, write to the Free Software
|
15 | 8bb7c6cb | Michael Hanselmann | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
16 | 8bb7c6cb | Michael Hanselmann | # 02110-1301, USA.
|
17 | 8bb7c6cb | Michael Hanselmann | |
18 | 8bb7c6cb | Michael Hanselmann | |
19 | 8bb7c6cb | Michael Hanselmann | """QA hook to log all function calls.
|
20 | 8bb7c6cb | Michael Hanselmann |
|
21 | 8bb7c6cb | Michael Hanselmann | """
|
22 | 8bb7c6cb | Michael Hanselmann | |
23 | 8bb7c6cb | Michael Hanselmann | from ganeti import utils |
24 | 8bb7c6cb | Michael Hanselmann | |
25 | 8bb7c6cb | Michael Hanselmann | import qa_utils |
26 | 8bb7c6cb | Michael Hanselmann | import qa_config |
27 | 8bb7c6cb | Michael Hanselmann | |
28 | 8bb7c6cb | Michael Hanselmann | from qa_utils import AssertEqual, StartSSH |
29 | 8bb7c6cb | Michael Hanselmann | |
30 | 8bb7c6cb | Michael Hanselmann | |
31 | 8bb7c6cb | Michael Hanselmann | class LogHook: |
32 | 8bb7c6cb | Michael Hanselmann | def __init__(self): |
33 | 8bb7c6cb | Michael Hanselmann | file_name = qa_config.get('options', {}).get('hook-logfile', None) |
34 | 8bb7c6cb | Michael Hanselmann | if file_name:
|
35 | 8bb7c6cb | Michael Hanselmann | self.log = open(file_name, "a+") |
36 | 8bb7c6cb | Michael Hanselmann | else:
|
37 | 8bb7c6cb | Michael Hanselmann | self.log = None |
38 | 8bb7c6cb | Michael Hanselmann | |
39 | 8bb7c6cb | Michael Hanselmann | def __del__(self): |
40 | 8bb7c6cb | Michael Hanselmann | if self.log: |
41 | 8bb7c6cb | Michael Hanselmann | self.log.close()
|
42 | 8bb7c6cb | Michael Hanselmann | |
43 | 8bb7c6cb | Michael Hanselmann | def run(self, ctx): |
44 | 8bb7c6cb | Michael Hanselmann | if not self.log: |
45 | 8bb7c6cb | Michael Hanselmann | return
|
46 | 8bb7c6cb | Michael Hanselmann | |
47 | 8bb7c6cb | Michael Hanselmann | msg = "%s-%s" % (ctx.phase, ctx.name)
|
48 | 8bb7c6cb | Michael Hanselmann | if ctx.phase == 'post': |
49 | 8bb7c6cb | Michael Hanselmann | msg += " success=%s" % ctx.success
|
50 | 8bb7c6cb | Michael Hanselmann | if ctx.args:
|
51 | 8bb7c6cb | Michael Hanselmann | msg += " %s" % repr(ctx.args) |
52 | 8bb7c6cb | Michael Hanselmann | if ctx.kwargs:
|
53 | 8bb7c6cb | Michael Hanselmann | msg += " %s" % repr(ctx.kwargs) |
54 | 8bb7c6cb | Michael Hanselmann | if ctx.phase == 'pre': |
55 | 8bb7c6cb | Michael Hanselmann | self.log.write("---\n") |
56 | 8bb7c6cb | Michael Hanselmann | self.log.write(msg)
|
57 | 8bb7c6cb | Michael Hanselmann | self.log.write("\n") |
58 | 8bb7c6cb | Michael Hanselmann | self.log.flush()
|
59 | 8bb7c6cb | Michael Hanselmann | |
60 | 8bb7c6cb | Michael Hanselmann | |
61 | 8bb7c6cb | Michael Hanselmann | hook = LogHook |