From 3487b54baf9e840b8834fc626f0ff2bd28f0ac51 Mon Sep 17 00:00:00 2001
From: Albin Vass <albin.vass@gmail.com>
Date: Mon, 27 Apr 2020 20:39:31 +0200
Subject: [PATCH] tox: Use 'block: ... always: ...' instead of ignore_errors

Change-Id: Ifc9f420687538a0ed666b41fa707810b184b0c66
---
 roles/tox/tasks/main.yaml | 71 ++++++++++++++++++---------------------
 1 file changed, 33 insertions(+), 38 deletions(-)

diff --git a/roles/tox/tasks/main.yaml b/roles/tox/tasks/main.yaml
index 9af1068f7..e14741ba0 100644
--- a/roles/tox/tasks/main.yaml
+++ b/roles/tox/tasks/main.yaml
@@ -38,43 +38,38 @@
       {% endif %}
       {{ tox_extra_args }}
 
-- name: Run tox
-  args:
-    chdir: "{{ zuul_work_dir }}"
-  environment: "{{ tox_environment|combine(tox_constraints_env|default({})) }}"
-  command: >-
-    {{ tox_executable }}
-    {% if tox_envlist is defined and tox_envlist %}
-    -e{{ tox_envlist }}
-    {% endif %}
-    {{ tox_extra_args }}
-  # Note: This intentionally ignores errors to give us the chance to look
-  # for file comments in the stdout. In case of an error this will be returned
-  # in a later task.
-  ignore_errors: yes
-  register: tox_output
+- block:
+    - name: Run tox
+      args:
+        chdir: "{{ zuul_work_dir }}"
+      environment: "{{ tox_environment|combine(tox_constraints_env|default({})) }}"
+      command: >-
+        {{ tox_executable }}
+        {% if tox_envlist is defined and tox_envlist %}
+        -e{{ tox_envlist }}
+        {% endif %}
+        {{ tox_extra_args }}
+      register: tox_output
 
-- name: Look for output
-  tox_parse_output:
-    tox_output: '{{ tox_output.stdout }}'
-    tox_envlist: '{{ tox_envlist }}'
-    workdir: '{{ zuul_work_dir }}'
-  when: tox_inline_comments
-  register: file_comments
-  ignore_errors: yes
+  # Even though any test environment in tox failed we want to
+  # return file comments produced so always run this.
+  always:
+    - name: Look for output
+      tox_parse_output:
+        tox_output: '{{ tox_output.stdout }}'
+        tox_envlist: '{{ tox_envlist }}'
+        workdir: '{{ zuul_work_dir }}'
+      when: tox_inline_comments
+      register: file_comments
+      failed_when: false
 
-- name: Return file comments to Zuul
-  when:
-    - file_comments
-    - file_comments.file_comments
-  delegate_to: localhost
-  zuul_return:
-    data:
-      zuul:
-        file_comments: '{{ file_comments.file_comments }}'
-  ignore_errors: yes
-
-- name: Return tox status
-  fail:
-    msg: 'tox exited with return code {{ tox_output.rc }}'
-  when: tox_output.rc != 0
+    - name: Return file comments to Zuul
+      when:
+        - tox_inline_comments
+        - file_comments.file_comments
+      delegate_to: localhost
+      zuul_return:
+        data:
+          zuul:
+            file_comments: '{{ file_comments.file_comments }}'
+      failed_when: false