Don't return POST_FAILURE when aborting post playbooks
Change-Id: I879eada078df7cfdce633318e4034cd0f788fb1b
This commit is contained in:
parent
7a04df263c
commit
bacbb888b6
13
tests/fixtures/config/post-playbook/git/common-config/playbooks/post.yaml
vendored
Normal file
13
tests/fixtures/config/post-playbook/git/common-config/playbooks/post.yaml
vendored
Normal file
@ -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
|
2
tests/fixtures/config/post-playbook/git/common-config/playbooks/pre.yaml
vendored
Normal file
2
tests/fixtures/config/post-playbook/git/common-config/playbooks/pre.yaml
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
- hosts: all
|
||||
tasks: []
|
2
tests/fixtures/config/post-playbook/git/common-config/playbooks/python27.yaml
vendored
Normal file
2
tests/fixtures/config/post-playbook/git/common-config/playbooks/python27.yaml
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
- hosts: all
|
||||
tasks: []
|
24
tests/fixtures/config/post-playbook/git/common-config/zuul.yaml
vendored
Normal file
24
tests/fixtures/config/post-playbook/git/common-config/zuul.yaml
vendored
Normal file
@ -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'
|
5
tests/fixtures/config/post-playbook/git/org_project/.zuul.yaml
vendored
Normal file
5
tests/fixtures/config/post-playbook/git/org_project/.zuul.yaml
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
- project:
|
||||
name: org/project
|
||||
check:
|
||||
jobs:
|
||||
- python27
|
1
tests/fixtures/config/post-playbook/git/org_project/README
vendored
Normal file
1
tests/fixtures/config/post-playbook/git/org_project/README
vendored
Normal file
@ -0,0 +1 @@
|
||||
test
|
9
tests/fixtures/config/post-playbook/main.yaml
vendored
Normal file
9
tests/fixtures/config/post-playbook/main.yaml
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
- tenant:
|
||||
name: tenant-one
|
||||
source:
|
||||
gerrit:
|
||||
config-projects:
|
||||
- common-config
|
||||
untrusted-projects:
|
||||
- org/project
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user