Skip to content

Commit 4bcb02a

Browse files
andrewhughes101GitHub Enterprise
authored andcommitted
Merge pull request ansible-collections#139 from CICS/fix-initial-behaviour
fix Initial data set behaviour and formatting issues
2 parents 93b80f0 + d5ba951 commit 4bcb02a

File tree

13 files changed

+340
-248
lines changed

13 files changed

+340
-248
lines changed

meta/runtime.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ action_groups:
1212
- local_catalog
1313
- local_request_queue
1414
- trace
15+
- intrapartition
16+
- auxiliary_temp

plugins/module_utils/data_set.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44
# Apache License, Version 2.0 (see https://opensource.org/licenses/Apache-2.0)
55

66
from __future__ import (absolute_import, division, print_function)
7+
8+
from ansible_collections.ibm.ibm_zos_cics.plugins.module_utils.icetool import _run_icetool
9+
from ansible_collections.ibm.ibm_zos_core.plugins.module_utils.better_arg_parser import BetterArgParser
710
__metaclass__ = type
811

912
from ansible.module_utils.basic import AnsibleModule
10-
from ansible_collections.ibm.ibm_zos_cics.plugins.module_utils import dataset_utils
13+
from ansible_collections.ibm.ibm_zos_cics.plugins.module_utils.dataset_utils import (
14+
_build_idcams_define_cmd, _data_set, _dataset_size, _run_idcams, _run_listds, _run_iefbr14)
1115
from ansible_collections.ibm.ibm_zos_cics.plugins.module_utils.response import _response, _state
1216
from ansible_collections.ibm.ibm_zos_core.plugins.module_utils.better_arg_parser import BetterArgParser
1317
from ansible_collections.ibm.ibm_zos_core.plugins.module_utils.dd_statement import DatasetDefinition
@@ -61,16 +65,16 @@ def _get_arg_defs(self): # type: () -> dict
6165
},
6266
}
6367

64-
def _get_data_set_object(self, size, result): # type: (dataset_utils._dataset_size, dict) -> dataset_utils._data_set
65-
return dataset_utils._data_set(
68+
def _get_data_set_object(self, size, result): # type: (_dataset_size, dict) -> _data_set
69+
return _data_set(
6670
size=size,
6771
name=result.get(_dataset_constants["DATASET_LOCATION_ALIAS"]).upper(),
6872
state=result.get(_dataset_constants["TARGET_STATE_ALIAS"]),
6973
exists=False,
7074
vsam=False)
7175

7276
def _get_data_set_size(self, result):
73-
return dataset_utils._dataset_size(
77+
return _dataset_size(
7478
unit=result.get(_dataset_constants["PRIMARY_SPACE_UNIT_ALIAS"]),
7579
primary=result.get(_dataset_constants["PRIMARY_SPACE_VALUE_ALIAS"]),
7680
secondary=_dataset_constants["SECONDARY_SPACE_VALUE_DEFAULT"])
@@ -93,11 +97,11 @@ def validate_parameters(self): # type: () -> None
9397
self.data_set = self._get_data_set_object(size, result)
9498

9599
def create_data_set(self):
96-
create_cmd = dataset_utils._build_idcams_define_cmd({})
100+
create_cmd = _build_idcams_define_cmd({})
97101

98102
def build_vsam_data_set(self, create_cmd, message): # type: (str, str) -> None
99103
try:
100-
idcams_executions = dataset_utils._run_idcams(
104+
idcams_executions = _run_idcams(
101105
cmd=create_cmd,
102106
name=message,
103107
location=self.data_set["name"],
@@ -111,7 +115,7 @@ def build_vsam_data_set(self, create_cmd, message): # type: (str, str) -> None
111115

112116
def build_seq_data_set(self, ddname, definition): # type: (str, DatasetDefinition) -> None
113117
try:
114-
iefbr14_executions = dataset_utils._run_iefbr14(ddname, definition)
118+
iefbr14_executions = _run_iefbr14(ddname, definition)
115119
self.result["executions"] = self.result["executions"] + iefbr14_executions
116120
self.result["changed"] = True
117121
except Exception as e:
@@ -124,7 +128,7 @@ def delete_data_set(self, message): # type: (str) -> None
124128
'''.format(self.data_set["name"])
125129

126130
try:
127-
idcams_executions = dataset_utils._run_idcams(
131+
idcams_executions = _run_idcams(
128132
cmd=delete_cmd,
129133
name=message,
130134
location=self.data_set["name"],
@@ -137,10 +141,17 @@ def delete_data_set(self, message): # type: (str) -> None
137141

138142
def init_data_set(self): # type: () -> None
139143
if self.data_set["exists"]:
140-
self.result["end_state"] = _state(exists=self.data_set["exists"], vsam=self.data_set["vsam"])
141-
self._exit()
144+
icetool_executions, record_count = _run_icetool(self.data_set["name"])
145+
self.result["executions"] = self.result["executions"] + icetool_executions
146+
if record_count["record_count"] <= 0:
147+
self.result["end_state"] = _state(exists=self.data_set["exists"], vsam=self.data_set["vsam"])
148+
self._exit()
149+
else:
150+
self.delete_data_set()
151+
self.data_set = self.get_data_set_state(self.data_set)
152+
self.create_data_set()
142153

143-
if not self.data_set["exists"]:
154+
else:
144155
self.create_data_set()
145156

146157
def warm_data_set(self): # type: () -> None
@@ -177,7 +188,7 @@ def get_target_method(self, target): # type: (str) -> [str | invalid_target_sta
177188

178189
def get_data_set_state(self, data_set): # type: (dict) -> dict
179190
try:
180-
listds_executions, ds_status = dataset_utils._run_listds(data_set["name"])
191+
listds_executions, ds_status = _run_listds(data_set["name"])
181192

182193
data_set["exists"] = ds_status["exists"]
183194
data_set["vsam"] = ds_status["vsam"]

plugins/module_utils/icetool.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55

66
from __future__ import (absolute_import, division, print_function)
77
__metaclass__ = type
8-
from typing import List
98

109
from ansible_collections.ibm.ibm_zos_core.plugins.module_utils.zos_mvs_raw import MVSCmd, MVSCmdResponse
1110
from ansible_collections.ibm.ibm_zos_core.plugins.module_utils.dd_statement import StdoutDefinition, DatasetDefinition, DDStatement, InputDefinition
1211
from ansible_collections.ibm.ibm_zos_cics.plugins.module_utils.response import _execution
1312

1413

15-
def _get_icetool_dds(location): # type: (str) -> List[DDStatement]
14+
def _get_icetool_dds(location): # type: (str) -> list[DDStatement]
1615
return [
1716
DDStatement('sysprint', StdoutDefinition()),
1817
DDStatement('dd1', DatasetDefinition(dataset_name=location, disposition="SHR")),

plugins/modules/auxiliary_temp.py

Lines changed: 100 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@
191191
"""
192192

193193

194-
from typing import Dict
195194
from ansible_collections.ibm.ibm_zos_core.plugins.module_utils.better_arg_parser import (
196195
BetterArgParser,
197196
)
@@ -219,116 +218,104 @@ class AnsibleAuxiliaryTempModule(DataSet):
219218
def __init__(self):
220219
super(AnsibleAuxiliaryTempModule, self).__init__()
221220

222-
def init_argument_spec(self): # type: () -> Dict
221+
def init_argument_spec(self): # type: () -> dict
223222
arg_spec = super(AnsibleAuxiliaryTempModule, self).init_argument_spec()
224223

225-
arg_spec[ds_constants["PRIMARY_SPACE_VALUE_ALIAS"]].update(
226-
{
227-
"default": temp_constants["PRIMARY_SPACE_VALUE_DEFAULT"],
228-
}
229-
)
230-
arg_spec[ds_constants["PRIMARY_SPACE_UNIT_ALIAS"]].update(
231-
{
232-
"default": temp_constants["SPACE_UNIT_DEFAULT"],
233-
}
234-
)
235-
arg_spec[ds_constants["TARGET_STATE_ALIAS"]].update(
236-
{
237-
"choices": temp_constants["TARGET_STATE_OPTIONS"],
238-
}
239-
)
240-
arg_spec.update(
241-
{
242-
ds_constants["REGION_DATA_SETS_ALIAS"]: {
243-
"type": "dict",
244-
"required": True,
245-
"options": {
246-
"template": {
247-
"type": "str",
248-
"required": False,
249-
},
250-
"dfhtemp": {
251-
"type": "dict",
252-
"required": False,
253-
"options": {
254-
"dsn": {
255-
"type": "str",
256-
"required": False,
257-
},
224+
arg_spec[ds_constants["PRIMARY_SPACE_VALUE_ALIAS"]].update({
225+
"default": temp_constants["PRIMARY_SPACE_VALUE_DEFAULT"],
226+
})
227+
arg_spec[ds_constants["PRIMARY_SPACE_UNIT_ALIAS"]].update({
228+
"default": temp_constants["SPACE_UNIT_DEFAULT"],
229+
})
230+
arg_spec[ds_constants["TARGET_STATE_ALIAS"]].update({
231+
"choices": temp_constants["TARGET_STATE_OPTIONS"],
232+
})
233+
arg_spec.update({
234+
ds_constants["REGION_DATA_SETS_ALIAS"]: {
235+
"type": "dict",
236+
"required": True,
237+
"options": {
238+
"template": {
239+
"type": "str",
240+
"required": False,
241+
},
242+
"dfhtemp": {
243+
"type": "dict",
244+
"required": False,
245+
"options": {
246+
"dsn": {
247+
"type": "str",
248+
"required": False,
258249
},
259250
},
260251
},
261252
},
262-
ds_constants["CICS_DATA_SETS_ALIAS"]: {
263-
"type": "dict",
264-
"required": False,
265-
"options": {
266-
"template": {
267-
"type": "str",
268-
"required": False,
269-
},
270-
"sdfhload": {
271-
"type": "str",
272-
"required": False,
273-
},
253+
},
254+
ds_constants["CICS_DATA_SETS_ALIAS"]: {
255+
"type": "dict",
256+
"required": False,
257+
"options": {
258+
"template": {
259+
"type": "str",
260+
"required": False,
261+
},
262+
"sdfhload": {
263+
"type": "str",
264+
"required": False,
274265
},
275266
},
276-
}
277-
)
267+
},
268+
})
278269
return arg_spec
279270

280-
def _get_arg_defs(self): # type: () -> Dict
271+
def _get_arg_defs(self): # type: () -> dict
281272
arg_def = super(AnsibleAuxiliaryTempModule, self)._get_arg_defs()
282273

283-
arg_def[ds_constants["PRIMARY_SPACE_VALUE_ALIAS"]].update(
284-
{"default": temp_constants["PRIMARY_SPACE_VALUE_DEFAULT"]}
285-
)
286-
(
287-
arg_def[ds_constants["PRIMARY_SPACE_UNIT_ALIAS"]].update(
288-
{"default": temp_constants["SPACE_UNIT_DEFAULT"]}
289-
),
290-
)
291-
arg_def[ds_constants["TARGET_STATE_ALIAS"]].update(
292-
{"choices": temp_constants["TARGET_STATE_OPTIONS"]}
293-
)
294-
arg_def.update(
295-
{
296-
ds_constants["REGION_DATA_SETS_ALIAS"]: {
297-
"arg_type": "dict",
298-
"required": True,
299-
"options": {
300-
"template": {
301-
"arg_type": "str",
302-
"required": False,
303-
},
304-
"dfhtemp": {
305-
"arg_type": "dict",
306-
"required": False,
307-
"options": {
308-
"dsn": {
309-
"arg_type": "data_set_base",
310-
"required": False,
311-
},
274+
arg_def[ds_constants["PRIMARY_SPACE_VALUE_ALIAS"]].update({
275+
"default": temp_constants["PRIMARY_SPACE_VALUE_DEFAULT"]
276+
})
277+
arg_def[ds_constants["PRIMARY_SPACE_UNIT_ALIAS"]].update({
278+
"default": temp_constants["SPACE_UNIT_DEFAULT"]
279+
})
280+
arg_def[ds_constants["TARGET_STATE_ALIAS"]].update({
281+
"choices": temp_constants["TARGET_STATE_OPTIONS"]
282+
})
283+
arg_def.update({
284+
ds_constants["REGION_DATA_SETS_ALIAS"]: {
285+
"arg_type": "dict",
286+
"required": True,
287+
"options": {
288+
"template": {
289+
"arg_type": "str",
290+
"required": False,
291+
},
292+
"dfhtemp": {
293+
"arg_type": "dict",
294+
"required": False,
295+
"options": {
296+
"dsn": {
297+
"arg_type": "data_set_base",
298+
"required": False,
312299
},
313300
},
314301
},
315302
},
316-
ds_constants["CICS_DATA_SETS_ALIAS"]: {
317-
"arg_type": "dict",
318-
"required": False,
319-
"options": {
320-
"template": {
321-
"arg_type": "str",
322-
"required": False,
323-
},
324-
"sdfhload": {
325-
"arg_type": "data_set_base",
326-
"required": False,
327-
},
303+
},
304+
ds_constants["CICS_DATA_SETS_ALIAS"]: {
305+
"arg_type": "dict",
306+
"required": False,
307+
"options": {
308+
"template": {
309+
"arg_type": "str",
310+
"required": False,
311+
},
312+
"sdfhload": {
313+
"arg_type": "data_set_base",
314+
"required": False,
328315
},
329316
},
330-
}
331-
)
317+
},
318+
})
332319

333320
return arg_def
334321

@@ -354,28 +341,26 @@ def _get_data_set_size(self, result):
354341
def validate_parameters(self): # type: () -> None
355342
arg_defs = self._get_arg_defs()
356343

357-
result = BetterArgParser(arg_defs).parse_args(
358-
{
359-
ds_constants["REGION_DATA_SETS_ALIAS"]: self._module.params.get(
360-
ds_constants["REGION_DATA_SETS_ALIAS"]
361-
),
362-
ds_constants["CICS_DATA_SETS_ALIAS"]: self._module.params.get(
363-
ds_constants["CICS_DATA_SETS_ALIAS"]
364-
),
365-
ds_constants["PRIMARY_SPACE_VALUE_ALIAS"]: self._module.params.get(
366-
ds_constants["PRIMARY_SPACE_VALUE_ALIAS"]
367-
),
368-
ds_constants["PRIMARY_SPACE_UNIT_ALIAS"]: self._module.params.get(
369-
ds_constants["PRIMARY_SPACE_UNIT_ALIAS"]
370-
),
371-
ds_constants["DATASET_LOCATION_ALIAS"]: self._module.params.get(
372-
ds_constants["DATASET_LOCATION_ALIAS"]
373-
),
374-
ds_constants["TARGET_STATE_ALIAS"]: self._module.params.get(
375-
ds_constants["TARGET_STATE_ALIAS"]
376-
),
377-
}
378-
)
344+
result = BetterArgParser(arg_defs).parse_args({
345+
ds_constants["REGION_DATA_SETS_ALIAS"]: self._module.params.get(
346+
ds_constants["REGION_DATA_SETS_ALIAS"]
347+
),
348+
ds_constants["CICS_DATA_SETS_ALIAS"]: self._module.params.get(
349+
ds_constants["CICS_DATA_SETS_ALIAS"]
350+
),
351+
ds_constants["PRIMARY_SPACE_VALUE_ALIAS"]: self._module.params.get(
352+
ds_constants["PRIMARY_SPACE_VALUE_ALIAS"]
353+
),
354+
ds_constants["PRIMARY_SPACE_UNIT_ALIAS"]: self._module.params.get(
355+
ds_constants["PRIMARY_SPACE_UNIT_ALIAS"]
356+
),
357+
ds_constants["DATASET_LOCATION_ALIAS"]: self._module.params.get(
358+
ds_constants["DATASET_LOCATION_ALIAS"]
359+
),
360+
ds_constants["TARGET_STATE_ALIAS"]: self._module.params.get(
361+
ds_constants["TARGET_STATE_ALIAS"]
362+
),
363+
})
379364

380365
size = self._get_data_set_size(result)
381366
self.data_set = self._get_data_set_object(size, result)

0 commit comments

Comments
 (0)