Skip to content

Commit e5dc0e7

Browse files
Fail ocp_testing when stage_unstable_flag is set after all stages
Test stages mark failures as UNSTABLE via stage_unstable_flag during rescue blocks but previously allowed the playbook to exit 0, so Zuul and ci-framework reported SUCCESS despite failing tests. Add fail_if_stage_unstable.yml and a final play in ocp_testing.yaml that reads accumulated messages and fails once all stages complete. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent dc76c06 commit e5dc0e7

4 files changed

Lines changed: 43 additions & 2 deletions

File tree

collection/stages/roles/verification/defaults/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cinder_csi_project_name: cinder-test # project for testing cinder-csi sc provide
55
manila_project_name: manila-test # project for testing manila sc provider
66
demo_project_name: demo # project for testing demo app
77
verify_existing_namespace: false
8-
soft_checks: true # run checks that won't stop the playbook but will generate the jenkins message to mark the run as unstable.
8+
soft_checks: true # run checks that won't stop the playbook but will mark the run as UNSTABLE via stage_unstable_flag.
99
alerts_to_ignore:
1010
# - 'Watchdog' # Should not be considered as severity is none
1111
- 'NodeClockNotSynchronising'
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
- name: Check whether any stage was marked UNSTABLE
3+
ansible.builtin.stat:
4+
path: "{{ stage_unstable_flag }}"
5+
register: _stage_unstable_flag
6+
7+
- name: Read accumulated UNSTABLE stage messages
8+
ansible.builtin.set_fact:
9+
_stage_unstable_messages: >-
10+
{{ lookup('ansible.builtin.file', stage_unstable_flag)
11+
| split('\n')
12+
| map('trim')
13+
| reject('equalto', '')
14+
| list
15+
| join('; ') }}
16+
when: _stage_unstable_flag.stat.exists
17+
18+
- name: Print accumulated UNSTABLE stage messages
19+
ansible.builtin.debug:
20+
msg: "{{ _stage_unstable_messages }}"
21+
when: _stage_unstable_flag.stat.exists
22+
23+
- name: Fail the playbook when any stage was marked UNSTABLE
24+
ansible.builtin.fail:
25+
msg: >-
26+
One or more stages were marked UNSTABLE:
27+
{{ _stage_unstable_messages }}
28+
when: _stage_unstable_flag.stat.exists

configs/global.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ report_dir: "{{ artifacts_dir }}/test_results"
3232

3333
# Sets the Ansible Controller Node machine's HOME environment variable
3434
controller_home_dir: "{{ lookup('ansible.builtin.env', 'HOME') }}"
35-
# The resources_file and stage_unstable_flag are in the Ansible control node's HOME environment variable
35+
# The resources_file and stage_unstable_flag are on the Ansible control node's HOME.
36+
# stage_unstable_flag accumulates UNSTABLE stage messages during the run; ocp_testing.yaml
37+
# fails at the end if the file exists so Zuul/ci-framework see a non-zero exit.
3638
resources_file: "{{ controller_home_dir }}/artifacts/resources.yml"
3739
stage_unstable_flag: "{{ controller_home_dir }}/artifacts/stage_unstable_flag"
3840

playbooks/ocp_testing.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,14 @@
119119
- name: Run EgressIP tests on OpenShift
120120
ansible.builtin.import_playbook: plays/egressip_tests.yaml
121121
when: "'egressip_tests' in stages"
122+
123+
- name: Fail if any stage was marked UNSTABLE
124+
hosts: localhost
125+
gather_facts: false
126+
vars_files:
127+
- "../configs/global.yml"
128+
tasks:
129+
- name: Check accumulated UNSTABLE stages and fail the playbook
130+
ansible.builtin.include_role:
131+
name: tools_stage_results
132+
tasks_from: fail_if_stage_unstable.yml

0 commit comments

Comments
 (0)