Fix bug that allowed failing jobs to pause

When a playbook requested a job pause in a playbook before a failing
task in the same playbook Zuul would happily do so.

With this fix the job can only be paused when the job is succeeding.

Change-Id: I939efb73c84abf051d300be3b642525d15a08e2d
This commit is contained in:
Simon Westphahl 2020-07-08 14:47:04 +02:00
parent 18026465d6
commit 4418547143
7 changed files with 51 additions and 1 deletions

View File

@ -0,0 +1 @@
test

View File

@ -0,0 +1,5 @@
- hosts: all
tasks:
- name: Good
debug:
msg: This shall not fail

View File

@ -0,0 +1,12 @@
- hosts: all
tasks:
- name: Pause and let child run
zuul_return:
data:
zuul:
pause: true
# Fail the playbook AFTER we have set zuul_return
- name: Fail
fail:
msg: This shall fail

View File

@ -0,0 +1,15 @@
- job:
name: compile-fail
run: playbooks/compile-fail.yaml
- job:
name: after-compile
run: playbooks/after-compile.yaml
- project:
check:
jobs:
- compile-fail
- after-compile:
dependencies:
- compile-fail

View File

@ -7,3 +7,4 @@
- org/project
- org/project2
- org/project3
- org/project4

View File

@ -5531,6 +5531,22 @@ class TestJobPause(AnsibleZuulTestCase):
dict(name='test2-after-compile1', result='SUCCESS', changes='1,1'),
], ordered=False)
def test_job_pause_fail(self):
"""
Test that only succeeding jobs are allowed to pause.
compile-fail
+--> after-compile
"""
A = self.fake_gerrit.addFakeChange('org/project4', 'master', 'A')
self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
self.waitUntilSettled()
self.assertHistory([
dict(name='compile-fail', result='FAILURE', changes='1,1'),
])
def test_job_node_failure_resume(self):
self.wait_timeout = 120

View File

@ -1418,7 +1418,7 @@ class AnsibleJob(object):
# check if we need to pause here
result_data = self.getResultData()
pause = result_data.get('zuul', {}).get('pause')
if pause:
if success and pause:
self.pause()
if self.aborted:
return 'ABORTED'