summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2019-02-06 13:28:32 +0000
committerGerrit Code Review <review@openstack.org>2019-02-06 13:28:32 +0000
commit9019158139c433679d82e88de23c248206aab9e3 (patch)
tree3e88355a482890acbc58ae3428d1c11e02a5234a
parent1f4d658d15da0b7e26cf2bf86e25e4a7a6d3a71d (diff)
parent6e424878ae0669adb2b2950c4e0e06c9c46daaec (diff)
Merge "Fix error reporting for special task failures"
-rw-r--r--tests/fixtures/config/job-output/git/common-config/playbooks/job-output-missing-role-include.yaml4
-rw-r--r--tests/fixtures/config/job-output/git/common-config/zuul.yaml5
-rw-r--r--tests/unit/test_v3.py10
-rw-r--r--zuul/executor/server.py29
4 files changed, 37 insertions, 11 deletions
diff --git a/tests/fixtures/config/job-output/git/common-config/playbooks/job-output-missing-role-include.yaml b/tests/fixtures/config/job-output/git/common-config/playbooks/job-output-missing-role-include.yaml
new file mode 100644
index 0000000..e8e7f28
--- /dev/null
+++ b/tests/fixtures/config/job-output/git/common-config/playbooks/job-output-missing-role-include.yaml
@@ -0,0 +1,4 @@
1- hosts: all
2 tasks:
3 - include_role:
4 name: 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 5b44347..a0122a6 100644
--- a/tests/fixtures/config/job-output/git/common-config/zuul.yaml
+++ b/tests/fixtures/config/job-output/git/common-config/zuul.yaml
@@ -30,6 +30,10 @@
30 name: job-output-missing-role 30 name: job-output-missing-role
31 run: playbooks/job-output-missing-role.yaml 31 run: playbooks/job-output-missing-role.yaml
32 32
33- job:
34 name: job-output-missing-role-include
35 run: playbooks/job-output-missing-role-include.yaml
36
33- project: 37- project:
34 name: org/project 38 name: org/project
35 check: 39 check:
@@ -47,3 +51,4 @@
47 check: 51 check:
48 jobs: 52 jobs:
49 - job-output-missing-role 53 - job-output-missing-role
54 - job-output-missing-role-include
diff --git a/tests/unit/test_v3.py b/tests/unit/test_v3.py
index 4bfea02..9c62652 100644
--- a/tests/unit/test_v3.py
+++ b/tests/unit/test_v3.py
@@ -4431,11 +4431,15 @@ class TestJobOutput(AnsibleZuulTestCase):
4431 self.assertHistory([ 4431 self.assertHistory([
4432 dict(name='job-output-missing-role', result='FAILURE', 4432 dict(name='job-output-missing-role', result='FAILURE',
4433 changes='1,1'), 4433 changes='1,1'),
4434 dict(name='job-output-missing-role-include', result='FAILURE',
4435 changes='1,1'),
4434 ], ordered=False) 4436 ], ordered=False)
4435 4437
4436 job_output = self._get_file(self.history[0], 4438 for history in self.history:
4437 'work/logs/job-output.txt') 4439 job_output = self._get_file(history,
4438 self.assertIn('the role \'not_existing\' was not found', job_output) 4440 'work/logs/job-output.txt')
4441 self.assertIn('the role \'not_existing\' was not found',
4442 job_output)
4439 4443
4440 def test_job_output_failure_log(self): 4444 def test_job_output_failure_log(self):
4441 logger = logging.getLogger('zuul.AnsibleJob') 4445 logger = logging.getLogger('zuul.AnsibleJob')
diff --git a/zuul/executor/server.py b/zuul/executor/server.py
index b3b1a8d..d8a7bd9 100644
--- a/zuul/executor/server.py
+++ b/zuul/executor/server.py
@@ -1960,14 +1960,27 @@ class AnsibleJob(object):
1960 now=datetime.datetime.now(), 1960 now=datetime.datetime.now(),
1961 line=line.decode('utf-8').rstrip())) 1961 line=line.decode('utf-8').rstrip()))
1962 elif ret == 2: 1962 elif ret == 2:
1963 # This is a workaround to detect winrm connection failures that are 1963 with open(self.jobdir.job_output_file, 'a') as job_output:
1964 # not detected by ansible. These can be detected if the string 1964 found_marker = False
1965 # 'FATAL ERROR DURING FILE TRANSFER' is in the ansible output. 1965 for line in syntax_buffer:
1966 # In this case we should treat the host as unreachable and retry 1966 # This is a workaround to detect winrm connection failures
1967 # the job. 1967 # that are not detected by ansible. These can be detected
1968 for line in syntax_buffer: 1968 # if the string 'FATAL ERROR DURING FILE TRANSFER' is in
1969 if b'FATAL ERROR DURING FILE TRANSFER' in line: 1969 # the ansible output. In this case we should treat the
1970 return self.RESULT_UNREACHABLE, None 1970 # host as unreachable and retry the job.
1971 if b'FATAL ERROR DURING FILE TRANSFER' in line:
1972 return self.RESULT_UNREACHABLE, None
1973
1974 # Extract errors for special cases that are treated like
1975 # task errors by Ansible (e.g. missing role when using
1976 # 'include_role').
1977 if line.startswith(b'ERROR!'):
1978 found_marker = True
1979 if not found_marker:
1980 continue
1981 job_output.write("{now} | {line}\n".format(
1982 now=datetime.datetime.now(),
1983 line=line.decode('utf-8').rstrip()))
1971 1984
1972 return (self.RESULT_NORMAL, ret) 1985 return (self.RESULT_NORMAL, ret)
1973 1986