Commit 17168f7b authored by Ilias Tsitsimpis's avatar Ilias Tsitsimpis
Browse files

burnin: Change --quiet logging behavior

When --quiet flag is used, burnin will not produce a logging
file at all (neither will log to stdout). This flag is used
when we simple want to check if there are stale servers from
previous runs (we can do this based on burnin's exit status)
but we don't want to produce any log files.
parent 3a651f51
......@@ -182,7 +182,7 @@ def parse_arguments(args):
parser.add_option(
"--quiet", action="store_true",
default=False, dest="quiet",
help="Turn off log output")
help="Turn off logging (both console and file logging)")
parser.add_option(
"--final-report-only", action="store_true",
default=False, dest="final_report",
......@@ -203,12 +203,15 @@ def parse_arguments(args):
if opts.delete_stale:
opts.show_stale = True
# `quiet' implies not `final_report'
if opts.quiet:
opts.final_report = False
# `final_report' implies `quiet'
# log_level:
# 0 -> log to console and file
# 1 -> log to file and output the results in console
# 2 -> don't log
opts.log_level = 0
if opts.final_report:
opts.quiet = True
opts.log_level = 1
if opts.quiet:
opts.log_level = 2
# Check `--set-tests' and `--exclude-tests' options
if opts.tests != "all" and \
......@@ -261,8 +264,7 @@ def main():
# Run burnin
# The return value denotes the success status
return common.run_burnin(testsuites, failfast=failfast,
final_report=opts.final_report)
return common.run_burnin(testsuites, failfast=failfast)
if __name__ == "__main__":
......
......@@ -455,7 +455,7 @@ def initialize(opts, testsuites, stale_testsuites):
curr_time = datetime.datetime.now()
logger = Log(opts.log_folder, verbose=opts.verbose,
use_colors=opts.use_colors, in_parallel=False,
quiet=opts.quiet, curr_time=curr_time)
log_level=opts.log_level, curr_time=curr_time)
# Initialize clients
Clients.auth_url = opts.auth_url
......@@ -489,7 +489,7 @@ def initialize(opts, testsuites, stale_testsuites):
# --------------------------------------------------------------------
# Run Burnin
def run_burnin(testsuites, failfast=False, final_report=False):
def run_burnin(testsuites, failfast=False):
"""Run burnin testsuites"""
global logger # Using global. pylint: disable-msg=C0103,W0603,W0602
......@@ -500,9 +500,6 @@ def run_burnin(testsuites, failfast=False, final_report=False):
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)
......
......@@ -256,12 +256,14 @@ class CycladesTests(BurninTests):
net_id = nic['network_id']
if network is None:
if self.clients.cyclades.get_network_details(net_id)['public']:
addrs = nic['ipv' + str(version)]
break
if nic['ipv' + str(version)]:
addrs = nic['ipv' + str(version)]
break
else:
if net_id == network['id']:
addrs = nic['ipv%s' % version]
break
if nic['ipv' + str(version)]:
addrs = nic['ipv' + str(version)]
break
self.assertIsNotNone(addrs, "Can not get IP from server attachments")
if network is None:
......
......@@ -212,7 +212,7 @@ class Log(object):
# ----------------------------------
# Too many arguments. pylint: disable-msg=R0913
def __init__(self, output_dir, verbose=1, use_colors=True,
in_parallel=False, quiet=False, curr_time=None):
in_parallel=False, log_level=0, curr_time=None):
"""Initialize our loggers
The file to be used by our file logger will be created inside
......@@ -229,14 +229,19 @@ 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
@type log_level: int
@param log_level: logging level
0: log to console and file
1: log to file only and output the results to console
2: don't log
@type curr_time: datetime.datetime()
@param curr_time: The current time (used as burnin's run id)
"""
self.verbose = verbose
self.use_colors = use_colors
self.in_parallel = in_parallel
self.quiet = quiet
self.log_level = log_level
assert output_dir
......@@ -266,6 +271,8 @@ class Log(object):
def _create_logging_file(self, timestamp):
"""Create the logging file"""
if self.log_level > 1:
return
self.debug(None, "Using \"%s\" file for logging", self.file_location)
with open(self.file_location, 'w') as out_file:
out_file.write(SECTION_SEPARATOR + "\n")
......@@ -277,6 +284,7 @@ class Log(object):
def __del__(self):
"""Delete the Log object"""
self.print_logfile_to_stdout()
# Remove the lock file
if hasattr(self, "file_location"):
file_lock = os.path.splitext(self.file_location)[0] + LOCK_EXT
......@@ -287,8 +295,9 @@ class Log(object):
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())
if self.log_level == 1:
with open(self.file_location, 'r') as fin:
sys.stdout.write(fin.read())
# ----------------------------------
# Logging methods
......@@ -358,22 +367,26 @@ class Log(object):
def _write_to_stdout(self, section, msg):
"""Write to stdout"""
if not self.quiet:
if section is not None and self.in_parallel:
sys.stdout.write(section + ": " + msg)
else:
sys.stdout.write(msg)
if self.log_level > 0:
return
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 not self.quiet:
if section is not None and self.in_parallel:
sys.stderr.write(section + ": " + msg)
else:
sys.stderr.write(msg)
if self.log_level > 0:
return
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"""
if self.log_level > 1:
return
_write_log_file(self.file_location, section, msg)
# ----------------------------------
......@@ -388,11 +401,11 @@ class Log(object):
# Add a new section in the logging file
test_runned = " * " + testsuite + "\n"
_write_log_file(self.file_location, SECTION_RUNNED, test_runned)
self._write_to_file(SECTION_RUNNED, test_runned)
new_section_entry = \
SECTION_SEPARATOR + "\n" + SECTION_PREFIX + testsuite + "\n\n\n\n"
_write_log_file(self.file_location, SECTION_NEW, new_section_entry)
self._write_to_file(SECTION_NEW, new_section_entry)
# Add new section to the stdout
msg = "Starting testsuite %s" % testsuite
......@@ -408,7 +421,7 @@ class Log(object):
assert testsuite, "Testsuite name can not be emtpy"
# Add our testsuite to Results
_write_log_file(self.file_location, SECTION_PASSED, testsuite)
self._write_to_file(SECTION_PASSED, testsuite)
# Add success to stdout
msg = "Testsuite %s passed" % testsuite
......@@ -424,7 +437,7 @@ class Log(object):
assert testsuite, "Testsuite name can not be emtpy"
# Add our testsuite to Results
_write_log_file(self.file_location, SECTION_FAILED, testsuite)
self._write_to_file(SECTION_FAILED, testsuite)
# Add success to stdout
msg = "Testsuite %s failed" % testsuite
......
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