Browse Source

Merge "Pass zuul_success to cleanup playbooks"

tags/3.10.2
Zuul 5 months ago
parent
commit
c9227360e2
4 changed files with 13 additions and 8 deletions
  1. +2
    -2
      tests/base.py
  2. +3
    -3
      tests/fixtures/config/cleanup-playbook/git/common-config/playbooks/cleanup.yaml
  3. +4
    -0
      tests/unit/test_v3.py
  4. +4
    -3
      zuul/executor/server.py

+ 2
- 2
tests/base.py View File

@@ -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)


+ 3
- 3
tests/fixtures/config/cleanup-playbook/git/common-config/playbooks/cleanup.yaml View File

@@ -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"

+ 4
- 0
tests/unit/test_v3.py View File

@@ -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

+ 4
- 3
zuul/executor/server.py View File

@@ -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…
Cancel
Save