Created
October 21, 2015 02:31
-
-
Save apahim/85f3f8e4673a44e13199 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 7e88d979d0f3a033c4dada3308d60908894fd753 | |
Author: Amador Pahim <[email protected]> | |
Date: Tue Oct 20 17:04:07 2015 -0200 | |
Initial support for replay | |
Loading urls from a given job and icreating a new job using the loaded urls. | |
Signed-off-by: Amador Pahim <[email protected]> | |
diff --git a/avocado/core/job.py b/avocado/core/job.py | |
index abcb447..78a269a 100644 | |
--- a/avocado/core/job.py | |
+++ b/avocado/core/job.py | |
@@ -21,11 +21,13 @@ import argparse | |
import commands | |
import logging | |
import os | |
+import re | |
import sys | |
import traceback | |
import tempfile | |
import shutil | |
import fnmatch | |
+import ast | |
from . import version | |
from . import data_dir | |
@@ -80,6 +82,7 @@ class Job(object): | |
if args is None: | |
args = argparse.Namespace() | |
self.args = args | |
+ self.replay = getattr(self.args, 'replay', False) | |
self.standalone = getattr(self.args, 'standalone', False) | |
unique_id = getattr(self.args, 'unique_job_id', None) | |
if unique_id is None: | |
@@ -147,6 +150,7 @@ class Job(object): | |
self.jobdir = data_dir.create_job_dir(jobdir=jobdir, | |
unique_id=self.unique_id) | |
self.rec_cmdfile = os.path.join(self.jobdir, "command") | |
+ self.rec_urlsfile = os.path.join(self.jobdir, "urls") | |
self.rec_configfile = os.path.join(self.jobdir, "config") | |
self.rec_configfilesfile = os.path.join(self.jobdir, "configfiles") | |
self.rec_datadirsfile = os.path.join(self.jobdir, "datadirs") | |
@@ -448,6 +452,10 @@ class Job(object): | |
with open(self.rec_cmdfile, 'w') as cmd_file_obj: | |
cmd_file_obj.write("%s" % sys.argv) | |
+ def _record_urls(self, urls): | |
+ with open(self.rec_urlsfile, 'w') as urls_file_obj: | |
+ urls_file_obj.write("%s" % urls) | |
+ | |
def _record_config(self): | |
config_matrix = [] | |
for section in settings.config.sections(): | |
@@ -462,8 +470,9 @@ class Job(object): | |
with open(self.rec_configfile, 'w') as config_file_obj: | |
config_file_obj.write("%s" % config_dict) | |
- def _record_job(self): | |
+ def _record_job(self, urls): | |
self._record_cmdline() | |
+ self._record_urls(urls) | |
self._record_config() | |
def _run(self, urls=None): | |
@@ -508,7 +517,7 @@ class Job(object): | |
self._start_sysinfo() | |
self._log_job_debug_info(mux) | |
- self._record_job() | |
+ self._record_job(self._handle_urls(urls)) | |
self.view.logfile = self.logfile | |
failures = self.test_runner.run_suite(test_suite, mux, | |
@@ -552,7 +561,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__ | |
@@ -584,6 +596,26 @@ class Job(object): | |
key_type=bool, default=False): | |
data_dir.clean_tmp_files() | |
+ def _get_recorded_urls(self, unique_id): | |
+ urlsfile = os.path.join(data_dir.get_job_dir(), unique_id, "urls") | |
+ with open(urlsfile, 'r') as urls_file_obj: | |
+ urls = urls_file_obj.read() | |
+ | |
+ return ast.literal_eval(urls) | |
+ | |
+ def _probe_uniq_id(self, job_id): | |
+ match = [ item for item in os.listdir(data_dir.get_job_dir()) if re.match(job_id, item)] | |
+ if len(match) == 1: | |
+ return match[0] | |
+ else: | |
+ print 'HASH NOT FOUND' | |
+ raise | |
+ | |
+ def _replay(self, job_id): | |
+ recorded_job_id = self._probe_uniq_id(job_id) | |
+ urls = self._get_recorded_urls(recorded_job_id) | |
+ return self._run(urls) | |
+ | |
class TestProgram(object): | |
diff --git a/avocado/core/plugins/runner.py b/avocado/core/plugins/runner.py | |
index 1fa254a..97188e6 100644 | |
--- a/avocado/core/plugins/runner.py | |
+++ b/avocado/core/plugins/runner.py | |
@@ -47,6 +47,10 @@ class TestRunner(plugin.Plugin): | |
'run', | |
help='Run one or more tests (native test, test alias, binary or script)') | |
+ self.parser.add_argument('--replay', dest='replay', | |
+ type=str, default=None, | |
+ help='Replay a JOB identified by its hash') | |
+ | |
self.parser.add_argument('url', type=str, default=[], nargs='*', | |
help='List of test IDs (aliases or paths)') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello friend I am new to this site and bootstrap,now I am designing a website for one educational consultant ,I am trying to create about us button with more links like (about company,about staff, about students like this)
but when i place curser that time only i want to see them,,,,,sorry for my english ,,,,thnk u