Skip to content

Commit a50db4f

Browse files
committed
[roles/common] allow using a dict to configure pod tests
The pod tests are currently configured by setting a common_pod_list var that specifies the names of the pods. These pods must all be in the same namespace and share the same status_str and test_id. This means that the user needs to run the role multiple times in order to check a list of pods that are in different namespaces or have different status_str values. This change allow the configuration of the tests to either remain the same or to use a dictionary of values per pod, allowing to check for pods across multiple namespaces or with multiple statuses and run the role once.
1 parent 0912332 commit a50db4f

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

roles/common/tasks/pod_tests.yml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,42 @@
11
---
2+
- name: Convert the pod info into a dict
3+
ansible.builtin.set_fact:
4+
pod:
5+
name: "{{ item.name if \"name\" in item else item }}"
6+
nspace: "{{ item.nspace if \"nspace\" in item else common_pod_nspace }}"
7+
status_str: "{{ item.status_str if \"status_str\" in item else common_pod_status_str }}"
8+
test_id: "{{ item.test_id if \"test_id\" in item else common_pod_test_id | default(omit) }}"
9+
10+
- debug: var=pod
11+
212
- block:
313
# expects that one line will be returned
414
# todo: define what happens when there are multiple pods returned
5-
- name: Get Pod Instance name "{{ common_pod_status_str }}"
15+
- name: Get Pod Instance name "{{ pod.status_str }}"
616
ansible.builtin.shell:
717
cmd: |
8-
oc get pods -n "{{ common_pod_nspace }}" | grep "{{ item }}" | grep "{{ common_pod_status_str }}" | awk '{print $1;}'
18+
oc get pods -n "{{ pod.nspace }}" | grep "{{ pod.name }}" | grep "{{ pod.status_str }}" | awk '{print $1;}'
919
register: podinstance
1020
failed_when:
1121
- podinstance.stdout_lines | length != 1
1222
changed_when: false
1323

1424
- name: |
15-
TEST Check {{ item }} pod is {{ common_pod_status_str }} in {{ common_pod_nspace }} namespace
16-
{{ common_pod_test_id }}
25+
TEST Check {{ pod.name }} pod is {{ pod.status_str }} in {{ pod.nspace }} namespace
26+
{{ pod.test_id if pod.test_id is defined }}
1727
ansible.builtin.command:
1828
cmd: |
19-
oc get pod -n "{{ common_pod_nspace }}" "{{ podinstance.stdout }}"
29+
oc get pod -n "{{ pod.nspace }}" "{{ podinstance.stdout }}"
2030
register: output
2131
changed_when: false
2232
failed_when:
2333
- output.rc != 0
2434
- podinstance.stdout == ""
2535
rescue:
26-
- name: Get Pod Instance "{{ item }}"
36+
- name: Get Pod Instance "{{ pod.name }}"
2737
ansible.builtin.shell:
2838
cmd: |
29-
oc get pods -n "{{ common_pod_nspace }}" | grep "{{ item }}"
39+
oc get pods -n "{{ pod.nspace }}" | grep "{{ pod.name }}"
3040
register: podinstance
3141
failed_when:
3242
- podinstance.stdout_lines | length == 0

0 commit comments

Comments
 (0)