提交 23ce2269 编写于 作者: C Cleber Rosa

Job: distinguish between the base log dir and the job logdir itself

The Job class code uses the same name, logdir, for both the directory
that will hold a given job's results (job-<timestamp>-<shortid>) and
the base directory, where the first one will be created.

This changes the naming so that the base log dir, only present in
the job arguments (the argparse.Namespace instance) will be named
"base_logdir".  The job's result dir, which value is kept in the
job instance itself, is still named "logdir".
Signed-off-by: NCleber Rosa <crosa@redhat.com>
上级 80ebf8ba
......@@ -154,40 +154,40 @@ def get_logs_dir():
SYSTEM_LOG_DIR, USER_LOG_DIR)
def create_job_logs_dir(logdir=None, unique_id=None):
def create_job_logs_dir(base_dir=None, unique_id=None):
"""
Create a log directory for a job, or a stand alone execution of a test.
:param logdir: Base log directory, if `None`, use value from configuration.
:param base_dir: Base log directory, if `None`, use value from configuration.
:param unique_id: The unique identification. If `None`, create one.
:rtype: basestring
"""
start_time = time.strftime('%Y-%m-%dT%H.%M')
if logdir is None:
logdir = get_logs_dir()
if not os.path.exists(logdir):
utils_path.init_dir(logdir)
if base_dir is None:
base_dir = get_logs_dir()
if not os.path.exists(base_dir):
utils_path.init_dir(base_dir)
# Stand alone tests handling
if unique_id is None:
unique_id = job_id.create_unique_job_id()
debugdir = os.path.join(logdir, 'job-%s-%s' % (start_time, unique_id[:7]))
logdir = os.path.join(base_dir, 'job-%s-%s' % (start_time, unique_id[:7]))
for i in xrange(7, len(unique_id)):
try:
os.mkdir(debugdir)
os.mkdir(logdir)
except OSError:
debugdir += unique_id[i]
logdir += unique_id[i]
continue
return debugdir
debugdir += "."
return logdir
logdir += "."
for i in xrange(1000):
try:
os.mkdir(debugdir + str(i))
os.mkdir(logdir + str(i))
except OSError:
continue
return debugdir + str(i)
return logdir + str(i)
raise IOError("Unable to create unique logdir in 1000 iterations: %s"
% (debugdir))
% (logdir))
class _TmpDirTracker(Borg):
......
......@@ -81,8 +81,8 @@ class Job(object):
if not self.args.unique_job_id:
self.args.unique_job_id = "0" * 40
self.args.sysinfo = False
if self.args.logdir is None:
self.args.logdir = tempfile.mkdtemp(prefix="avocado-dry-run-")
if self.args.base_logdir is None:
self.args.base_logdir = tempfile.mkdtemp(prefix="avocado-dry-run-")
unique_id = getattr(self.args, 'unique_job_id', None)
if unique_id is None:
......@@ -154,20 +154,20 @@ class Job(object):
"""
Prepares a job result directory, also known as logdir, for this job
"""
logdir = getattr(self.args, 'logdir', None)
base_logdir = getattr(self.args, 'base_logdir', None)
if self.standalone:
if logdir is not None:
logdir = os.path.abspath(logdir)
self.logdir = data_dir.create_job_logs_dir(logdir=logdir,
if base_logdir is not None:
base_logdir = os.path.abspath(base_logdir)
self.logdir = data_dir.create_job_logs_dir(base_dir=base_logdir,
unique_id=self.unique_id)
else:
self.logdir = tempfile.mkdtemp(prefix='avocado_' + __name__)
else:
if logdir is None:
if base_logdir is None:
self.logdir = data_dir.create_job_logs_dir(unique_id=self.unique_id)
else:
logdir = os.path.abspath(logdir)
self.logdir = data_dir.create_job_logs_dir(logdir=logdir,
base_logdir = os.path.abspath(base_logdir)
self.logdir = data_dir.create_job_logs_dir(base_dir=base_logdir,
unique_id=self.unique_id)
if not (self.standalone or getattr(self.args, "dry_run", False)):
self._update_latest_link()
......@@ -571,7 +571,7 @@ class TestProgram(object):
self.parser.add_argument('-r', '--remove-test-results',
action='store_true', help="remove all test "
"results files after test execution")
self.parser.add_argument('-d', '--test-results-dir', dest='logdir',
self.parser.add_argument('-d', '--test-results-dir', dest='base_logdir',
default=None, metavar='TEST_RESULTS_DIR',
help="use an alternative test results "
"directory")
......
......@@ -178,20 +178,19 @@ class Replay(CLI):
LOG_UI.error(err)
sys.exit(exit_codes.AVOCADO_FAIL)
if getattr(args, 'logdir', None) is not None:
logdir = args.logdir
else:
logdir = settings.get_value(section='datadir.paths',
key='logs_dir', key_type='path',
default=None)
base_logdir = getattr(args, 'base_logdir', None)
if base_logdir is None:
base_logdir = settings.get_value(section='datadir.paths',
key='logs_dir', key_type='path',
default=None)
try:
resultsdir = jobdata.get_resultsdir(logdir, args.replay_jobid)
resultsdir = jobdata.get_resultsdir(base_logdir, args.replay_jobid)
except ValueError as exception:
LOG_UI.error(exception.message)
sys.exit(exit_codes.AVOCADO_FAIL)
if resultsdir is None:
LOG_UI.error("Can't find job results directory in '%s'", logdir)
LOG_UI.error("Can't find job results directory in '%s'", base_logdir)
sys.exit(exit_codes.AVOCADO_FAIL)
sourcejob = jobdata.get_id(os.path.join(resultsdir, 'id'),
......
......@@ -65,7 +65,7 @@ class Run(CLICmd):
'unless you know exactly what you\'re doing')
parser.add_argument('--job-results-dir', action='store',
dest='logdir', default=None, metavar='DIRECTORY',
dest='base_logdir', default=None, metavar='DIRECTORY',
help=('Forces to use of an alternate job '
'results directory.'))
......
......@@ -29,22 +29,22 @@ class JobTest(unittest.TestCase):
return found
def test_job_empty_suite(self):
args = argparse.Namespace(logdir=self.tmpdir)
args = argparse.Namespace(base_logdir=self.tmpdir)
empty_job = job.Job(args)
self.assertIsNone(empty_job.test_suite)
def test_job_empty_has_id(self):
args = argparse.Namespace(logdir=self.tmpdir)
args = argparse.Namespace(base_logdir=self.tmpdir)
empty_job = job.Job(args)
self.assertIsNotNone(empty_job.unique_id)
def test_job_test_suite_not_created(self):
args = argparse.Namespace(logdir=self.tmpdir)
args = argparse.Namespace(base_logdir=self.tmpdir)
myjob = job.Job(args)
self.assertIsNone(myjob.test_suite)
def test_job_create_test_suite_empty(self):
args = argparse.Namespace(logdir=self.tmpdir)
args = argparse.Namespace(base_logdir=self.tmpdir)
myjob = job.Job(args)
self.assertRaises(exceptions.OptionValidationError,
myjob.create_test_suite)
......@@ -52,7 +52,7 @@ class JobTest(unittest.TestCase):
def test_job_create_test_suite_simple(self):
simple_tests_found = self._find_simple_test_candidates()
args = argparse.Namespace(reference=simple_tests_found,
logdir=self.tmpdir)
base_logdir=self.tmpdir)
myjob = job.Job(args)
myjob.create_test_suite()
self.assertEqual(len(simple_tests_found), len(myjob.test_suite))
......@@ -69,7 +69,7 @@ class JobTest(unittest.TestCase):
super(JobFilterTime, self).pre_tests()
simple_tests_found = self._find_simple_test_candidates()
args = argparse.Namespace(reference=simple_tests_found,
logdir=self.tmpdir)
base_logdir=self.tmpdir)
myjob = JobFilterTime(args)
myjob.create_test_suite()
try:
......@@ -81,7 +81,7 @@ class JobTest(unittest.TestCase):
def test_job_run_tests(self):
simple_tests_found = self._find_simple_test_candidates(['true'])
args = argparse.Namespace(reference=simple_tests_found,
logdir=self.tmpdir)
base_logdir=self.tmpdir)
myjob = job.Job(args)
myjob.create_test_suite()
self.assertEqual(myjob.run_tests(),
......@@ -95,7 +95,7 @@ class JobTest(unittest.TestCase):
super(JobLogPost, self).post_tests()
simple_tests_found = self._find_simple_test_candidates()
args = argparse.Namespace(reference=simple_tests_found,
logdir=self.tmpdir)
base_logdir=self.tmpdir)
myjob = JobLogPost(args)
myjob.create_test_suite()
try:
......@@ -123,7 +123,7 @@ class JobTest(unittest.TestCase):
super(JobFilterLog, self).post_tests()
simple_tests_found = self._find_simple_test_candidates()
args = argparse.Namespace(reference=simple_tests_found,
logdir=self.tmpdir)
base_logdir=self.tmpdir)
myjob = JobFilterLog(args)
self.assertEqual(myjob.run(),
exit_codes.AVOCADO_ALL_OK)
......@@ -132,7 +132,7 @@ class JobTest(unittest.TestCase):
open(os.path.join(myjob.logdir, "reversed_id")).read())
def test_job_run_account_time(self):
args = argparse.Namespace(logdir=self.tmpdir)
args = argparse.Namespace(base_logdir=self.tmpdir)
myjob = job.Job(args)
myjob.run()
self.assertNotEqual(myjob.time_start, -1)
......@@ -140,7 +140,7 @@ class JobTest(unittest.TestCase):
self.assertNotEqual(myjob.time_elapsed, -1)
def test_job_self_account_time(self):
args = argparse.Namespace(logdir=self.tmpdir)
args = argparse.Namespace(base_logdir=self.tmpdir)
myjob = job.Job(args)
myjob.time_start = 10.0
myjob.run()
......
......@@ -30,7 +30,7 @@ class JSONResultTest(unittest.TestCase):
self.tmpfile = tempfile.mkstemp()
self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__)
args = argparse.Namespace(json_output=self.tmpfile[1],
logdir=self.tmpdir)
base_logdir=self.tmpdir)
self.job = job.Job(args)
self.test_result = Result(FakeJob(args))
self.test_result.filename = self.tmpfile[1]
......
......@@ -39,7 +39,7 @@ class xUnitSucceedTest(unittest.TestCase):
self.tmpfile = tempfile.mkstemp()
self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__)
args = argparse.Namespace(logdir=self.tmpdir)
args = argparse.Namespace(base_logdir=self.tmpdir)
args.xunit_output = self.tmpfile[1]
self.job = job.Job(args)
self.test_result = Result(FakeJob(args))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册