avocado: Make job ID more prominent in avocado

Make some changes to bring the concept of job ID as a
user visible information:

* Make the human output to display the job ID
* Make the json output to have the job ID
* Record the job id in a file inside the results dir

Adapt functional tests to that new schema.
Signed-off-by: NLucas Meneghel Rodrigues <lmr@redhat.com>
上级 7723cfed
......@@ -219,13 +219,15 @@ class OutputManager(object):
extra = {'skip_newline': skip_newline}
self.console_log.log(level=level, msg=msg, extra=extra)
def start_file_logging(self, logfile, loglevel):
def start_file_logging(self, logfile, loglevel, unique_id):
"""
Start the main file logging.
:param logfile: Path to file that will receive logging.
:param loglevel: Level of the logger. Example: :mod:`logging.DEBUG`.
:param unique_id: job.Job() unique id attribute.
"""
self.job_unique_id = unique_id
self.debuglog = logfile
self.file_handler = logging.FileHandler(filename=logfile)
self.file_handler.setLevel(loglevel)
......
......@@ -243,6 +243,11 @@ class Job(object):
self.unique_id = str(uuid.uuid4())
self.logdir = data_dir.get_job_logs_dir(self.args, self.unique_id)
self.logfile = os.path.join(self.logdir, "job.log")
self.idfile = os.path.join(self.logdir, "id")
with open(self.idfile, 'w') as id_file_obj:
id_file_obj.write("%s\n" % self.unique_id)
if self.args is not None:
self.loglevel = args.log_level or logging.DEBUG
self.multiplex_file = args.multiplex_file
......@@ -381,7 +386,8 @@ class Job(object):
self._make_test_runner()
self.output_manager.start_file_logging(self.logfile,
self.loglevel)
self.loglevel,
self.unique_id)
self.output_manager.logfile = self.logfile
failures = self.test_runner.run(params_list)
self.output_manager.stop_file_logging()
......
......@@ -50,6 +50,8 @@ class JSONTestResult(TestResult):
:type state: dict
"""
TestResult.end_test(self, state)
if 'job_id' not in self.json:
self.json['job_id'] = state['job_unique_id']
t = {'test': state['tagged_name'],
'url': state['name'],
'time': state['time_elapsed'],
......
......@@ -244,8 +244,9 @@ class HumanTestResult(TestResult):
Called once before any tests are executed.
"""
TestResult.start_tests(self)
self.stream.log_header("JOB ID : %s" % self.stream.job_unique_id)
self.stream.log_header("JOB LOG: %s" % self.stream.logfile)
self.stream.log_header("TESTS: %s" % self.tests_total)
self.stream.log_header("TESTS : %s" % self.tests_total)
def end_tests(self):
"""
......
......@@ -165,8 +165,8 @@ class OutputPluginTest(unittest.TestCase):
"Avocado did not return rc %d:\n%s" %
(expected_rc, result))
output_lines = output.splitlines()
first_line = output_lines[0]
debug_log = first_line.split()[-1]
second_line = output_lines[1]
debug_log = second_line.split()[-1]
self.check_output_files(debug_log)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册