Skip to content

Commit bbd0dac

Browse files
committed
adds new test for bad dataset for CICS version parsing
Signed-off-by: Kye Maloy <[email protected]>
1 parent 39f2117 commit bbd0dac

File tree

4 files changed

+159
-4
lines changed

4 files changed

+159
-4
lines changed

plugins/module_utils/cicsgetversion.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@
1515

1616
def get_dataset_member_version_record(dataset): # type: (str) -> str
1717
try:
18-
records = Datasets.read("%s.SDFHSAMP(DFH0SINX)" % dataset)
19-
return records.split("STATUS = ", 1)[1].split(" ")[0]
18+
result = Datasets.read("%s.SDFHSAMP(DFH0SINX)" % dataset).split("STATUS = ", 1)[1].split(" ")[0]
19+
if not result or result == "":
20+
raise Exception("CICS version was blank")
21+
elif len(result) >= 10:
22+
raise Exception("CICS version was too long")
23+
else:
24+
return result
2025
except ZOAUExceptions.ZOAUException:
2126
raise Exception("Error reading dataset for calculating CICS version.")

tests/integration/targets/cics_utilities/playbooks/cics_get_version.yml

Lines changed: 144 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
- name: CICS Version Integration Test
55
hosts: "all"
66
gather_facts: false
7+
vars:
8+
username: "{{ cmci_user }}"
9+
uniquename: "{{ uniquename }}"
710

811
tasks:
912
############################################################################
10-
# Get CICS version for development version
13+
# Get CICS version for dev version
1114
############################################################################
1215
- name: Retrieve CICS version information
1316
environment: "{{ environment_vars }}"
@@ -90,3 +93,143 @@
9093
- result is not changed
9194
- result.rc != 0
9295
- "'exception' in result"
96+
97+
############################################################################
98+
# Create a empty dataset and try to read non-existent status
99+
############################################################################
100+
- name: Create empty PDS dataset
101+
environment: "{{ environment_vars }}"
102+
ibm.ibm_zos_core.zos_data_set:
103+
batch:
104+
- name: "{{ username }}.{{ uniquename }}.SDFHSAMP"
105+
type: PDS
106+
- name: "{{ username }}.{{ uniquename }}.SDFHSAMP(DFH0SINX)"
107+
type: MEMBER
108+
register: create_result
109+
110+
- name: Fail to get CICS version information from empty dataset
111+
environment: "{{ environment_vars }}"
112+
cics_version:
113+
CICS_HLQ: "{{ username }}.{{ uniquename }}"
114+
register: result
115+
failed_when: false
116+
117+
- name: Assert 6
118+
ansible.builtin.assert:
119+
that:
120+
- result is not changed
121+
- result.rc != 0
122+
- "'exception' in result"
123+
124+
############################################################################
125+
# Create some data and read a non numeric STATUS value
126+
############################################################################
127+
128+
- name: Write data to the dataset to test for STATUS field
129+
environment: "{{ environment_vars }}"
130+
ansible.builtin.shell:
131+
args:
132+
executable: /rocket/bin/bash
133+
cmd: decho 'STATUS = TEST' "{{ username }}.{{ uniquename }}.SDFHSAMP(DFH0SINX)"
134+
135+
- name: Get CICS version from new dataset
136+
environment: "{{ environment_vars }}"
137+
cics_version:
138+
CICS_HLQ: "{{ username }}.{{ uniquename }}"
139+
register: result
140+
failed_when: false
141+
142+
- name: Assert 7
143+
ansible.builtin.assert:
144+
that:
145+
- result is not changed
146+
- result.cics_version == 'TEST'
147+
- result.rc == 0
148+
- "'exception' not in result"
149+
150+
############################################################################
151+
# Create and read from dataset where STATUS is EOF
152+
############################################################################
153+
154+
- name: Write data to the dataset to test for no data after STATUS
155+
environment: "{{ environment_vars }}"
156+
ansible.builtin.shell:
157+
args:
158+
executable: /rocket/bin/bash
159+
cmd: decho 'STATUS =' "{{ username }}.{{ uniquename }}.SDFHSAMP(DFH0SINX)"
160+
161+
- name: Attempt to read data from STATUS which is EOF
162+
environment: "{{ environment_vars }}"
163+
cics_version:
164+
CICS_HLQ: "{{ username }}.{{ uniquename }}"
165+
register: result
166+
failed_when: false
167+
168+
- name: Assert 8
169+
ansible.builtin.assert:
170+
that:
171+
- result is not changed
172+
- result.rc != 0
173+
- "'exception' in result"
174+
175+
############################################################################
176+
# Cleanup dataset
177+
############################################################################
178+
179+
- name: Delete member
180+
environment: "{{ environment_vars }}"
181+
ibm.ibm_zos_core.zos_data_set:
182+
name: "{{ username }}.{{ uniquename }}.SDFHSAMP(DFH0SINX)"
183+
state: absent
184+
type: MEMBER
185+
register: delete_member_result
186+
187+
- name: Delete dataset
188+
environment: "{{ environment_vars }}"
189+
ibm.ibm_zos_core.zos_data_set:
190+
name: "{{ username }}.{{ uniquename }}.SDFHSAMP"
191+
state: absent
192+
register: delete_result
193+
194+
195+
############################################################################
196+
# Create and read from a SEQ dataset
197+
############################################################################
198+
- name: Create empty SEQ dataset
199+
environment: "{{ environment_vars }}"
200+
ibm.ibm_zos_core.zos_data_set:
201+
batch:
202+
- name: "{{ username }}.{{ uniquename }}.SDFHSAMP"
203+
type: SEQ
204+
- name: "{{ username }}.{{ uniquename }}.SDFHSAMP(DFH0SINX)"
205+
type: MEMBER
206+
register: create_result
207+
208+
- name: Write data to SEQ dataset
209+
environment: "{{ environment_vars }}"
210+
ansible.builtin.shell:
211+
args:
212+
executable: /rocket/bin/bash
213+
cmd: decho 'STATUS = 1.0.0' "{{ username }}.{{ uniquename }}.SDFHSAMP(DFH0SINX)"
214+
215+
- name: Read version from SEQ dataset
216+
environment: "{{ environment_vars }}"
217+
cics_version:
218+
CICS_HLQ: "{{ username }}.{{ uniquename }}"
219+
register: result
220+
failed_when: false
221+
222+
- name: Assert 9
223+
ansible.builtin.assert:
224+
that:
225+
- result is not changed
226+
- result.cics_version == '1.0.0'
227+
- result.rc == 0
228+
- "'exception' not in result"
229+
230+
- name: Delete SEQ dataset
231+
environment: "{{ environment_vars }}"
232+
ibm.ibm_zos_core.zos_data_set:
233+
name: "{{ username }}.{{ uniquename }}.SDFHSAMP"
234+
state: absent
235+
register: delete_result

tests/integration/targets/cics_utilities/runme.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
# (c) Copyright IBM Corp. 2023
33
# Apache License, Version 2.0 (see https://opensource.org/licenses/Apache-2.0)
44
set -eux # This is important to ensure that return codes from failing tests are propagated
5-
ANSIBLE_LIBRARY=./library ansible-playbook -i zos_inventory playbooks/cics_get_version.yml
5+
6+
export ANSIBLE_COLLECTIONS_PATH=/root/.ansible/collections:$ANSIBLE_COLLECTIONS_PATH
7+
ANSIBLE_LIBRARY=./library ansible-playbook -e "@variables.yml" -i zos_inventory playbooks/cics_get_version.yml
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# (c) Copyright IBM Corp. 2023
2+
# Apache License, Version 2.0 (see https://opensource.org/licenses/Apache-2.0)
3+
---
4+
cmci_user: __user__
5+
uniquename: __uniquename__

0 commit comments

Comments
 (0)