Last active
October 25, 2015 15:32
-
-
Save apahim/7f7d9b2f1d6e5cb49af5 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 3ea2603add9fa72d51c1400dcb9e383b1ec7c277 | |
Author: Amador Pahim <[email protected]> | |
Date: Sun Oct 25 13:16:59 2015 -0200 | |
SUpport for record/replay with avocado settings | |
Signed-off-by: Amador Pahim <[email protected]> | |
diff --git a/avocado/core/job.py b/avocado/core/job.py | |
index d0e1735..4adf57e 100644 | |
--- a/avocado/core/job.py | |
+++ b/avocado/core/job.py | |
@@ -153,6 +153,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_config_file = os.path.join(self.replay_dir, 'config') | |
self.replay_urls = os.path.join(self.replay_dir, 'urls') | |
def _update_latest_link(self): | |
@@ -448,6 +449,7 @@ class Job(object): | |
def _record_job_replay(self, urls): | |
self._record_urls(urls) | |
self._record_multiplex() | |
+ self._record_config() | |
def _record_urls(self, urls): | |
with open(self.replay_urls, 'w') as urls_file_obj: | |
@@ -463,6 +465,10 @@ class Job(object): | |
with open(mux_file, 'r') as mux_file_obj: | |
rec_mux_file_obj.write(mux_file_obj.read()) | |
+ def _record_config(self): | |
+ with open(self.replay_config_file, 'a') as config_file_obj: | |
+ settings.config.write(config_file_obj) | |
+ | |
def _run(self, urls=None, replay_map=None): | |
""" | |
Unhandled job method. Runs a list of test URLs to its completion. | |
diff --git a/avocado/core/settings.py b/avocado/core/settings.py | |
index cc3ae65..c5547d2 100644 | |
--- a/avocado/core/settings.py | |
+++ b/avocado/core/settings.py | |
@@ -15,13 +15,16 @@ | |
""" | |
Reads the avocado settings from a .ini file (from python ConfigParser). | |
""" | |
+import argparse | |
import ast | |
import ConfigParser | |
import os | |
import sys | |
import glob | |
+import re | |
from ..utils import path | |
+from ..utils.data_structures import Borg | |
if 'VIRTUAL_ENV' in os.environ: | |
CFG_DIR = os.path.join(os.environ['VIRTUAL_ENV'], 'etc') | |
@@ -153,6 +156,25 @@ class Settings(object): | |
self.intree = False | |
self.config_paths = [] | |
self.config_paths_failed = [] | |
+ | |
+ self.parser = argparse.ArgumentParser() | |
+ self.parser.add_argument("--replay", type=str) | |
+ self.parser.add_argument('--replay-ignore', dest='replay-ignore', | |
+ type=str, default=None, nargs='*', | |
+ help='Ignore replay properties') | |
+ | |
+ self.args, extras = self.parser.parse_known_args() | |
+ self.replay = getattr(self.args, 'replay', False) | |
+ self.replay_ignore = getattr(self.args, 'replay-ignore', False) | |
+ if self.replay: | |
+ if self.replay_ignore and 'config' in self.replay_ignore: | |
+ pass | |
+ else: | |
+ self.process_config_path(config_path_system) | |
+ self.logdir = os.path.expanduser(self.get_value('datadir.paths', | |
+ 'logs_dir')) | |
+ config_path = self._get_recorded_settings() | |
+ | |
if config_path is None: | |
config_system = os.path.exists(config_path_system) | |
config_system_extra = os.path.exists(_config_dir_system_extra) | |
@@ -195,6 +217,18 @@ class Settings(object): | |
else: | |
self.config_paths_failed.append(pth) | |
+ def _probe_job_replay_dir(self): | |
+ idfile_pattern = '%s/job-*/id' % self.logdir | |
+ 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(self.replay, fileid): | |
+ return os.path.join(os.path.dirname(id_file), '.replay') | |
+ | |
+ def _get_recorded_settings(self): | |
+ replaydir = self._probe_job_replay_dir() | |
+ return os.path.join(replaydir, "config") | |
+ | |
def _handle_no_value(self, section, key, default): | |
""" | |
What to do if key in section has no value. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment