diff --git a/tests/fixtures/config/job-output/git/common-config/playbooks/job-output-missing-role.yaml b/tests/fixtures/config/job-output/git/common-config/playbooks/job-output-missing-role.yaml new file mode 100644 index 0000000000..24ac04c4fd --- /dev/null +++ b/tests/fixtures/config/job-output/git/common-config/playbooks/job-output-missing-role.yaml @@ -0,0 +1,3 @@ +- hosts: all + roles: + - not_existing diff --git a/tests/fixtures/config/job-output/git/common-config/zuul.yaml b/tests/fixtures/config/job-output/git/common-config/zuul.yaml index 9373038b32..5b44347b2e 100644 --- a/tests/fixtures/config/job-output/git/common-config/zuul.yaml +++ b/tests/fixtures/config/job-output/git/common-config/zuul.yaml @@ -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 diff --git a/tests/fixtures/config/job-output/git/org_project3/README b/tests/fixtures/config/job-output/git/org_project3/README new file mode 100644 index 0000000000..9daeafb986 --- /dev/null +++ b/tests/fixtures/config/job-output/git/org_project3/README @@ -0,0 +1 @@ +test diff --git a/tests/fixtures/config/job-output/main.yaml b/tests/fixtures/config/job-output/main.yaml index 14b382fe08..7eacee534d 100644 --- a/tests/fixtures/config/job-output/main.yaml +++ b/tests/fixtures/config/job-output/main.yaml @@ -7,3 +7,4 @@ untrusted-projects: - org/project - org/project2 + - org/project3 diff --git a/tests/unit/test_v3.py b/tests/unit/test_v3.py index 7da8ebc9c4..3622be446e 100644 --- a/tests/unit/test_v3.py +++ b/tests/unit/test_v3.py @@ -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() diff --git a/zuul/executor/server.py b/zuul/executor/server.py index 823b7ad9f7..8e243d6696 100644 --- a/zuul/executor/server.py +++ b/zuul/executor/server.py @@ -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")