X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=qaapi%2Fqa%2Futils.py;h=871a54fb75e9d3d1e4cf94c0f551acc1b069ee1c;hb=ecfd3c10755fc660c44151b3773f971517d017f9;hp=40eb086af3369750417f8a0eb09f5959cbe99074;hpb=6ac92caedc7c2ada996bac6c96f958033632268b;p=tests.git diff --git a/qaapi/qa/utils.py b/qaapi/qa/utils.py index 40eb086..871a54f 100644 --- a/qaapi/qa/utils.py +++ b/qaapi/qa/utils.py @@ -2,45 +2,48 @@ import time import os from commands import getstatusoutput -from logger import logfile +from logger import Logfile -def header(message, log = True): +def header(message, log = True, logfile = Logfile('/var/log/qaapi')): now=time.strftime("%H:%M:%S", time.localtime()) + if isinstance(message, list): + message = "".join(message) output = "*"+now+'--'+message print output - if log: + if log: print >> logfile, output -def popen(command, fatal=True, verbose = False): +def popen(command, fatal=True, verbose = False, logfile = Logfile('/var/log/qaapi.log')): header(command) if verbose: header(command, False) (stdin, stdout, stderr) = os.popen3(command) output = stdout.readlines() + errors = stderr.readlines() print >> logfile, "+ "+command print >> logfile, "".join(output).strip() # filter output generated by set x remove_set_x = lambda line: not line.startswith("+") - errors = filter(remove_set_x, stderr.readlines()) + errors = filter(remove_set_x, errors) if fatal and errors: raise Exception, "".join(errors) return (output, errors) -def popen3(command, verbose = False): +def popen3(command, verbose = False, logfile = Logfile('/var/log/qaapi.log')): if verbose: header(command, False) (stdin, stdout, stderr) = os.popen3(command) print >> logfile, "+ "+command return (stdin, stdout, stderr) -def commands(command, fatal = True, verbose = False): +def commands(command, fatal = True, verbose = False, logfile = Logfile('/var/log/qaapi.log')): if verbose: header(command, False) (status, output) = getstatusoutput(command) print >> logfile, "+ "+command print >> logfile, output.strip() - if fatal and not status == 0: - raise Exception, "%(command)s Failed:\n%(output)s" % locals() + if fatal and status == 256 and output: + raise Exception, "%(command)s Failed:\n%(output)s" % locals() return (status, output)