Browse Source

Merge "Fix error reporting for special task failures"

Zuul 2 months ago
parent
commit
9019158139

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

@@ -0,0 +1,4 @@
1
+- hosts: all
2
+  tasks:
3
+    - include_role:
4
+        name: not_existing

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

@@ -30,6 +30,10 @@
30 30
     name: job-output-missing-role
31 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 37
 - project:
34 38
     name: org/project
35 39
     check:
@@ -47,3 +51,4 @@
47 51
     check:
48 52
       jobs:
49 53
         - job-output-missing-role
54
+        - job-output-missing-role-include

+ 7
- 3
tests/unit/test_v3.py View File

@@ -4431,11 +4431,15 @@ class TestJobOutput(AnsibleZuulTestCase):
4431 4431
         self.assertHistory([
4432 4432
             dict(name='job-output-missing-role', result='FAILURE',
4433 4433
                  changes='1,1'),
4434
+            dict(name='job-output-missing-role-include', result='FAILURE',
4435
+                 changes='1,1'),
4434 4436
         ], ordered=False)
4435 4437
 
4436
-        job_output = self._get_file(self.history[0],
4437
-                                    'work/logs/job-output.txt')
4438
-        self.assertIn('the role \'not_existing\' was not found', job_output)
4438
+        for history in self.history:
4439
+            job_output = self._get_file(history,
4440
+                                        'work/logs/job-output.txt')
4441
+            self.assertIn('the role \'not_existing\' was not found',
4442
+                          job_output)
4439 4443
 
4440 4444
     def test_job_output_failure_log(self):
4441 4445
         logger = logging.getLogger('zuul.AnsibleJob')

+ 21
- 8
zuul/executor/server.py View File

@@ -1960,14 +1960,27 @@ class AnsibleJob(object):
1960 1960
                         now=datetime.datetime.now(),
1961 1961
                         line=line.decode('utf-8').rstrip()))
1962 1962
         elif ret == 2:
1963
-            # This is a workaround to detect winrm connection failures that are
1964
-            # not detected by ansible. These can be detected if the string
1965
-            # 'FATAL ERROR DURING FILE TRANSFER' is in the ansible output.
1966
-            # In this case we should treat the host as unreachable and retry
1967
-            # the job.
1968
-            for line in syntax_buffer:
1969
-                if b'FATAL ERROR DURING FILE TRANSFER' in line:
1970
-                    return self.RESULT_UNREACHABLE, None
1963
+            with open(self.jobdir.job_output_file, 'a') as job_output:
1964
+                found_marker = False
1965
+                for line in syntax_buffer:
1966
+                    # This is a workaround to detect winrm connection failures
1967
+                    # that are not detected by ansible. These can be detected
1968
+                    # if the string 'FATAL ERROR DURING FILE TRANSFER' is in
1969
+                    # the ansible output. In this case we should treat the
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 1985
         return (self.RESULT_NORMAL, ret)
1973 1986
 

Loading…
Cancel
Save