Skip to content

Instantly share code, notes, and snippets.

@apahim
Created October 21, 2015 02:29
Show Gist options
  • Save apahim/aa67387a8bd1ee3f75cb to your computer and use it in GitHub Desktop.
Save apahim/aa67387a8bd1ee3f75cb to your computer and use it in GitHub Desktop.
commit 721c00b4343912da743efe3605889caa5f5dec4d
Author: Amador Pahim <[email protected]>
Date: Tue Oct 20 00:39:39 2015 -0200
Create job record dir structure
In order to record the jobs machine-readable information for
further job replays, this patch creates a new directory 'jobs'
with sub-directories named after the job_id:
~/avocado/jobs/<job_id>
Signed-off-by: Amador Pahim <[email protected]>
diff --git a/avocado/core/data_dir.py b/avocado/core/data_dir.py
index e634d6b..d00d979 100755
--- a/avocado/core/data_dir.py
+++ b/avocado/core/data_dir.py
@@ -46,6 +46,7 @@ SETTINGS_BASE_DIR = os.path.expanduser(settings.get_value('datadir.paths', 'base
SETTINGS_TEST_DIR = os.path.expanduser(settings.get_value('datadir.paths', 'test_dir'))
SETTINGS_DATA_DIR = os.path.expanduser(settings.get_value('datadir.paths', 'data_dir'))
SETTINGS_LOG_DIR = os.path.expanduser(settings.get_value('datadir.paths', 'logs_dir'))
+SETTINGS_JOB_DIR = os.path.expanduser(settings.get_value('datadir.paths', 'job_dir'))
SYSTEM_BASE_DIR = '/var/lib/avocado'
if 'VIRTUAL_ENV' in os.environ:
@@ -53,11 +54,13 @@ if 'VIRTUAL_ENV' in os.environ:
SYSTEM_TEST_DIR = os.path.join(SYSTEM_BASE_DIR, 'tests')
SYSTEM_DATA_DIR = os.path.join(SYSTEM_BASE_DIR, 'data')
SYSTEM_LOG_DIR = os.path.join(SYSTEM_BASE_DIR, 'job-results')
+SYSTEM_JOB_DIR = os.path.join(SYSTEM_BASE_DIR, 'jobs')
USER_BASE_DIR = os.path.expanduser('~/avocado')
USER_TEST_DIR = os.path.join(USER_BASE_DIR, 'tests')
USER_DATA_DIR = os.path.join(USER_BASE_DIR, 'data')
USER_LOG_DIR = os.path.join(USER_BASE_DIR, 'job-results')
+USER_JOB_DIR = os.path.join(USER_BASE_DIR, 'jobs')
BASE_TMP_DIR = os.environ.get('TMPDIR', '/var/tmp')
@@ -201,6 +204,15 @@ def get_logs_dir():
return _get_rw_dir(SETTINGS_LOG_DIR, SYSTEM_LOG_DIR, USER_LOG_DIR)
+def get_job_dir():
+ """
+ Get the most appropriate job dir location.
+
+ The job dir is where we store job data for a further re-run.
+ """
+ return _get_rw_dir(SETTINGS_JOB_DIR, SYSTEM_JOB_DIR, USER_JOB_DIR)
+
+
def create_job_logs_dir(logdir=None, unique_id=None):
"""
Create a log directory for a job, or a stand alone execution of a test.
@@ -237,6 +249,27 @@ def create_job_logs_dir(logdir=None, unique_id=None):
% (debugdir))
+def create_job_dir(jobdir=None, unique_id=None):
+ """
+ Create a job directory to store information for a further re-run.
+
+ :param jobdir: Base job directory, if `None`, use value from configuration.
+ :param unique_id: The unique identification.
+ :rtype: basestring
+ """
+ if jobdir is None:
+ jobdir = get_job_dir()
+ if not os.path.exists(jobdir):
+ utils_path.init_dir(jobdir)
+ hashdir = os.path.join(jobdir, unique_id)
+ try:
+ os.mkdir(hashdir)
+ return hashdir
+ except:
+ raise IOError("SHA1 collision [%s]. You better go to Vegas."
+ % (hashdir))
+
+
class _TmpDirTracker(Borg):
def __init__(self):
diff --git a/avocado/core/job.py b/avocado/core/job.py
index 0e15d92..c3ba361 100644
--- a/avocado/core/job.py
+++ b/avocado/core/job.py
@@ -87,6 +87,7 @@ class Job(object):
self.unique_id = unique_id
self.view = output.View(app_args=self.args)
self.logdir = None
+ self.jobdir = None
raw_log_level = settings.get_value('job.output', 'loglevel',
default='debug')
mapping = {'info': logging.INFO,
@@ -141,6 +142,17 @@ class Job(object):
with open(self.idfile, 'w') as id_file_obj:
id_file_obj.write("%s\n" % self.unique_id)
+ def _setup_job_record(self):
+ jobdir = getattr(self.args, 'jobdir', None)
+ 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_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")
+ self.rec_muxfile = os.path.join(self.jobdir, "multiplex")
+ self.rec_pluginsfile = os.path.join(self.jobdir, "plugins")
+
def _update_latest_link(self):
"""
Update the latest job result symbolic link [avocado-logs-dir]/latest.
@@ -354,6 +366,7 @@ class Job(object):
job_log.info('tests ' + data_dir.get_test_dir())
job_log.info('data ' + data_dir.get_data_dir())
job_log.info('logs ' + data_dir.get_logs_dir())
+ job_log.info('jobs ' + data_dir.get_job_dir())
job_log.info('')
@staticmethod
@@ -444,6 +457,7 @@ class Job(object):
that configure a job failure.
"""
self._setup_job_results()
+ self._setup_job_record()
self.view.start_file_logging(self.logfile,
self.loglevel,
self.unique_id)
diff --git a/etc/avocado/avocado.conf b/etc/avocado/avocado.conf
index a1c34b9..a2a4f05 100644
--- a/etc/avocado/avocado.conf
+++ b/etc/avocado/avocado.conf
@@ -7,6 +7,8 @@ test_dir = /usr/share/avocado/tests
data_dir = /usr/share/avocado/data
# You may override the specific job results directory with logs_dir
logs_dir = ~/avocado/job-results
+# You may override the specific job record directory with job_dir
+job_dir = ~/avocado/jobs
[sysinfo.collect]
# Whether to collect system information during avocado jobs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment