Pass zuul_success to cleanup playbooks
You might want to take action only if a job fails or succeeds. Change-Id: I45c1d3d22d3c49cd100552f6d4606b0c560fab10
This commit is contained in:
parent
533659fe0c
commit
2d8b45738d
|
@ -1874,8 +1874,8 @@ class RecordingAnsibleJob(zuul.executor.server.AnsibleJob):
|
|||
self.recordResult(None)
|
||||
return self.result
|
||||
|
||||
def runCleanupPlaybooks(self):
|
||||
super(RecordingAnsibleJob, self).runCleanupPlaybooks()
|
||||
def runCleanupPlaybooks(self, success):
|
||||
super(RecordingAnsibleJob, self).runCleanupPlaybooks(success)
|
||||
if self.result is not None:
|
||||
self.recordResult(self.result)
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
- hosts: all
|
||||
tasks:
|
||||
- file:
|
||||
path: "{{zuul._test.test_root}}/{{zuul.build}}.cleanup.flag"
|
||||
state: touch
|
||||
- copy:
|
||||
content: "{{ zuul_success }}"
|
||||
dest: "{{ zuul._test.test_root }}/{{ zuul.build }}.cleanup.flag"
|
||||
|
|
|
@ -2925,6 +2925,8 @@ class TestCleanupPlaybooks(AnsibleZuulTestCase):
|
|||
cleanup_flag = os.path.join(self.test_root, build.uuid +
|
||||
'.cleanup.flag')
|
||||
self.assertTrue(os.path.exists(cleanup_flag))
|
||||
with open(cleanup_flag) as f:
|
||||
self.assertEqual('True', f.readline())
|
||||
|
||||
def test_cleanup_playbook_failure(self):
|
||||
# Test that the cleanup run is performed
|
||||
|
@ -2950,6 +2952,8 @@ class TestCleanupPlaybooks(AnsibleZuulTestCase):
|
|||
cleanup_flag = os.path.join(self.test_root, build.uuid +
|
||||
'.cleanup.flag')
|
||||
self.assertTrue(os.path.exists(cleanup_flag))
|
||||
with open(cleanup_flag) as f:
|
||||
self.assertEqual('False', f.readline())
|
||||
|
||||
def test_cleanup_playbook_abort(self):
|
||||
# Test that when we abort a job the cleanup run is performed
|
||||
|
|
|
@ -998,8 +998,9 @@ class AnsibleJob(object):
|
|||
self.job.sendWorkStatus(0, 100)
|
||||
|
||||
result = self.runPlaybooks(args)
|
||||
success = result == 'SUCCESS'
|
||||
|
||||
self.runCleanupPlaybooks()
|
||||
self.runCleanupPlaybooks(success)
|
||||
|
||||
# Stop the persistent SSH connections.
|
||||
setup_status, setup_code = self.runAnsibleCleanup(
|
||||
|
@ -1294,7 +1295,7 @@ class AnsibleJob(object):
|
|||
|
||||
return result
|
||||
|
||||
def runCleanupPlaybooks(self):
|
||||
def runCleanupPlaybooks(self, success):
|
||||
if not self.jobdir.cleanup_playbooks:
|
||||
return
|
||||
|
||||
|
@ -1310,7 +1311,7 @@ class AnsibleJob(object):
|
|||
for index, playbook in enumerate(self.jobdir.cleanup_playbooks):
|
||||
self.runAnsiblePlaybook(
|
||||
playbook, cleanup_timeout, self.ansible_version,
|
||||
phase='cleanup', index=index)
|
||||
success=success, phase='cleanup', index=index)
|
||||
|
||||
def _logFinalPlaybookError(self):
|
||||
# Failures in the final post playbook can include failures
|
||||
|
|
Loading…
Reference in New Issue