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
This commit is contained in:
James E. Blair 2016-08-08 15:53:24 -07:00
parent 8b5408c6e9
commit a5dba23e77
3 changed files with 19 additions and 18 deletions

View File

@ -617,9 +617,7 @@ class FakeBuild(object):
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 @@ class FakeBuild(object):
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 @@ class RecordingLaunchServer(zuul.launcher.server.LaunchServer):
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 @@ class ZuulTestCase(BaseTestCase):
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:

View File

@ -53,7 +53,7 @@ class TestConnections(ZuulTestCase):
'jenkins')
B = self.fake_review_gerrit.addFakeChange('org/project', 'master', 'B')
self.worker.addFailTest('project-test2', B)
self.launch_server.failJob('project-test2', B)
self.addEvent('review_gerrit', B.getPatchsetCreatedEvent(1))
self.waitUntilSettled()

View File

@ -372,7 +372,6 @@ class Job(object):
file_matcher=None,
irrelevant_file_matcher=None, # skip-if
parameter_function=None, # TODOv3(jeblair): remove
success_pattern=None, # TODOv3(jeblair): remove
tags=set(),
mutex=None,
)
@ -873,13 +872,13 @@ class QueueItem(object):
if result == 'SUCCESS':
if job.success_message:
result = job.success_message
if job.success_pattern:
pattern = job.success_pattern
if job.success_url:
pattern = job.success_url
elif result == 'FAILURE':
if job.failure_message:
result = job.failure_message
if job.failure_pattern:
pattern = job.failure_pattern
if job.failure_url:
pattern = job.failure_url
url = None
if pattern:
try: