From c066e53a4c6d700a4c0e540bf889b984adcc551d Mon Sep 17 00:00:00 2001 From: Lucas Meneghel Rodrigues Date: Thu, 19 Feb 2015 20:03:28 -0200 Subject: [PATCH] avocado.plugins: Fix HTML report links for remote/vm tests Modify the VM test info in order to correct paths of test directories. This will fix a long standing bug with regards to broken HTML report links. Signed-off-by: Lucas Meneghel Rodrigues --- avocado/plugins/htmlresult.py | 7 ++++-- avocado/plugins/remote.py | 24 +++++++++++++++---- avocado/test.py | 7 ++++-- selftests/all/unit/avocado/remote_unittest.py | 12 ++++++++-- 4 files changed, 40 insertions(+), 10 deletions(-) diff --git a/avocado/plugins/htmlresult.py b/avocado/plugins/htmlresult.py index f423a601..0ac79c5b 100644 --- a/avocado/plugins/htmlresult.py +++ b/avocado/plugins/htmlresult.py @@ -113,10 +113,11 @@ class ReportModel(object): for t in test_info: t['logdir'] = os.path.join(self._results_dir( relative_links=self.relative_links), - 'test-results', t['url']) + 'test-results', t['logdir']) t['logfile'] = os.path.join(self._results_dir( relative_links=self.relative_links), - 'test-results', t['url'], 'debug.log') + 'test-results', t['logdir'], + 'debug.log') t['logfile_basename'] = os.path.basename(t['logfile']) t['time'] = "%.2f" % t['time'] t['time_start'] = time.strftime("%Y-%m-%d %H:%M:%S", @@ -204,6 +205,8 @@ class HTMLTestResult(TestResult): 'status': state['status'], 'fail_reason': state['fail_reason'], 'whiteboard': state['whiteboard'], + 'logdir': state['logdir'], + 'logfile': state['logfile'] } self.json['tests'].append(t) diff --git a/avocado/plugins/remote.py b/avocado/plugins/remote.py index 19e236ae..7f2789567 100644 --- a/avocado/plugins/remote.py +++ b/avocado/plugins/remote.py @@ -50,15 +50,27 @@ class RemoteTestRunner(TestRunner): if result.exit_status == 127: raise exceptions.JobError('Remote machine does not have avocado ' 'installed') + json_result = None for json_output in result.stdout.splitlines(): # We expect dictionary: if json_output.startswith('{') and json_output.endswith('}'): try: - return json.loads(json_output) + json_result = json.loads(json_output) except ValueError: pass - raise ValueError("Could not parse JSON from avocado remote output:" - "\n%s" % result.stdout) + + if json_result is None: + raise ValueError("Could not parse JSON from avocado remote output:" + "\n%s" % result.stdout) + + for t_dict in json_result['tests']: + logdir = os.path.dirname(self.result.stream.debuglog) + logdir = os.path.join(logdir, 'test-results') + logdir = os.path.join(logdir, os.path.relpath(t_dict['url'], '/')) + t_dict['logdir'] = logdir + t_dict['logfile'] = os.path.join(logdir, 'debug.log') + + return json_result def run_suite(self, test_suite): """ @@ -79,7 +91,11 @@ class RemoteTestRunner(TestRunner): time=tst['time'], start=tst['start'], end=tst['end'], - status=tst['status']) + status=tst['status'], + logdir=tst['logdir'], + logfile=tst['logfile'], + fail_reason=tst['fail_reason'] + ) state = test.get_state() self.result.start_test(state) self.result.check_test(state) diff --git a/avocado/test.py b/avocado/test.py index 5ff6a4e7..f8d05088 100644 --- a/avocado/test.py +++ b/avocado/test.py @@ -612,7 +612,8 @@ class RemoteTest(object): Mimics :class:`avocado.test.Test` for remote tests. """ - def __init__(self, name, status, time, start, end): + def __init__(self, name, status, time, start, end, fail_reason, logdir, + logfile): note = "Not supported yet" self.name = name self.tagged_name = name @@ -623,9 +624,11 @@ class RemoteTest(object): self.fail_class = note self.traceback = note self.text_output = note - self.fail_reason = note + self.fail_reason = fail_reason self.whiteboard = '' self.job_unique_id = '' + self.logdir = logdir + self.logfile = logfile def get_state(self): """ diff --git a/selftests/all/unit/avocado/remote_unittest.py b/selftests/all/unit/avocado/remote_unittest.py index 3ddbcefd..1658d127 100644 --- a/selftests/all/unit/avocado/remote_unittest.py +++ b/selftests/all/unit/avocado/remote_unittest.py @@ -1,19 +1,24 @@ #!/usr/bin/env python import unittest +import os from flexmock import flexmock, flexmock_teardown from avocado.plugins import remote +cwd = os.getcwd() JSON_RESULTS = ('Something other than json\n' '{"tests": [{"test": "sleeptest.1", "url": "sleeptest", ' + '"fail_reason": "None", ' '"status": "PASS", "time": 1.23, "start": 0, "end": 1.23}],' '"debuglog": "/home/user/avocado/logs/run-2014-05-26-15.45.' '37/debug.log", "errors": 0, "skip": 0, "time": 1.4, ' + '"logdir": "/local/path/test-results%s/sleeptest", ' + '"logdir": "/local/path/test-results%s/sleeptest", ' '"start": 0, "end": 1.4, "pass": 1, "failures": 0, "total": ' - '1}\nAdditional stuff other than json') + '1}\nAdditional stuff other than json' % (cwd, cwd)) class RemoteTestRunnerTest(unittest.TestCase): @@ -42,7 +47,10 @@ class RemoteTestRunnerTest(unittest.TestCase): 'text_output': 'Not supported yet', 'time_end': 1.23, 'tagged_name': u'sleeptest.1', 'time_elapsed': 1.23, 'fail_class': 'Not supported yet', 'job_unique_id': '', - 'fail_reason': 'Not supported yet'} + 'fail_reason': 'None', + 'logdir': '/local/path/test-results%s/sleeptest' % cwd, + 'logfile': '/local/path/test-results%s/sleeptest/debug.log' % + cwd} Results.should_receive('start_test').once().with_args(args).ordered() Results.should_receive('check_test').once().with_args(args).ordered() (Remote.should_receive('receive_files') -- GitLab