Skip to content

Commit f7026c8

Browse files
Harden verification OpenStack CLI calls to use JSON output
Replace fragile -f value/-c/csv+grep parsing in Priority A verification tasks with -f json and structured parsing so OSC formatter drift (e.g. Invalid formatter provided on floating ip show) no longer fails nightlies. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 54d97d5 commit f7026c8

5 files changed

Lines changed: 65 additions & 31 deletions

File tree

collection/stages/roles/verification/tasks/check_cinder_csi.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,20 @@
4343
- name: Get volume az for workers (if any)
4444
ansible.builtin.shell: |
4545
set -o pipefail
46-
openstack volume show $(openstack volume list -c ID -c Name -f value | grep "{{ item }}" | cut -d' ' -f2) -c availability_zone -f value
46+
vol_id=$(openstack volume list -f json | jq -r --arg w "{{ item }}" '
47+
[.[] | select((.Name // .name // "") | contains($w)) | (.ID // .id)] | first // empty
48+
')
49+
if [ -z "${vol_id}" ]; then
50+
exit 0
51+
fi
52+
openstack volume show "${vol_id}" -f json | jq -r '.availability_zone // empty'
4753
environment:
4854
OS_CLOUD: "{{ user_cloud }}"
4955
loop: "{{ worker_names }}"
5056
register: temporary_output
5157
failed_when: false
5258
changed_when: false
59+
when: edge_nova_az is not defined
5360

5461
- name: Convert output on a list
5562
ansible.builtin.set_fact:
@@ -97,8 +104,7 @@
97104
existing_pvc_ids: "{{ existing_pvcs | json_query('resources[].spec.volumeName') | list }}"
98105

99106
- name: Get cinder volumes for PVCs
100-
ansible.builtin.shell: |
101-
openstack volume show "{{ item }}" -c availability_zone -f value
107+
ansible.builtin.command: openstack volume show "{{ item }}" -f json
102108
environment:
103109
OS_CLOUD: "{{ user_cloud }}"
104110
loop: "{{ existing_pvc_ids }}"
@@ -107,7 +113,7 @@
107113

108114
- name: Convert output on a list
109115
ansible.builtin.set_fact:
110-
existing_pvc_azs: "{{ existing_pvc_azs + [item.stdout] }}"
116+
existing_pvc_azs: "{{ existing_pvc_azs + [(item.stdout | from_json).availability_zone] }}"
111117
loop: "{{ temporary_output.results | list }}"
112118

113119
- name: Check - expected cinder AZs on PVCs

collection/stages/roles/verification/tasks/check_lb_svc.yml

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -53,35 +53,36 @@
5353
- lb_ingress_ip is match(ipv4_regex)
5454
block:
5555
- name: Get the LB internal IP on openstack when the lb is using a FIP
56-
ansible.builtin.shell: |
57-
openstack floating ip show {{ lb_ingress_ip }} -c fixed_ip_address -f value
56+
ansible.builtin.command: openstack floating ip show {{ lb_ingress_ip }} -f json
5857
environment:
5958
OS_CLOUD: "{{ user_cloud }}"
60-
register: lb_internal_ip_output
59+
register: lb_fip_show
6160
changed_when: false
6261

6362
- name: Define the internal IP
6463
ansible.builtin.set_fact:
65-
lb_internal_ip: "{{ internal_lb | ternary(lb_ingress_ip, lb_internal_ip_output.stdout) }}"
64+
lb_internal_ip: "{{ internal_lb | ternary(lb_ingress_ip, (lb_fip_show.stdout | from_json).fixed_ip_address) }}"
6665

67-
- name: Get the Octavia provider type for the LB
68-
ansible.builtin.shell: |
69-
set -o pipefail
70-
openstack loadbalancer list -c vip_address -c provider -f value | grep {{ lb_internal_ip }} | awk '{print $2}'
66+
- name: List load balancers on OpenStack
67+
ansible.builtin.command: openstack loadbalancer list -f json
7168
environment:
7269
OS_CLOUD: "{{ user_cloud }}"
73-
register: svc_lb_type
70+
register: svc_lb_list
7471
changed_when: false
7572

73+
- name: Select the LB matching VIP "{{ lb_internal_ip }}"
74+
ansible.builtin.set_fact:
75+
svc_lb_matches: "{{ svc_lb_list.stdout | from_json | selectattr('vip_address', 'defined') | selectattr('vip_address', 'equalto', lb_internal_ip) | list }}"
76+
7677
- name: Check the LB exists with the internal IP (VIP address) "{{ lb_internal_ip }}"
7778
ansible.builtin.assert:
78-
that: svc_lb_type.stdout | length > 0
79+
that: svc_lb_matches | length > 0
7980
fail_msg: Could not find a LB in OSP with the vip_address "{{ lb_internal_ip }}"
8081
success_msg: A LB with the vip_address "{{ lb_internal_ip }}" has been found in OSP
8182

8283
- name: Detecte LB Octavia provider
8384
ansible.builtin.debug:
84-
msg: "Detected LB Octavia provider: {{ svc_lb_type.stdout }}"
85+
msg: "Detected LB Octavia provider: {{ svc_lb_matches[0].provider }}"
8586

8687
- name: Get pod names
8788
kubernetes.core.k8s_info:
@@ -142,27 +143,42 @@
142143
delay: 15
143144
until: oc_project.resources|length == 0
144145

145-
- name: Check the LB with "{{ lb_ingress_ip }}" ingress IP has been removed from OSP
146-
ansible.builtin.shell: |
147-
set -o pipefail
148-
openstack loadbalancer list -f value | grep {{ lb_ingress_ip }}
146+
- name: List load balancers after project deletion
147+
ansible.builtin.command: openstack loadbalancer list -f json
149148
environment:
150149
OS_CLOUD: "{{ user_cloud }}"
151-
register: svc_lb
152-
failed_when: svc_lb.rc == 0
150+
register: svc_lb_after
153151
changed_when: false
154152
when:
155153
- lb_internal_ip is defined
156154
- lb_internal_ip | length > 0
157155

158-
- name: Check the fip "{{ lb_ingress_ip }}" has been removed from OSP
159-
ansible.builtin.shell: |
160-
openstack floating ip show {{ lb_ingress_ip }} -f value
156+
- name: Check the LB with "{{ lb_ingress_ip }}" ingress IP has been removed from OSP
157+
ansible.builtin.assert:
158+
that:
159+
- (svc_lb_after.stdout | from_json | selectattr('vip_address', 'defined') | selectattr('vip_address', 'equalto', lb_ingress_ip) | list | length) == 0
160+
- (svc_lb_after.stdout | from_json | selectattr('vip_address', 'defined') | selectattr('vip_address', 'equalto', lb_internal_ip) | list | length) == 0
161+
fail_msg: Found a LB in OSP still associated with vip_address "{{ lb_ingress_ip }}" or "{{ lb_internal_ip }}"
162+
when:
163+
- lb_internal_ip is defined
164+
- lb_internal_ip | length > 0
165+
166+
- name: Check whether the fip "{{ lb_ingress_ip }}" still exists on OSP
167+
ansible.builtin.command: openstack floating ip show {{ lb_ingress_ip }} -f json
161168
environment:
162169
OS_CLOUD: "{{ user_cloud }}"
163170
register: fip
164-
failed_when: fip.rc == 0
171+
failed_when: false
165172
changed_when: false
166173
when:
167174
- lb_internal_ip is defined
168175
- lb_internal_ip | length > 0
176+
177+
- name: Check the fip "{{ lb_ingress_ip }}" has been removed from OSP
178+
ansible.builtin.assert:
179+
that:
180+
- fip.rc != 0
181+
fail_msg: FIP "{{ lb_ingress_ip }}" is still present in OSP
182+
when:
183+
- lb_internal_ip is defined
184+
- lb_internal_ip | length > 0

collection/stages/roles/verification/tasks/check_prometheus_pvcs.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@
3232
monitoring_pvc_ids: "{{ monitoring_pvcs | json_query('resources[].spec.volumeName') | list }}"
3333

3434
- name: Check cinder volume for PVC exist
35-
ansible.builtin.shell: |
36-
set -o pipefail
37-
openstack volume list -f csv | grep {{ item }}
35+
ansible.builtin.command: openstack volume show "{{ item }}" -f json
3836
environment:
3937
OS_CLOUD: "{{ user_cloud }}"
4038
changed_when: false

collection/stages/roles/verification/tasks/check_registry.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,14 @@
111111
- name: Get the images objects in swift for the {{ swift_check_ns }} namespace from the containers
112112
ansible.builtin.shell: |
113113
set -o pipefail
114-
openstack container list -c Name -f value | xargs -I% openstack object list % -c Name -f value | grep {{ swift_check_ns }}.{{ swift_check_image }}
114+
target="{{ swift_check_ns }}.{{ swift_check_image }}"
115+
openstack container list -f json \
116+
| jq -r '.[] | (.Name // .name // empty)' \
117+
| while read -r container; do
118+
[ -z "${container}" ] && continue
119+
openstack object list "${container}" -f json \
120+
| jq -r --arg t "${target}" '.[] | (.Name // .name // empty) | select(contains($t))'
121+
done
115122
environment:
116123
OS_CLOUD: "{{ user_cloud }}"
117124
register: image_registry_objects
@@ -123,7 +130,14 @@
123130
- name: List objects in case of failure from the containers
124131
ansible.builtin.shell: |
125132
set -o pipefail
126-
openstack container list -c Name -f value | xargs -I% openstack object list % -c Name -f value
133+
openstack container list -f json \
134+
| jq -r '.[] | (.Name // .name // empty)' \
135+
| while read -r container; do
136+
[ -z "${container}" ] && continue
137+
echo "=== container: ${container} ==="
138+
openstack object list "${container}" -f json \
139+
| jq -r '.[] | (.Name // .name // empty)'
140+
done
127141
environment:
128142
OS_CLOUD: "{{ user_cloud }}"
129143
changed_when: false

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
- not _skip_health # CSI is disabled post-adoption
120120

121121
- name: Check if manila is present on the OSP installation
122-
ansible.builtin.command: openstack catalog show manila -c name
122+
ansible.builtin.command: openstack catalog show manila -f json
123123
environment:
124124
OS_CLOUD: "{{ user_cloud }}"
125125
register: manila_enabled

0 commit comments

Comments
 (0)