Statistics
| Branch: | Tag: | Revision:

root / qa / hooks / loghook.py @ 9b3939ea

History | View | Annotate | Download (1.5 kB)

1
# Copyright (C) 2007 Google Inc.
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful, but
9
# WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11
# General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16
# 02110-1301, USA.
17

    
18

    
19
"""QA hook to log all function calls.
20

21
"""
22

    
23
from ganeti import utils
24

    
25
import qa_utils
26
import qa_config
27

    
28
from qa_utils import AssertEqual, StartSSH
29

    
30

    
31
class LogHook:
32
  def __init__(self):
33
    file_name = qa_config.get('options', {}).get('hook-logfile', None)
34
    if file_name:
35
      self.log = open(file_name, "a+")
36
    else:
37
      self.log = None
38

    
39
  def __del__(self):
40
    if self.log:
41
      self.log.close()
42

    
43
  def run(self, ctx):
44
    if not self.log:
45
      return
46

    
47
    msg = "%s-%s" % (ctx.phase, ctx.name)
48
    if ctx.phase == 'post':
49
      msg += " success=%s" % ctx.success
50
    if ctx.args:
51
      msg += " %s" % repr(ctx.args)
52
    if ctx.kwargs:
53
      msg += " %s" % repr(ctx.kwargs)
54
    if ctx.phase == 'pre':
55
      self.log.write("---\n")
56
    self.log.write(msg)
57
    self.log.write("\n")
58
    self.log.flush()
59

    
60

    
61
hook = LogHook