提交 31063ac6 编写于 作者: C Cleber Rosa

Add relationship between a test and the job it's being run on.

It's very useful for a given test to be able to get information
on the job it's running. For instance, if we want to notify
a server that a test has failed, the unique identification of
the failed test will be its tag together with the unique job id.
Signed-off-by: NCleber Rosa <crosa@redhat.com>
上级 cf114dab
......@@ -70,14 +70,17 @@ class Job(object):
if os.path.exists(path_attempt):
test_class = test.DropinTest
test_instance = test_class(path=path_attempt,
base_logdir=self.debugdir)
base_logdir=self.debugdir,
job=self)
else:
test_module_dir = os.path.join(self.test_dir, url)
f, p, d = imp.find_module(url, [test_module_dir])
test_module = imp.load_module(url, f, p, d)
f.close()
test_class = getattr(test_module, url)
test_instance = test_class(base_logdir=self.debugdir)
test_instance = test_class(name=url,
base_logdir=self.debugdir,
job=self)
return test_instance
def run_test(self, url):
......
......@@ -51,10 +51,15 @@ class Test(unittest.TestCase):
image files will be created and modified.
base_logdir:
Base log directory, where logs from all tests go to.
tag:
A name that can differentiate between 2 executions of the same test
name.
job:
The job that this test is part of.
"""
def __init__(self, methodName='runTest', name=None, base_logdir=None,
tag=None):
tag=None, job=None):
"""
Initializes the test.
......@@ -69,6 +74,7 @@ class Test(unittest.TestCase):
:param tag: Tag that differentiates 2 executions of the same test name.
Example: 'long', 'short', so we can differentiate
'sleeptest.long' and 'sleeptest.short'.
:param job: The job that this test is part of.
"""
if name is not None:
self.name = name
......@@ -76,6 +82,7 @@ class Test(unittest.TestCase):
self.name = self.__class__.__name__
self.tag = tag
self.job = job
self.basedir = os.path.join(data_dir.get_test_dir(), self.name)
self.depsdir = os.path.join(self.basedir, 'deps')
self.workdir = os.path.join(data_dir.get_tmp_dir(), self.name)
......@@ -278,12 +285,12 @@ class DropinTest(Test):
Run an arbitrary command that returns either 0 (PASS) or !=0 (FAIL).
"""
def __init__(self, path, base_logdir, tag=None):
def __init__(self, path, base_logdir, tag=None, job=None):
basename = os.path.basename(path)
name = basename.split(".")[0]
self.path = os.path.abspath(path)
super(DropinTest, self).__init__(name=name, base_logdir=base_logdir,
tag=tag)
tag=tag, job=job)
def _log_detailed_cmd_info(self, result):
"""
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册