summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames E. Blair <jeblair@redhat.com>2017-10-17 09:48:23 -0700
committerJames E. Blair <jeblair@redhat.com>2017-10-17 10:01:11 -0700
commitbacbb888b6229c5862fa1d028fd3e618e611eb88 (patch)
treea8063779c2c8c73b50cb1bdd933884664bab92f8
parent7a04df263cf75b35e558cb11e08ab811192c944a (diff)
downloadzuul-bacbb888b6229c5862fa1d028fd3e618e611eb88.tar.gz
Don't return POST_FAILURE when aborting post playbooks
Change-Id: I879eada078df7cfdce633318e4034cd0f788fb1b
-rw-r--r--tests/fixtures/config/post-playbook/git/common-config/playbooks/post.yaml13
-rw-r--r--tests/fixtures/config/post-playbook/git/common-config/playbooks/pre.yaml2
-rw-r--r--tests/fixtures/config/post-playbook/git/common-config/playbooks/python27.yaml2
-rw-r--r--tests/fixtures/config/post-playbook/git/common-config/zuul.yaml24
-rw-r--r--tests/fixtures/config/post-playbook/git/org_project/.zuul.yaml5
-rw-r--r--tests/fixtures/config/post-playbook/git/org_project/README1
-rw-r--r--tests/fixtures/config/post-playbook/main.yaml9
-rwxr-xr-xtests/unit/test_v3.py35
-rw-r--r--zuul/executor/server.py2
9 files changed, 93 insertions, 0 deletions
diff --git a/tests/fixtures/config/post-playbook/git/common-config/playbooks/post.yaml b/tests/fixtures/config/post-playbook/git/common-config/playbooks/post.yaml
new file mode 100644
index 000000000..40b3ca732
--- /dev/null
+++ b/tests/fixtures/config/post-playbook/git/common-config/playbooks/post.yaml
@@ -0,0 +1,13 @@
+- hosts: all
+ tasks:
+ - debug: var=waitpath
+ - file:
+ path: "{{zuul._test.test_root}}/{{zuul.build}}.post_start.flag"
+ state: touch
+ # Do not finish until test creates the flag file
+ - wait_for:
+ state: present
+ path: "{{waitpath}}"
+ - file:
+ path: "{{zuul._test.test_root}}/{{zuul.build}}.post_end.flag"
+ state: touch
diff --git a/tests/fixtures/config/post-playbook/git/common-config/playbooks/pre.yaml b/tests/fixtures/config/post-playbook/git/common-config/playbooks/pre.yaml
new file mode 100644
index 000000000..f679dceae
--- /dev/null
+++ b/tests/fixtures/config/post-playbook/git/common-config/playbooks/pre.yaml
@@ -0,0 +1,2 @@
+- hosts: all
+ tasks: []
diff --git a/tests/fixtures/config/post-playbook/git/common-config/playbooks/python27.yaml b/tests/fixtures/config/post-playbook/git/common-config/playbooks/python27.yaml
new file mode 100644
index 000000000..f679dceae
--- /dev/null
+++ b/tests/fixtures/config/post-playbook/git/common-config/playbooks/python27.yaml
@@ -0,0 +1,2 @@
+- hosts: all
+ tasks: []
diff --git a/tests/fixtures/config/post-playbook/git/common-config/zuul.yaml b/tests/fixtures/config/post-playbook/git/common-config/zuul.yaml
new file mode 100644
index 000000000..92a551557
--- /dev/null
+++ b/tests/fixtures/config/post-playbook/git/common-config/zuul.yaml
@@ -0,0 +1,24 @@
+- pipeline:
+ name: check
+ manager: independent
+ post-review: true
+ trigger:
+ gerrit:
+ - event: patchset-created
+ success:
+ gerrit:
+ Verified: 1
+ failure:
+ gerrit:
+ Verified: -1
+
+- job:
+ name: base
+ parent: null
+
+- job:
+ name: python27
+ pre-run: playbooks/pre
+ post-run: playbooks/post
+ vars:
+ waitpath: '{{zuul._test.test_root}}/{{zuul.build}}/test_wait'
diff --git a/tests/fixtures/config/post-playbook/git/org_project/.zuul.yaml b/tests/fixtures/config/post-playbook/git/org_project/.zuul.yaml
new file mode 100644
index 000000000..89a567472
--- /dev/null
+++ b/tests/fixtures/config/post-playbook/git/org_project/.zuul.yaml
@@ -0,0 +1,5 @@
+- project:
+ name: org/project
+ check:
+ jobs:
+ - python27
diff --git a/tests/fixtures/config/post-playbook/git/org_project/README b/tests/fixtures/config/post-playbook/git/org_project/README
new file mode 100644
index 000000000..9daeafb98
--- /dev/null
+++ b/tests/fixtures/config/post-playbook/git/org_project/README
@@ -0,0 +1 @@
+test
diff --git a/tests/fixtures/config/post-playbook/main.yaml b/tests/fixtures/config/post-playbook/main.yaml
new file mode 100644
index 000000000..60338795d
--- /dev/null
+++ b/tests/fixtures/config/post-playbook/main.yaml
@@ -0,0 +1,9 @@
+- tenant:
+ name: tenant-one
+ source:
+ gerrit:
+ config-projects:
+ - common-config
+ untrusted-projects:
+ - org/project
+
diff --git a/tests/unit/test_v3.py b/tests/unit/test_v3.py
index bfb908873..b30d71065 100755
--- a/tests/unit/test_v3.py
+++ b/tests/unit/test_v3.py
@@ -20,6 +20,7 @@ import logging
import os
import textwrap
import gc
+import time
from unittest import skip
import testtools
@@ -1460,6 +1461,40 @@ class TestPrePlaybooks(AnsibleZuulTestCase):
"The file %s should exist" % post_flag_path)
+class TestPostPlaybooks(AnsibleZuulTestCase):
+ tenant_config_file = 'config/post-playbook/main.yaml'
+
+ def test_post_playbook_abort(self):
+ # Test that when we abort a job in the post playbook, that we
+ # don't send back POST_FAILURE.
+ self.executor_server.verbose = True
+ A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
+ self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
+
+ while not len(self.builds):
+ time.sleep(0.1)
+ build = self.builds[0]
+
+ post_start = os.path.join(self.test_root, build.uuid +
+ '.post_start.flag')
+ start = time.time()
+ while time.time() < start + 90:
+ if os.path.exists(post_start):
+ break
+ time.sleep(0.1)
+ # The post playbook has started, abort the job
+ self.fake_gerrit.addEvent(A.getChangeAbandonedEvent())
+ self.waitUntilSettled()
+
+ build = self.getJobFromHistory('python27')
+ self.assertEqual('ABORTED', build.result)
+
+ post_end = os.path.join(self.test_root, build.uuid +
+ '.post_end.flag')
+ self.assertTrue(os.path.exists(post_start))
+ self.assertFalse(os.path.exists(post_end))
+
+
class TestBrokenConfig(ZuulTestCase):
# Test that we get an appropriate syntax error if we start with a
# broken config.
diff --git a/zuul/executor/server.py b/zuul/executor/server.py
index 6af538c4d..e3f8a24e6 100644
--- a/zuul/executor/server.py
+++ b/zuul/executor/server.py
@@ -835,6 +835,8 @@ class AnsibleJob(object):
# TODOv3(pabelanger): Implement post-run timeout setting.
post_status, post_code = self.runAnsiblePlaybook(
playbook, args['timeout'], success, phase='post', index=index)
+ if post_status == self.RESULT_ABORTED:
+ return 'ABORTED'
if post_status != self.RESULT_NORMAL or post_code != 0:
success = False
# If we encountered a pre-failure, that takes