Don't return POST_FAILURE when aborting post playbooks

Change-Id: I879eada078df7cfdce633318e4034cd0f788fb1b
This commit is contained in:
James E. Blair 2017-10-17 09:48:23 -07:00
parent 7a04df263c
commit bacbb888b6
9 changed files with 93 additions and 0 deletions

View 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

View File

@ -0,0 +1,2 @@
- hosts: all
tasks: []

View File

@ -0,0 +1,2 @@
- hosts: all
tasks: []

View 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'

View File

@ -0,0 +1,5 @@
- project:
name: org/project
check:
jobs:
- python27

View File

@ -0,0 +1 @@
test

View File

@ -0,0 +1,9 @@
- tenant:
name: tenant-one
source:
gerrit:
config-projects:
- common-config
untrusted-projects:
- org/project

View File

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

View File

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