Skip to content

Commit 7ca704e

Browse files
committed
Add DFHCSDUP
1 parent e8db95d commit 7ca704e

File tree

14 files changed

+310
-151
lines changed

14 files changed

+310
-151
lines changed

plugins/module_utils/csd.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,60 @@
66
from __future__ import (absolute_import, division, print_function)
77
__metaclass__ = type
88

9+
from ansible_collections.ibm.ibm_zos_core.plugins.module_utils.dd_statement import StdinDefinition, DatasetDefinition, DDStatement, StdoutDefinition
10+
from ansible_collections.ibm.ibm_zos_core.plugins.module_utils.zos_mvs_raw import MVSCmd, MVSCmdResponse
11+
from ansible_collections.ibm.ibm_zos_cics.plugins.module_utils.response import _execution
912
from ansible_collections.ibm.ibm_zos_cics.plugins.module_utils.data_set import _dataset_constants as ds_constants
1013

1114

15+
def _get_csdup_dds(catalog): # type: (dict) -> dict
16+
return [
17+
DDStatement('steplib', DatasetDefinition(catalog["sdfhload"], disposition="SHR")),
18+
DDStatement(
19+
'dfhcsd',
20+
DatasetDefinition(
21+
dataset_name=catalog["name"],
22+
disposition="SHR")),
23+
DDStatement('sysprint', StdoutDefinition()),
24+
DDStatement('sysudump', StdoutDefinition()),
25+
DDStatement('sysin', StdinDefinition(content=_get_csdupcmd())),
26+
]
27+
28+
29+
def _run_dfhcsdup(starting_catalog): # type: (dict) -> [_execution]
30+
executions = []
31+
dfhcsdup_response = _execute_dfhcsdup(starting_catalog)
32+
33+
executions.append(_execution(
34+
name="DFHCSDUP - Initialise CSD",
35+
rc=dfhcsdup_response.rc,
36+
stdout=dfhcsdup_response.stdout,
37+
stderr=dfhcsdup_response.stderr))
38+
39+
if dfhcsdup_response.rc != 0:
40+
raise Exception(
41+
"DFHCSDUP failed with RC {0}".format(
42+
dfhcsdup_response.rc
43+
), executions
44+
)
45+
return executions
46+
47+
48+
def _execute_dfhcsdup(starting_catalog): # type: (dict) -> MVSCmdResponse
49+
return MVSCmd.execute(
50+
pgm="DFHCSDUP",
51+
dds=_get_csdup_dds(catalog=starting_catalog),
52+
verbose=True,
53+
debug=False)
54+
55+
56+
def _get_csdupcmd(): # type () -> dict
57+
cmd = [
58+
"INITIALIZE"
59+
]
60+
return cmd
61+
62+
1263
def _get_idcams_cmd_csd(dataset): # type: (dict) -> dict
1364
defaults = {
1465
"CLUSTER": {

plugins/modules/csd.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,7 @@
203203
_dataset_size, _data_set, _build_idcams_define_cmd)
204204
from ansible_collections.ibm.ibm_zos_cics.plugins.module_utils.data_set import DataSet
205205
from ansible_collections.ibm.ibm_zos_cics.plugins.module_utils.csd import (
206-
_get_idcams_cmd_csd)
207-
from ansible_collections.ibm.ibm_zos_cics.plugins.module_utils.icetool import (_run_icetool)
206+
_run_dfhcsdup, _get_idcams_cmd_csd)
208207
from ansible_collections.ibm.ibm_zos_cics.plugins.module_utils.csd import _csd_constants as csd_constants
209208
from ansible_collections.ibm.ibm_zos_cics.plugins.module_utils.data_set import _dataset_constants as ds_constants
210209

@@ -348,6 +347,13 @@ def create_data_set(self): # type: () -> None
348347

349348
super().build_vsam_data_set(create_cmd, "Create CSD data set")
350349

350+
try:
351+
csdup_executions = _run_dfhcsdup(self.data_set)
352+
self.result["executions"] = self.result["executions"] + csdup_executions
353+
except Exception as e:
354+
self.result["executions"] = self.result["executions"] + e.args[1]
355+
self._fail(e.args[0])
356+
351357
def delete_data_set(self): # type: () -> None
352358
if not self.data_set["exists"]:
353359
self.result["end_state"] = {
@@ -361,26 +367,14 @@ def delete_data_set(self): # type: () -> None
361367
def warm_data_set(self): # type: () -> None
362368
super().warm_data_set()
363369

364-
try:
365-
icetool_executions, record_count = _run_icetool(self.data_set["name"])
366-
if record_count["record_count"] <= 0:
367-
self._fail("Unused data set. The data set must be used by CICS before doing a warm start.")
368-
369-
self.result["executions"] = self.result["executions"] + icetool_executions
370-
self.result["changed"] = False
371-
except Exception as e:
372-
self.result["executions"] = self.result["executions"] + e.args[1]
373-
self._fail(e.args[0])
374-
375370
def init_data_set(self): # type: () -> None
376371
if self.data_set["exists"]:
377372
self.result["end_state"] = {
378373
"exists": self.data_set["exists"],
379374
"vsam": self.data_set["vsam"]
380375
}
381376
self._exit()
382-
383-
if not self.data_set["exists"]:
377+
else:
384378
self.create_data_set()
385379

386380

tests/integration/targets/cics_csd/playbooks/absent_catalog.yml renamed to tests/integration/targets/cics_csd/playbooks/absent_csd.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# (c) Copyright IBM Corp. 2023
22
# Apache License, Version 2.0 (see https://opensource.org/licenses/Apache-2.0)
33
---
4-
- name: Absent Catalog
4+
- name: Absent CSD
55

66
hosts: "all"
77
gather_facts: false
88
vars:
99
region_dataset_path: "ANSIBIT.CICS.TESTS.{{ cics_test_area_absent }}"
10-
catalog_name: "DFHCSD"
11-
catalog_path: "{{ region_dataset_path }}.{{ catalog_name }}"
10+
ds_name: "DFHCSD"
11+
ds_path: "{{ region_dataset_path }}.{{ ds_name }}"
1212

1313
module_defaults:
1414
ibm.ibm_zos_cics.csd:
@@ -27,7 +27,7 @@
2727
- name: Delete CSD Data Set if it exists
2828
environment: "{{ environment_vars }}"
2929
ibm.ibm_zos_core.zos_data_set:
30-
name: "{{ catalog_path }}"
30+
name: "{{ ds_path }}"
3131
state: absent
3232
register: delete_result
3333
retries: 3
@@ -93,7 +93,7 @@
9393
- name: Delete CSD Data Set
9494
environment: "{{ environment_vars }}"
9595
ibm.ibm_zos_core.zos_data_set:
96-
name: "{{ catalog_path }}"
96+
name: "{{ ds_path }}"
9797
state: absent
9898
register: delete_result
9999
retries: 3

tests/integration/targets/cics_csd/playbooks/check_bad_csd_location.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
gather_facts: false
88
vars:
99
region_dataset_path: "ANSIBIT.CICS.TESTS.{{ cics_test_area_initial }}"
10-
catalog_name: "DFHCSD"
11-
catalog_path: "{{ region_dataset_path }}.{{ catalog_name }}"
10+
ds_name: "DFHCSD"
11+
ds_path: "{{ region_dataset_path }}.{{ ds_name }}"
1212

1313
tasks:
1414
# #############################################################################

tests/integration/targets/cics_csd/playbooks/check_lowercase_location.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
gather_facts: false
88
vars:
99
region_dataset_path: "ANSIBIT.TESTS.{{ cics_test_area_initial }}"
10-
catalog_name: "DFHCSD"
10+
ds_name: "DFHCSD"
1111

1212
tasks:
1313
# #############################################################################
1414
# ############################## Initial cleanup ##############################
1515
# #############################################################################
1616

17-
- name: Delete Catalog Data Set if it exists
17+
- name: Delete CSD Data Set if it exists
1818
environment: "{{ environment_vars }}"
1919
ibm.ibm_zos_core.zos_data_set:
20-
name: "{{ region_dataset_path }}.LOW.{{ catalog_name }}"
20+
name: "{{ region_dataset_path }}.LOW.{{ ds_name }}"
2121
state: absent
2222
register: delete_result
2323
retries: 3
@@ -37,7 +37,7 @@
3737
ibm.ibm_zos_cics.csd:
3838
region_data_sets:
3939
dfhcsd:
40-
dsn: "{{ region_dataset_path }}.low.{{ catalog_name }}"
40+
dsn: "{{ region_dataset_path }}.low.{{ ds_name }}"
4141
cics_data_sets:
4242
sdfhload: "{{ cics_steplib }}"
4343
space_primary: 5
@@ -66,10 +66,10 @@
6666
# ################################## Cleanup ##################################
6767
# #############################################################################
6868

69-
- name: Delete Catalog Data Set
69+
- name: Delete CSD Data Set
7070
environment: "{{ environment_vars }}"
7171
ibm.ibm_zos_core.zos_data_set:
72-
name: "{{ region_dataset_path }}.LOW.{{ catalog_name }}"
72+
name: "{{ region_dataset_path }}.LOW.{{ ds_name }}"
7373
state: absent
7474
register: delete_result
7575
retries: 3
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# (c) Copyright IBM Corp. 2023
2+
# Apache License, Version 2.0 (see https://opensource.org/licenses/Apache-2.0)
3+
---
4+
- name: Warm CSD when CSD doesn't exist
5+
6+
hosts: "all"
7+
gather_facts: false
8+
vars:
9+
region_dataset_path: "ANSIBIT.CICS.TESTS.{{ cics_test_area_absent }}"
10+
ds_name: "DFHCSD"
11+
ds_path: "{{ region_dataset_path }}.{{ ds_name }}"
12+
13+
module_defaults:
14+
ibm.ibm_zos_cics.csd:
15+
cics_data_sets:
16+
sdfhload: "{{ cics_steplib }}"
17+
space_primary: 5
18+
space_type: "M"
19+
region_data_sets:
20+
template: "{{ region_dataset_path }}.<< data_set_name >>"
21+
22+
tasks:
23+
# #############################################################################
24+
# ############################## Initial cleanup ##############################
25+
# #############################################################################
26+
27+
- name: Delete CSD Data Set if it exists
28+
environment: "{{ environment_vars }}"
29+
ibm.ibm_zos_core.zos_data_set:
30+
name: "{{ ds_path }}"
31+
state: absent
32+
register: delete_result
33+
retries: 3
34+
until: delete_result is not failed
35+
36+
- name: Assert Delete Passed
37+
ansible.builtin.assert:
38+
that:
39+
- delete_result.failed == false
40+
41+
# #############################################################################
42+
# ############################## Module Testing ###############################
43+
# #############################################################################
44+
45+
- name: Run CSD module with Warm target state
46+
environment: "{{ environment_vars }}"
47+
ibm.ibm_zos_cics.csd:
48+
state: "warm"
49+
register: warm_result
50+
ignore_errors: true
51+
52+
- name: Debug
53+
ansible.builtin.debug:
54+
msg: "{{ warm_result }}"
55+
56+
- name: Assert Removed
57+
ansible.builtin.assert:
58+
that:
59+
- warm_result.failed is true
60+
- warm_result.changed is false
61+
62+
- warm_result.start_state.exists == false
63+
- warm_result.start_state.vsam == false
64+
65+
- warm_result.end_state.exists == false

tests/integration/targets/cics_csd/playbooks/check_output.yml renamed to tests/integration/targets/cics_csd/playbooks/create_existing_csd.yml

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# (c) Copyright IBM Corp. 2023
22
# Apache License, Version 2.0 (see https://opensource.org/licenses/Apache-2.0)
33
---
4-
- name: Validate return data
4+
- name: Create a CSD and then set it's state to initial again
55

66
hosts: "all"
77
gather_facts: false
@@ -42,7 +42,7 @@
4242
# ############################## Module Testing ###############################
4343
# #############################################################################
4444

45-
- name: Create Catalog with initial state
45+
- name: Create CSD with initial state
4646
environment: "{{ environment_vars }}"
4747
ibm.ibm_zos_cics.csd:
4848
state: "initial"
@@ -102,21 +102,3 @@
102102
- res.start_state.vsam is true
103103
- res.end_state.exists is false
104104
- res.end_state.vsam is false
105-
106-
- name: Try removing catalog, changed is false
107-
environment: "{{ environment_vars }}"
108-
ibm.ibm_zos_cics.csd:
109-
state: "absent"
110-
register: res
111-
112-
- name: Debug
113-
ansible.builtin.debug:
114-
msg: "{{ res }}"
115-
116-
- name: Assert CSD removed, changed is false
117-
ansible.builtin.assert:
118-
that:
119-
- res.failed is false
120-
- res.changed is false
121-
- res.start_state.exists is false
122-
- res.end_state.exists is false

tests/integration/targets/cics_csd/playbooks/initial_catalog.yml renamed to tests/integration/targets/cics_csd/playbooks/initial_csd.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# (c) Copyright IBM Corp. 2023
22
# Apache License, Version 2.0 (see https://opensource.org/licenses/Apache-2.0)
33
---
4-
- name: Initial Catalog
4+
- name: Initial CSD
55

66
hosts: "all"
77
gather_facts: false
88
vars:
99
region_dataset_path: "ANSIBIT.CICS.TESTS.{{ cics_test_area_initial }}"
10-
catalog_name: "DFHCSD"
11-
catalog_path: "{{ region_dataset_path }}.{{ catalog_name }}"
10+
ds_name: "DFHCSD"
11+
ds_path: "{{ region_dataset_path }}.{{ ds_name }}"
1212

1313
module_defaults:
1414
ibm.ibm_zos_cics.csd:
@@ -24,10 +24,10 @@
2424
# ############################## Initial cleanup ##############################
2525
# #############################################################################
2626

27-
- name: Delete Catalog Data Set if it exists
27+
- name: Delete CSD Data Set if it exists
2828
environment: "{{ environment_vars }}"
2929
ibm.ibm_zos_core.zos_data_set:
30-
name: "{{ catalog_path }}"
30+
name: "{{ ds_path }}"
3131
state: absent
3232
register: delete_result
3333
retries: 3
@@ -42,7 +42,7 @@
4242
# ############################## Module Testing ###############################
4343
# #############################################################################
4444

45-
- name: Run Local Catalog module with Initial target state
45+
- name: Run CSD module with Initial target state
4646
environment: "{{ environment_vars }}"
4747
ibm.ibm_zos_cics.csd:
4848
state: "initial"
@@ -52,7 +52,7 @@
5252
ansible.builtin.debug:
5353
msg: "{{ result }}"
5454

55-
- name: Assert Created Catalog
55+
- name: Assert Created CSD
5656
ansible.builtin.assert:
5757
that:
5858
- result.failed is false
@@ -68,10 +68,10 @@
6868
# ################################## Cleanup ##################################
6969
# #############################################################################
7070

71-
- name: Delete Catalog Data Set
71+
- name: Delete CSD Data Set
7272
environment: "{{ environment_vars }}"
7373
ibm.ibm_zos_core.zos_data_set:
74-
name: "{{ catalog_path }}"
74+
name: "{{ ds_path }}"
7575
state: absent
7676
register: delete_result
7777
retries: 3

0 commit comments

Comments
 (0)