Browse Source

Fix reporting ansible errors in buildlog

We had a mechanism that collects ansible errors like missing roles
that are catched early during parsing the playbook. However we had no
tests for this and this mechanism is now broken. The reason is that we
check if the first line of the syntax buffer containing the ansible
output is 'ERROR!'. However now this is the second line while the
first line tells us which ansible.cfg file it used.

To fix that just output the buffer starting with the first found line
that starts with 'ERROR!' and add a test case to it such it won't
break again.

Change-Id: Idf86bacf1117a3e95b69b45d6c70db9abb92cffc
Story: 2004289
Task: 27841
changes/06/616206/3
Tobias Henkel 3 years ago
parent
commit
5e9f77326c
No known key found for this signature in database GPG Key ID: 3750DEC158E5FA2
6 changed files with 42 additions and 6 deletions
  1. +3
    -0
      tests/fixtures/config/job-output/git/common-config/playbooks/job-output-missing-role.yaml
  2. +10
    -0
      tests/fixtures/config/job-output/git/common-config/zuul.yaml
  3. +1
    -0
      tests/fixtures/config/job-output/git/org_project3/README
  4. +1
    -0
      tests/fixtures/config/job-output/main.yaml
  5. +17
    -0
      tests/unit/test_v3.py
  6. +10
    -6
      zuul/executor/server.py

+ 3
- 0
tests/fixtures/config/job-output/git/common-config/playbooks/job-output-missing-role.yaml View File

@ -0,0 +1,3 @@
- hosts: all
roles:
- not_existing

+ 10
- 0
tests/fixtures/config/job-output/git/common-config/zuul.yaml View File

@ -26,6 +26,10 @@
run: playbooks/job-output.yaml
post-run: playbooks/job-output-failure-post.yaml
- job:
name: job-output-missing-role
run: playbooks/job-output-missing-role.yaml
- project:
name: org/project
check:
@ -37,3 +41,9 @@
check:
jobs:
- job-output-failure
- project:
name: org/project3
check:
jobs:
- job-output-missing-role

+ 1
- 0
tests/fixtures/config/job-output/git/org_project3/README View File

@ -0,0 +1 @@
test

+ 1
- 0
tests/fixtures/config/job-output/main.yaml View File

@ -7,3 +7,4 @@
untrusted-projects:
- org/project
- org/project2
- org/project3

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

@ -4073,6 +4073,23 @@ class TestJobOutput(AnsibleZuulTestCase):
self._get_file(self.history[0],
'work/logs/job-output.txt'))
def test_job_output_missing_role(self):
# Verify that ansible errors such as missing roles are part of the
# buildlog.
self.executor_server.keep_jobdir = True
A = self.fake_gerrit.addFakeChange('org/project3', 'master', 'A')
self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
self.waitUntilSettled()
self.assertHistory([
dict(name='job-output-missing-role', result='FAILURE',
changes='1,1'),
], ordered=False)
job_output = self._get_file(self.history[0],
'work/logs/job-output.txt')
self.assertIn('the role \'not_existing\' was not found', job_output)
def test_job_output_failure_log(self):
logger = logging.getLogger('zuul.AnsibleJob')
output = io.StringIO()


+ 10
- 6
zuul/executor/server.py View File

@ -1800,12 +1800,16 @@ class AnsibleJob(object):
# Received abort request.
return (self.RESULT_ABORTED, None)
elif ret == 1:
if syntax_buffer[0].startswith(b'ERROR!'):
with open(self.jobdir.job_output_file, 'a') as job_output:
for line in syntax_buffer:
job_output.write("{now} | {line}\n".format(
now=datetime.datetime.now(),
line=line.decode('utf-8').rstrip()))
with open(self.jobdir.job_output_file, 'a') as job_output:
found_marker = False
for line in syntax_buffer:
if line.startswith(b'ERROR!'):
found_marker = True
if not found_marker:
continue
job_output.write("{now} | {line}\n".format(
now=datetime.datetime.now(),
line=line.decode('utf-8').rstrip()))
elif ret == 4:
# Ansible could not parse the yaml.
self.log.debug("Ansible parse error")


Loading…
Cancel
Save