Created
October 21, 2015 02:40
-
-
Save apahim/f4e471e7944739f34b2f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit f91d8436bad1cad9c479acc08a23fb96f0de10e4 | |
Author: Amador Pahim <[email protected]> | |
Date: Wed Oct 21 00:36:00 2015 -0200 | |
Initial support for replay jobs | |
- Creating the directory structure: datadir/job-results/<job_dir>/.replay/ | |
- Recording the job urls. | |
- Adding option '--replay'. | |
- Locating the <job_dir> based on provided hash. | |
- Replay a job loading recorded urls. | |
Signed-off-by: Amador Pahim <[email protected]> | |
diff --git a/avocado/core/job.py b/avocado/core/job.py | |
index 0e15d92..a218342 100644 | |
--- a/avocado/core/job.py | |
+++ b/avocado/core/job.py | |
@@ -26,6 +26,9 @@ import traceback | |
import tempfile | |
import shutil | |
import fnmatch | |
+import glob | |
+import re | |
+import ast | |
from . import version | |
from . import data_dir | |
@@ -81,6 +84,7 @@ class Job(object): | |
args = argparse.Namespace() | |
self.args = args | |
self.standalone = getattr(self.args, 'standalone', False) | |
+ self.replay = getattr(self.args, 'replay', False) | |
unique_id = getattr(self.args, 'unique_job_id', None) | |
if unique_id is None: | |
unique_id = job_id.create_unique_job_id() | |
@@ -141,6 +145,10 @@ class Job(object): | |
with open(self.idfile, 'w') as id_file_obj: | |
id_file_obj.write("%s\n" % self.unique_id) | |
+ def _setup_job_replay(self): | |
+ self.replay_dir = path.init_dir(self.logdir, '.replay') | |
+ self.replay_urls = os.path.join(self.replay_dir, 'urls') | |
+ | |
def _update_latest_link(self): | |
""" | |
Update the latest job result symbolic link [avocado-logs-dir]/latest. | |
@@ -431,6 +439,13 @@ class Job(object): | |
self._log_mux_variants(mux) | |
self._log_job_id() | |
+ def _record_job_replay(self, urls): | |
+ self._record_urls(urls) | |
+ | |
+ def _record_urls(self, urls): | |
+ with open(self.replay_urls, 'w') as urls_file_obj: | |
+ urls_file_obj.write("%s" % urls) | |
+ | |
def _run(self, urls=None): | |
""" | |
Unhandled job method. Runs a list of test URLs to its completion. | |
@@ -444,6 +459,7 @@ class Job(object): | |
that configure a job failure. | |
""" | |
self._setup_job_results() | |
+ self._setup_job_replay() | |
self.view.start_file_logging(self.logfile, | |
self.loglevel, | |
self.unique_id) | |
@@ -472,6 +488,7 @@ class Job(object): | |
self._start_sysinfo() | |
self._log_job_debug_info(mux) | |
+ self._record_job_replay(self._handle_urls(urls)) | |
self.view.logfile = self.logfile | |
failures = self.test_runner.run_suite(test_suite, mux, | |
@@ -515,7 +532,10 @@ class Job(object): | |
""" | |
runtime.CURRENT_JOB = self | |
try: | |
- return self._run(urls) | |
+ if self.replay: | |
+ return self._replay(self.replay) | |
+ else: | |
+ return self._run(urls) | |
except exceptions.JobBaseException, details: | |
self.status = details.status | |
fail_class = details.__class__.__name__ | |
@@ -547,6 +567,26 @@ class Job(object): | |
key_type=bool, default=False): | |
data_dir.clean_tmp_files() | |
+ def _get_recorded_urls(self, replaydir): | |
+ urlsfile = os.path.join(self.logdir, replaydir, ".replay", "urls") | |
+ with open(urlsfile, 'r') as urls_file_obj: | |
+ urls = urls_file_obj.read() | |
+ | |
+ return ast.literal_eval(urls) | |
+ | |
+ def _probe_job_replay_dir(self, jobid): | |
+ idfile_pattern = '%s/job-*/id' % data_dir.get_logs_dir() | |
+ for id_file in glob.glob(idfile_pattern): | |
+ with open(id_file, 'r') as id_file_obj: | |
+ fileid = id_file_obj.read().strip('\n') | |
+ if re.match(jobid,fileid): | |
+ return os.path.dirname(id_file) | |
+ | |
+ def _replay(self, jobid): | |
+ job_replaydir = self._probe_job_replay_dir(jobid) | |
+ urls = self._get_recorded_urls(job_replaydir) | |
+ return self._run(urls) | |
+ | |
class TestProgram(object): | |
diff --git a/avocado/core/plugins/runner.py b/avocado/core/plugins/runner.py | |
index 1fa254a..d8cf192 100644 | |
--- a/avocado/core/plugins/runner.py | |
+++ b/avocado/core/plugins/runner.py | |
@@ -50,6 +50,10 @@ class TestRunner(plugin.Plugin): | |
self.parser.add_argument('url', type=str, default=[], nargs='*', | |
help='List of test IDs (aliases or paths)') | |
+ self.parser.add_argument('--replay', dest='replay', | |
+ type=str, default=None, | |
+ help='Replay a job identified by its hash') | |
+ | |
self.parser.add_argument('-z', '--archive', action='store_true', default=False, | |
help='Archive (ZIP) files generated by tests') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment