diff --git a/avocado/core/replay.py b/avocado/core/replay.py index 86a8f48cc32172a7cec0db71c37445a398358d4f..4495b2acd117dd89142ecad01cd817aaea11dc0c 100644 --- a/avocado/core/replay.py +++ b/avocado/core/replay.py @@ -36,6 +36,7 @@ def record(args, logdir, mux, urls=None): path_urls = os.path.join(replay_dir, 'urls') path_mux = os.path.join(replay_dir, 'multiplex') path_pwd = os.path.join(replay_dir, 'pwd') + path_args = os.path.join(replay_dir, 'args') if urls: with open(path_urls, 'w') as f: @@ -50,6 +51,9 @@ def record(args, logdir, mux, urls=None): with open(path_pwd, 'w') as f: f.write('%s' % os.getcwd()) + with open(path_args, 'w') as f: + pickle.dump(args.__dict__, f, pickle.HIGHEST_PROTOCOL) + def retrieve_pwd(resultsdir): recorded_pwd = os.path.join(resultsdir, "replay", "pwd") @@ -99,6 +103,15 @@ def retrieve_replay_map(resultsdir, replay_filter): return replay_map +def retrieve_args(resultsdir): + pkl_path = os.path.join(resultsdir, 'replay', 'args') + if not os.path.exists(pkl_path): + return None + + with open(pkl_path, 'r') as f: + return pickle.load(f) + + def get_resultsdir(logdir, jobid): matches = 0 short_jobid = jobid[:7] diff --git a/avocado/plugins/replay.py b/avocado/plugins/replay.py index 886f619467754f97192376f1a7b3276dafde7246..9953b2d586f279cd63f7b83ccbf533f3b37985bb 100644 --- a/avocado/plugins/replay.py +++ b/avocado/plugins/replay.py @@ -129,9 +129,29 @@ class Replay(CLI): % (args.replay_jobid, resultsdir)) log.error(msg) sys.exit(exit_codes.AVOCADO_JOB_FAIL) - setattr(args, 'replay_sourcejob', sourcejob) + replay_args = replay.retrieve_args(resultsdir) + whitelist = ['loaders', + 'external_runner', + 'external_runner_testdir', + 'external_runner_chdir'] + if replay_args is None: + log.warn('Source job args data not found. These options will not ' + 'be loaded in this replay job: %s', ', '.join(whitelist)) + else: + for option in whitelist: + optvalue = getattr(args, option, None) + if optvalue: + log.warn("Overriding the replay %s with the --%s value " + "given on the command line.", + option.replace('_', '-'), + option.replace('_', '-')) + else: + setattr(args, option, replay_args[option]) + + # Keeping this for compatibility. + # TODO: Use replay_args['url'] at some point in the future. if getattr(args, 'url', None): log.warn('Overriding the replay urls with urls provided in ' 'command line.') diff --git a/selftests/functional/test_replay.py b/selftests/functional/test_replay_basic.py similarity index 93% rename from selftests/functional/test_replay.py rename to selftests/functional/test_replay_basic.py index 79084990c3178a307de5fdf07f5230656bb4a43a..2dae91c7da61eb62ebd04eb76c90f8808548237a 100644 --- a/selftests/functional/test_replay.py +++ b/selftests/functional/test_replay_basic.py @@ -23,13 +23,13 @@ class ReplayTests(unittest.TestCase): def setUp(self): self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__) - cmd_line = ('./scripts/avocado run passtest --multiplex ' + cmd_line = ('./scripts/avocado run passtest ' + '--multiplex ' 'examples/tests/sleeptest.py.data/sleeptest.yaml ' - '--job-results-dir %s --sysinfo=off' % + '--job-results-dir %s --sysinfo=off --json -' % self.tmpdir) expected_rc = exit_codes.AVOCADO_ALL_OK self.run_and_check(cmd_line, expected_rc) - self.jobdir = ''.join(glob.glob(os.path.join(self.tmpdir, 'job-*'))) idfile = ''.join(os.path.join(self.jobdir, 'id')) with open(idfile, 'r') as f: @@ -51,7 +51,7 @@ class ReplayTests(unittest.TestCase): self.run_and_check(cmd_line, expected_rc) def test_run_replay_data(self): - file_list = ['multiplex', 'config', 'urls', 'pwd'] + file_list = ['multiplex', 'config', 'urls', 'pwd', 'args'] for filename in file_list: path = os.path.join(self.jobdir, 'replay', filename) self.assertTrue(glob.glob(path)) @@ -106,10 +106,7 @@ class ReplayTests(unittest.TestCase): '--sysinfo=off' % (self.jobid, self.tmpdir, self.jobdir)) expected_rc = exit_codes.AVOCADO_ALL_OK result = self.run_and_check(cmd_line, expected_rc) - msg = '(1/4) passtest.py:PassTest.test.variant1: SKIP\n ' \ - '(2/4) passtest.py:PassTest.test.variant2: SKIP\n ' \ - '(3/4) passtest.py:PassTest.test.variant3: SKIP\n ' \ - '(4/4) passtest.py:PassTest.test.variant4: SKIP' + msg = 'RESULTS : PASS 0 | ERROR 0 | FAIL 0 | SKIP 4 | WARN 0 | INTERRUPT 0' self.assertIn(msg, result.stdout) def test_run_replay_remotefail(self): diff --git a/selftests/functional/test_replay_external_runner.py b/selftests/functional/test_replay_external_runner.py new file mode 100644 index 0000000000000000000000000000000000000000..e58bcf75fce3977740d58d97bc038e26ab306437 --- /dev/null +++ b/selftests/functional/test_replay_external_runner.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python + +import glob +import os +import sys +import tempfile +import shutil + +if sys.version_info[:2] == (2, 6): + import unittest2 as unittest +else: + import unittest + +from avocado.core import exit_codes +from avocado.utils import process +from avocado.utils import script + + +basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..') +basedir = os.path.abspath(basedir) + + +class ReplayTests(unittest.TestCase): + + def setUp(self): + self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__) + test = script.make_script(os.path.join(self.tmpdir, 'test'), 'exit 0') + cmd_line = ('./scripts/avocado run %s ' + '--multiplex ' + 'examples/tests/sleeptest.py.data/sleeptest.yaml ' + '--external-runner /bin/bash ' + '--job-results-dir %s --sysinfo=off --json -' % + (test, self.tmpdir)) + expected_rc = exit_codes.AVOCADO_ALL_OK + self.run_and_check(cmd_line, expected_rc) + self.jobdir = ''.join(glob.glob(os.path.join(self.tmpdir, 'job-*'))) + idfile = ''.join(os.path.join(self.jobdir, 'id')) + with open(idfile, 'r') as f: + self.jobid = f.read().strip('\n') + + def run_and_check(self, cmd_line, expected_rc): + os.chdir(basedir) + result = process.run(cmd_line, ignore_status=True) + self.assertEqual(result.exit_status, expected_rc, + "Command %s did not return rc " + "%d:\n%s" % (cmd_line, expected_rc, result)) + return result + + def test_run_replay_external_runner(self): + cmd_line = ('./scripts/avocado run --replay %s ' + '--external-runner /bin/sh ' + '--job-results-dir %s --replay-data-dir %s --sysinfo=off' % + (self.jobid, self.tmpdir, self.jobdir)) + expected_rc = exit_codes.AVOCADO_ALL_OK + result = self.run_and_check(cmd_line, expected_rc) + msg = "Overriding the replay external-runner with the "\ + "--external-runner value given on the command line." + self.assertIn(msg, result.stderr) + + def tearDown(self): + shutil.rmtree(self.tmpdir) + + +if __name__ == '__main__': + unittest.main()