Skip to content

Commit b3ecf49

Browse files
committed
[shiftstack] Use GitHub for shiftstack-qa clone and fix false-positive test results
shiftstack-qa moved code review to GitHub PRs (shiftstack/ shiftstack-qa#2). The role default still clones from GerritHub, which is no longer maintained. - Change cifmw_shiftstack_qa_repo default to GitHub - Rename cifmw_shiftstack_qa_gerrithub_change to cifmw_shiftstack_qa_change_ref Also fix a false-positive bug in exec_command_in_pod.yml where oc rsh could return rc=0 before the inner command finished, causing the test to report PASS when the playbook actually failed. Observed in tp!2297 build d078ccbd - the shiftstack test ran for only 145s (vs typical 1.5-2h), OCP was never installed, yet the job reported SUCCESS. The fix writes the inner command exit code to a marker file on the pod, then verifies it in a separate oc exec call. This catches failures even if the first oc exec connection drops mid-execution. Also switches from oc rsh to oc exec for non-interactive pod commands. Default polling timeout set to 8h (5760 retries x 5s) to cover the full test suite duration, configurable via cifmw_shiftstack_exec_retries and cifmw_shiftstack_exec_delay. Related-Issue: #OSPRH-30385 Assisted-By: Claude Code Signed-off-by: Itay Matza <imatza@redhat.com>
1 parent f67ae9b commit b3ecf49

4 files changed

Lines changed: 97 additions & 13 deletions

File tree

roles/shiftstack/README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ Role for triggering Openshift on Openstack QA automation (installation and tests
1414
* `cifmw_shiftstack_client_pvc_manifest`: (*string*) The file name for the shiftstackclient pvc manifest. Defaults to `"{{ cifmw_shiftstack_client_pod_name }}_pvc.yml"`.
1515
* `cifmw_shiftstack_cluster_name`: (*string*) The Openshift cluster name. Defaults to `ostest`.
1616
* `cifmw_shiftstack_hypervisor`: (*string*) The hypervisor where RHOSO is deployed. Defaults to `"{{ hostvars[hostvars['controller-0']['cifmw_hypervisor_host'] | default ('')]['ansible_host'] | default('') }}"`.
17+
* `cifmw_shiftstack_exec_delay`: (*integer*) Seconds between polling attempts when waiting for a command to complete in the pod. Defaults to `5`.
18+
* `cifmw_shiftstack_exec_retries`: (*integer*) Maximum polling attempts when waiting for a command to complete in the pod. With the default delay of 5s, 5760 retries gives an 8-hour timeout. Defaults to `5760`.
1719
* `cifmw_shiftstack_exclude_artifacts_regex`: (*string*) Regex that will be passed on `oc rsync` command as `--exclude` param, so the role does not gather the artifacts matching it.
1820
* `cifmw_shiftstack_installation_dir`: (*string*) Directory to place installation files. Defaults to `"{{ cifmw_shiftstack_shiftstackclient_artifacts_dir }}/installation"`.
1921
* `cifmw_shiftstack_manifests_dir`: (*string*) Directory name for the role generated Openshift manifests. Defaults to `"{{ cifmw_shiftstack_basedir }}/manifests"`.
2022
* `cifmw_shiftstack_project_name`: (*string*) The Openstack project name. Defaults to `shiftstack`.
2123
* `cifmw_shiftstack_proxy`: (*string*) The proxy url that should be used to reach the underlying OCP. Defaults to omit.
22-
* `cifmw_shiftstack_qa_gerrithub_change`: (*string*) The gerrithub change to fetch from the `cifmw_shiftstack_qa_repo` repository (i.e. 'refs/changes/29/1188429/50)'. Defaults to ''.
23-
* `cifmw_shiftstack_qa_repo`: (*string*) The repository containing the Openshift on Openstack QA automation. Defaults to `https://review.gerrithub.io/shiftstack/shiftstack-qa`.
24+
* `cifmw_shiftstack_qa_change_ref`: (*string*) A git ref to fetch and checkout from the `cifmw_shiftstack_qa_repo` repository. Supports GitHub PR refs (e.g. `refs/pull/5/head`) and GerritHub change refs (e.g. `refs/changes/29/1188429/50`). Defaults to `''`.
25+
* `cifmw_shiftstack_qa_repo`: (*string*) The repository containing the Openshift on Openstack QA automation. Defaults to `https://github.com/shiftstack/shiftstack-qa`.
2426
* `cifmw_shiftstack_run_playbook`: (*string*) The playbook to be run from the `cifmw_shiftstack_qa_repo` repository. Defaults to `ocp_testing.yaml`.
2527
* `cifmw_shiftstack_sc`: (*string*) The storage class to be used for PVC for the shiftstackclient pod. Defaults to `local-storage`.
2628
* `cifmw_shiftstack_shiftstackclient_artifacts_dir`: (*string*) The artifacts directory path for the shiftstackclient pod. Defaults to `/home/cloud-admin/artifacts`.
@@ -40,7 +42,7 @@ cifmw_run_test_role: shiftstack
4042
cifmw_run_test_shiftstack_testconfig:
4143
- 4.17_ovnkubernetes_ipi.yaml
4244
- 4.17_ovnkubernetes_upi.yaml
43-
cifmw_shiftstack_qa_gerrithub_change: refs/changes/29/1188429/50 #optional
45+
cifmw_shiftstack_qa_change_ref: refs/pull/5/head #optional
4446
45-
$ ansible-playbook deploy-edpm.yml --extra-vars "cifmw_run_tests=true cifmw_run_test_role=shiftstack cifmw_test_operator_stages=[] cifmw_openshift_kubeconfig={{ ansible_user_dir }}/.kube/config cifmw_run_test_shiftstack_testconfig=4.15_ovnkubernetes_ipi_va1.yaml cifmw_shiftstack_qa_gerrithub_change=refs/changes/29/1188429/50"
47+
$ ansible-playbook deploy-edpm.yml --extra-vars "cifmw_run_tests=true cifmw_run_test_role=shiftstack cifmw_test_operator_stages=[] cifmw_openshift_kubeconfig={{ ansible_user_dir }}/.kube/config cifmw_run_test_shiftstack_testconfig=4.15_ovnkubernetes_ipi_va1.yaml cifmw_shiftstack_qa_change_ref=refs/pull/5/head"
4648
```

roles/shiftstack/defaults/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ cifmw_shiftstack_hypervisor: "{{ hostvars[hostvars['controller-0']['cifmw_hyperv
3333
cifmw_shiftstack_installation_dir: "{{ cifmw_shiftstack_basedir }}/installation"
3434
cifmw_shiftstack_manifests_dir: "{{ cifmw_shiftstack_basedir }}/manifests"
3535
cifmw_shiftstack_project_name: "shiftstack"
36-
cifmw_shiftstack_qa_gerrithub_change: ""
37-
cifmw_shiftstack_qa_repo: "https://review.gerrithub.io/shiftstack/shiftstack-qa"
36+
cifmw_shiftstack_qa_change_ref: ""
37+
cifmw_shiftstack_qa_repo: "https://github.com/shiftstack/shiftstack-qa"
3838
cifmw_shiftstack_run_playbook: "ocp_testing.yaml"
3939
cifmw_shiftstack_sc: "local-storage"
4040
cifmw_shiftstack_shiftstackclient_artifacts_dir: "/home/cloud-admin/artifacts"

roles/shiftstack/tasks/exec_command_in_pod.yml

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,101 @@
1414
# License for the specific language governing permissions and limitations
1515
# under the License.
1616

17+
- name: Kill any previous background command
18+
environment:
19+
PATH: "{{ cifmw_path }}"
20+
KUBECONFIG: "{{ cifmw_openshift_kubeconfig }}"
21+
ansible.builtin.command:
22+
cmd: >-
23+
oc exec -n {{ namespace }} {{ pod_name }} --
24+
bash -c 'if [ -f /tmp/cifmw_cmd_pid ]; then
25+
kill $(cat /tmp/cifmw_cmd_pid) 2>/dev/null; fi'
26+
changed_when: false
27+
failed_when: false
28+
29+
- name: Clear previous run markers
30+
environment:
31+
PATH: "{{ cifmw_path }}"
32+
KUBECONFIG: "{{ cifmw_openshift_kubeconfig }}"
33+
ansible.builtin.command:
34+
cmd: >-
35+
oc exec -n {{ namespace }} {{ pod_name }} --
36+
bash -c 'rm -f /tmp/cifmw_cmd_rc /tmp/cifmw_cmd_pid
37+
/tmp/cifmw_cmd_script.sh /tmp/cifmw_cmd_output.log'
38+
changed_when: false
39+
failed_when: false
40+
41+
- name: Write the command to a local script file
42+
ansible.builtin.copy:
43+
content: |
44+
#!/bin/bash
45+
{{ command }}
46+
dest: /tmp/cifmw_cmd_script.sh
47+
mode: "0755"
48+
49+
- name: Copy the script into the pod
50+
environment:
51+
PATH: "{{ cifmw_path }}"
52+
KUBECONFIG: "{{ cifmw_openshift_kubeconfig }}"
53+
ansible.builtin.shell:
54+
cmd: >-
55+
oc exec -i -n {{ namespace }} {{ pod_name }} --
56+
tee /tmp/cifmw_cmd_script.sh > /dev/null
57+
< /tmp/cifmw_cmd_script.sh
58+
changed_when: true
59+
60+
- name: Make the script executable in the pod
61+
environment:
62+
PATH: "{{ cifmw_path }}"
63+
KUBECONFIG: "{{ cifmw_openshift_kubeconfig }}"
64+
ansible.builtin.command:
65+
cmd: >-
66+
oc exec -n {{ namespace }} {{ pod_name }} --
67+
chmod +x /tmp/cifmw_cmd_script.sh
68+
1769
- name: Command execution block
1870
block:
1971
- name: Execute in the pod the command '{{ command }}'
2072
environment:
2173
PATH: "{{ cifmw_path }}"
2274
KUBECONFIG: "{{ cifmw_openshift_kubeconfig }}"
2375
ansible.builtin.command:
24-
cmd: "oc rsh -n {{ namespace }} {{ pod_name }} bash -c '{{ command }}'"
76+
cmd: >-
77+
oc exec -n {{ namespace }} {{ pod_name }} --
78+
bash -c 'nohup bash -c "/tmp/cifmw_cmd_script.sh; echo \$? > /tmp/cifmw_cmd_rc"
79+
> /tmp/cifmw_cmd_output.log 2>&1 &
80+
echo $! > /tmp/cifmw_cmd_pid && cat /tmp/cifmw_cmd_pid'
2581
register: pod_command_result
2682

83+
- name: Wait for the command to complete in the pod
84+
environment:
85+
PATH: "{{ cifmw_path }}"
86+
KUBECONFIG: "{{ cifmw_openshift_kubeconfig }}"
87+
ansible.builtin.command:
88+
cmd: >-
89+
oc exec -n {{ namespace }} {{ pod_name }} --
90+
bash -c 'cat /tmp/cifmw_cmd_rc'
91+
register: pod_exit_code
92+
changed_when: false
93+
until: pod_exit_code.rc == 0
94+
retries: "{{ cifmw_shiftstack_exec_retries | default(5760) }}"
95+
delay: "{{ cifmw_shiftstack_exec_delay | default(5) }}"
96+
97+
- name: Fail if the command failed inside the pod
98+
ansible.builtin.fail:
99+
msg: >-
100+
"{{ command }}" failed inside the pod with
101+
exit code {{ pod_exit_code.stdout | trim }}.
102+
when: (pod_exit_code.stdout | trim) != '0'
103+
27104
rescue:
28105
- name: Fail when the command module fails
29106
ansible.builtin.fail:
30-
msg: '"{{ command }}" command execution failed with exit code "{{ pod_command_result.rc }}" and error: "{{ pod_command_result.stderr }}".'
107+
msg: >-
108+
"{{ command }}" failed.
109+
oc exit code: {{ pod_command_result.rc | default('N/A') }},
110+
pod exit code: {{ pod_exit_code.stdout | default('N/A') | trim }},
111+
stderr: {{ pod_command_result.stderr | default('') }}{{ pod_exit_code.stderr | default('') }}.
31112
32113
always:
33114
- name: Command execution log saving block
@@ -45,6 +126,7 @@
45126
pod_name: "{{ pod_name }}"
46127
command: "{{ command }}"
47128
pod_command_result: "{{ pod_command_result }}"
129+
pod_exit_code: "{{ pod_exit_code | default('N/A') }}"
48130
ansible.builtin.copy:
49131
content: "{{ command_info | to_nice_yaml }}"
50132
dest: "{{ cifmw_shiftstack_ansible_command_logs_dir }}/{{ current_date.stdout }}.{{ log_file_name }}"

roles/shiftstack/tasks/test_shiftstack.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@
2323
log_file_name: "clone_shiftstack_qa_repo.log"
2424
ansible.builtin.include_tasks: exec_command_in_pod.yml
2525

26-
- name: Fetch the gerrithub change '{{ cifmw_shiftstack_qa_gerrithub_change }}'
26+
- name: Fetch the change ref '{{ cifmw_shiftstack_qa_change_ref }}'
2727
vars:
2828
namespace: "{{ cifmw_shiftstack_client_pod_namespace }}"
2929
pod_name: "{{ cifmw_shiftstack_client_pod_name }}"
3030
command: >-
3131
cd shiftstack-qa &&
32-
git fetch {{ cifmw_shiftstack_qa_repo }} {{ cifmw_shiftstack_qa_gerrithub_change }} &&
32+
git fetch {{ cifmw_shiftstack_qa_repo }} {{ cifmw_shiftstack_qa_change_ref }} &&
3333
git checkout FETCH_HEAD
34-
log_file_name: "fetch_shiftstack_qa_gerrithub_change.log"
34+
log_file_name: "fetch_shiftstack_qa_change_ref.log"
3535
when:
36-
- cifmw_shiftstack_qa_gerrithub_change is defined
37-
- cifmw_shiftstack_qa_gerrithub_change != ''
36+
- cifmw_shiftstack_qa_change_ref is defined
37+
- cifmw_shiftstack_qa_change_ref != ''
3838
ansible.builtin.include_tasks: exec_command_in_pod.yml
3939

4040
- name: Install the ansible collections

0 commit comments

Comments
 (0)