Commit fa663bc1 authored by Ilias Tsitsimpis's avatar Ilias Tsitsimpis
Browse files

burnin: Add --quiet and --final-report-only flags

`final-report-only' flag is useful when burnin is used in
script files and it's output is to be sent using email.
parent 2288b8e8
......@@ -161,6 +161,16 @@ def parse_arguments(args):
"--no-colors", action="store_false",
default=True, dest="use_colors",
help="Disable colorful output")
parser.add_option(
"--quiet", action="store_true",
default=False, dest="quiet",
help="Turn off log output")
parser.add_option(
"--final-report-only", action="store_true",
default=False, dest="final_report",
help="Turn off log output and only print the contents of the log "
"file at the end of the test. Useful when burnin is used in "
"script files and it's output is to be sent using email")
(opts, args) = parser.parse_args(args)
......@@ -171,6 +181,17 @@ def parse_arguments(args):
show_version()
sys.exit(0)
# `delete_stale' implies `show_stale'
if opts.delete_stale:
opts.show_stale = True
# `quiet' implies not `final_report'
if opts.quiet:
opts.final_report = False
# `final_report' implies `quiet'
if opts.final_report:
opts.quiet = True
# `token' is mandatory
mandatory_argument(opts.token, "--token")
# `auth_url' is mandatory
......@@ -213,7 +234,8 @@ def main():
# Run burnin
# The return value denotes the success status
return common.run(testsuites)
return common.run(testsuites, failfast=opts.failfast,
final_report=opts.final_report)
if __name__ == "__main__":
......
......@@ -173,7 +173,8 @@ def initialize(opts, testsuites):
# Initialize logger
global logger # Using global statement. pylint: disable-msg=C0103,W0603
logger = Log(opts.log_folder, verbose=opts.verbose,
use_colors=opts.use_colors, in_parallel=False)
use_colors=opts.use_colors, in_parallel=False,
quiet=opts.quiet)
# Initialize clients
Clients.auth_url = opts.auth_url
......@@ -194,7 +195,7 @@ def initialize(opts, testsuites):
# --------------------------------------------------------------------
# Run Burnin
def run(testsuites):
def run(testsuites, failfast=False, final_report=False):
"""Run burnin testsuites"""
global logger # Using global. pylint: disable-msg=C0103,W0603,W0602
......@@ -204,7 +205,12 @@ def run(testsuites):
results = tsuite.run(BurninTestResult())
success = success and \
was_successful(tcase.__name__, results.wasSuccessful())
if failfast and not success:
break
# Are we going to print final report?
if final_report:
logger.print_logfile_to_stdout()
# Clean up our logger
del(logger)
......
......@@ -207,8 +207,9 @@ class Log(object):
"""
# ----------------------------------
# Too many arguments. pylint: disable-msg=R0913
def __init__(self, output_dir, verbose=1, use_colors=True,
in_parallel=False):
in_parallel=False, quiet=False):
"""Initialize our loggers
The file to be used by our file logger will be created inside
......@@ -225,11 +226,14 @@ class Log(object):
@param use_colors: use colors for out stdout/stderr logger
@type in_parallel: boolean
@param in_parallel: this signifies that burnin is running in parallel
@type quiet: boolean
@type quiet: do not print logs to stdout/stderr
"""
self.verbose = verbose
self.use_colors = use_colors
self.in_parallel = in_parallel
self.quiet = quiet
assert output_dir
......@@ -252,7 +256,7 @@ class Log(object):
timestamp = datetime.datetime.strftime(
datetime.datetime.now(), "%a %b %d %Y %H:%M")
sys.stdout.write("Starting burnin (%s)\n" % timestamp)
self._write_to_stdout(None, "Starting burnin (%s)\n" % timestamp)
# Create the logging file
self._create_logging_file(timestamp)
......@@ -278,6 +282,11 @@ class Log(object):
except OSError:
self.debug(None, "Couldn't delete lock file")
def print_logfile_to_stdout(self):
"""Print the contents of our log file to stdout"""
with open(self.file_location, 'r') as fin:
sys.stdout.write(fin.read())
# ----------------------------------
# Logging methods
def debug(self, section, msg, *args):
......@@ -346,17 +355,19 @@ class Log(object):
def _write_to_stdout(self, section, msg):
"""Write to stdout"""
if section is not None and self.in_parallel:
sys.stdout.write(section + ": " + msg)
else:
sys.stdout.write(msg)
if not self.quiet:
if section is not None and self.in_parallel:
sys.stdout.write(section + ": " + msg)
else:
sys.stdout.write(msg)
def _write_to_stderr(self, section, msg):
"""Write to stderr"""
if section is not None and self.in_parallel:
sys.stderr.write(section + ": " + msg)
else:
sys.stderr.write(msg)
if not self.quiet:
if section is not None and self.in_parallel:
sys.stderr.write(section + ": " + msg)
else:
sys.stderr.write(msg)
def _write_to_file(self, section, msg):
"""Write to file"""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment