Fix addFailTest
The addFailTest method needed to be updated to catch up with some
test infrastructure changes. Rather than consulting the merger's
git repo for the ZUUL_REF to find out if a job which is supposed to
fail is present for a given build, use the new FakeBuild.hasChanges
method to inspect the launcher's prepared git repo.
Also rename the method as 'Job' is more descriptive than 'Test' and
document it.
Change-Id: I3224b8a01d49cfa06b799a8028c1bf0d455d25b1
diff --git a/tests/base.py b/tests/base.py
index 1661957..9acc0ef 100755
--- a/tests/base.py
+++ b/tests/base.py
@@ -617,9 +617,7 @@
self.log.debug("Build %s continuing" % self.unique)
result = 'SUCCESS'
- if (('ZUUL_REF' in self.parameters) and
- self.launch_server.shouldFailTest(self.name,
- self.parameters['ZUUL_REF'])):
+ if (('ZUUL_REF' in self.parameters) and self.shouldFail()):
result = 'FAILURE'
if self.aborted:
result = 'ABORTED'
@@ -629,6 +627,13 @@
return result
+ def shouldFail(self):
+ changes = self.launch_server.fail_tests.get(self.name, [])
+ for change in changes:
+ if self.hasChanges(change):
+ return True
+ return False
+
def hasChanges(self, *changes):
"""Return whether this build has certain changes in its git repos.
@@ -680,24 +685,19 @@
self.fail_tests = {}
self.job_builds = {}
- def addFailTest(self, name, change):
+ def failJob(self, name, change):
"""Instruct the launcher to report matching builds as failures.
:arg str name: The name of the job to fail.
- :arg change: TODO: document
+ :arg Change change: The :py:class:`~tests.base.FakeChange`
+ instance which should cause the job to fail. This job
+ will also fail for changes depending on this change.
"""
l = self.fail_tests.get(name, [])
l.append(change)
self.fail_tests[name] = l
- def shouldFailTest(self, name, ref):
- l = self.fail_tests.get(name, [])
- for change in l:
- if self.test.ref_has_change(ref, change):
- return True
- return False
-
def release(self, regex=None):
"""Release a held build.
@@ -1264,6 +1264,8 @@
return commit.hexsha
def ref_has_change(self, ref, change):
+ # TODOv3(jeblair): this should probably be removed in favor of
+ # build.hasChanges
path = os.path.join(self.git_root, change.project)
repo = git.Repo(path)
try: