Skip to content

Instantly share code, notes, and snippets.

@apahim
Created October 22, 2015 20:33
Show Gist options
  • Save apahim/c30a50540d625a348ae1 to your computer and use it in GitHub Desktop.
Save apahim/c30a50540d625a348ae1 to your computer and use it in GitHub Desktop.
commit 2213ff23d17acd9f00b70133c18c2581b7f54c71
Author: Amador Pahim <[email protected]>
Date: Thu Oct 22 18:27:43 2015 -0200
Support for replay multiplex
Signed-off-by: Amador Pahim <[email protected]>
diff --git a/avocado/core/job.py b/avocado/core/job.py
index a218342..8a436b3 100644
--- a/avocado/core/job.py
+++ b/avocado/core/job.py
@@ -29,6 +29,7 @@ import fnmatch
import glob
import re
import ast
+import json
from . import version
from . import data_dir
@@ -147,6 +148,7 @@ class Job(object):
def _setup_job_replay(self):
self.replay_dir = path.init_dir(self.logdir, '.replay')
+ self.replay_dir_mux = path.init_dir(self.replay_dir, 'multiplex')
self.replay_urls = os.path.join(self.replay_dir, 'urls')
def _update_latest_link(self):
@@ -441,11 +443,22 @@ class Job(object):
def _record_job_replay(self, urls):
self._record_urls(urls)
+ self._record_multiplex()
def _record_urls(self, urls):
with open(self.replay_urls, 'w') as urls_file_obj:
urls_file_obj.write("%s" % urls)
+ def _record_multiplex(self):
+ #TODO Make recorded mux files unique.
+ if self.args.multiplex_files:
+ for mux_file in self.args.multiplex_files:
+ rec_mux_file = os.path.join(self.replay_dir_mux,
+ os.path.basename(mux_file))
+ with open(rec_mux_file, 'w') as rec_mux_file_obj:
+ with open(mux_file, 'r') as mux_file_obj:
+ rec_mux_file_obj.write(mux_file_obj.read())
+
def _run(self, urls=None):
"""
Unhandled job method. Runs a list of test URLs to its completion.
@@ -533,7 +546,7 @@ class Job(object):
runtime.CURRENT_JOB = self
try:
if self.replay:
- return self._replay(self.replay)
+ return self._replay(self.replay, urls)
else:
return self._run(urls)
except exceptions.JobBaseException, details:
@@ -568,12 +581,24 @@ class Job(object):
data_dir.clean_tmp_files()
def _get_recorded_urls(self, replaydir):
- urlsfile = os.path.join(self.logdir, replaydir, ".replay", "urls")
+ urlsfile = os.path.join(self.logdir, replaydir, "urls")
with open(urlsfile, 'r') as urls_file_obj:
urls = urls_file_obj.read()
return ast.literal_eval(urls)
+ def _get_recorded_muxfiles(self, replaydir):
+ mux_dir = os.path.join(self.logdir, replaydir, "multiplex")
+ pattern = os.path.join(mux_dir, "*.yaml")
+ return glob.glob(pattern)
+
+# def _get_recorded_results(self, replaydir):
+# resultsfile = os.path.join(self.logdir, replaydir, "results.json")
+# with open(resultsfile, 'r') as results_file_obj:
+# results = results_file_obj.read()
+#
+# return json.loads(results)
+
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):
@@ -582,10 +607,21 @@ class Job(object):
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)
+ def _replay(self, jobid, urls):
+ urls = self._handle_urls(urls)
+ replaydir = os.path.join(self._probe_job_replay_dir(jobid),
+ ".replay")
+
+ if not self.args.multiplex_files:
+ setattr(self.args, 'multiplex_files',
+ self._get_recorded_muxfiles(replaydir))
+
+ if not urls:
+ urls = self._get_recorded_urls(replaydir)
+ return self._run(urls)
+ else:
+ return self._run(urls)
+
class TestProgram(object):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment