Merge "Also retry the job if a post job failed with unreachable"

This commit is contained in:
Zuul 2018-11-05 12:36:57 +00:00 committed by Gerrit Code Review
commit bf99aef9b7
3 changed files with 20 additions and 0 deletions

View File

@ -28,8 +28,16 @@
attempts: 2
run: playbooks/unreachable.yaml
- job:
name: post-unreachable
attempts: 2
run: playbooks/run.yaml
post-run:
- playbooks/unreachable.yaml
- project:
check:
jobs:
- pre-unreachable
- run-unreachable
- post-unreachable

View File

@ -4207,6 +4207,8 @@ class TestUnreachable(AnsibleZuulTestCase):
dict(name='pre-unreachable', result=None, changes='1,1'),
dict(name='run-unreachable', result=None, changes='1,1'),
dict(name='run-unreachable', result=None, changes='1,1'),
dict(name='post-unreachable', result=None, changes='1,1'),
dict(name='post-unreachable', result=None, changes='1,1'),
], ordered=False)
unreachable_log = self._get_file(self.history[0],
'.ansible/nodes.unreachable')

View File

@ -1137,6 +1137,7 @@ class AnsibleJob(object):
self.pause()
post_timeout = args['post_timeout']
unreachable = False
for index, playbook in enumerate(self.jobdir.post_playbooks):
# Post timeout operates a little differently to the main job
# timeout. We give each post playbook the full post timeout to
@ -1147,6 +1148,12 @@ class AnsibleJob(object):
playbook, post_timeout, success, phase='post', index=index)
if post_status == self.RESULT_ABORTED:
return 'ABORTED'
if post_status == self.RESULT_UNREACHABLE:
# In case we encounter unreachable nodes we need to return None
# so the job can be retried. However in the case of post
# playbooks we should still try to run all playbooks to get a
# chance to upload logs.
unreachable = True
if post_status != self.RESULT_NORMAL or post_code != 0:
success = False
# If we encountered a pre-failure, that takes
@ -1156,6 +1163,9 @@ class AnsibleJob(object):
if (index + 1) == len(self.jobdir.post_playbooks):
self._logFinalPlaybookError()
if unreachable:
return None
return result
def _logFinalPlaybookError(self):