Skip to content

Commit 73bc136

Browse files
mayankmani-sdefernandofloresgrexemin
authored
Adding Raw option to DDUMP for generic DCB selection (#2341)
* added test cases for raw command * added code to support raw * added piece of code to support raw * added code * added raw in doc * added doc * reverted * added raw in doc * changed * added doc in concat * added example of raw in doc * added raw * fixed * typo * removed print statement * fixed * fixed * changed raw doc * added fragments * typo * Update plugins/modules/zos_mvs_raw.py Co-authored-by: Fernando Flores <[email protected]> * Update changelogs/fragments/2341-zos_mvs_raw-Add-raw-option-for-generic-dcb-selection Co-authored-by: Fernando Flores <[email protected]> * Update changelogs/fragments/2341-zos_mvs_raw-Add-raw-option-for-generic-dcb-selection Co-authored-by: Fernando Flores <[email protected]> * Update plugins/modules/zos_mvs_raw.py Co-authored-by: Alex Moreno <[email protected]> * Update plugins/modules/zos_mvs_raw.py Co-authored-by: Alex Moreno <[email protected]> * Update plugins/modules/zos_mvs_raw.py Co-authored-by: Alex Moreno <[email protected]> * Update plugins/modules/zos_mvs_raw.py Co-authored-by: Alex Moreno <[email protected]> --------- Co-authored-by: Fernando Flores <[email protected]> Co-authored-by: Alex Moreno <[email protected]>
1 parent b945878 commit 73bc136

File tree

5 files changed

+235
-77
lines changed

5 files changed

+235
-77
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
minor_changes:
2+
- zos_mvs_raw - Adds new `raw` option under ``dd_data_set`` that lets the MVS program create datasets with its own
3+
DCB attributes without the user having to specify them.
4+
(https://github.com/ansible-collections/ibm_zos_core/pull/2341).
5+
trivial:
6+
- dd_statement - Internal updates to support the new `raw` option behavior.
7+
(https://github.com/ansible-collections/ibm_zos_core/pull/2341).
8+
- mvs_cmd_command - Internal updates to support the new `raw` option behavior and
9+
pass it as an MVS command.
10+
(https://github.com/ansible-collections/ibm_zos_core/pull/2341).
11+
- test_adrdssu_dataset_dump_with_raw_dd - Added test case to verify `raw` dataset
12+
support in `zos_mvs_raw` for ADRDSSU logical dumps.
13+
(https://github.com/ansible-collections/ibm_zos_core/pull/2341).

plugins/module_utils/dd_statement.py

Lines changed: 84 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ def __init__(
356356
key_encoding1=None,
357357
key_label2=None,
358358
key_encoding2=None,
359+
raw=False,
359360
):
360361
"""Dataset DD data type to be used in a DDStatement.
361362
Defaults and validation are handled my mvscmd.
@@ -539,19 +540,23 @@ def __init__(
539540
super().__init__(dataset_name)
540541
self.disposition = disposition
541542
self.type = type
542-
543-
if primary_unit and space_units.get(primary_unit.lower()) is not None:
544-
primary_unit = space_units.get(primary_unit.lower())
545-
if secondary_unit and space_units.get(secondary_unit.lower()) is not None:
546-
secondary_unit = space_units.get(secondary_unit.lower())
547-
if primary and primary_unit:
548-
self.primary = str(primary) + primary_unit
549-
else:
550-
self.primary = primary
551-
if secondary and secondary_unit:
552-
self.secondary = str(secondary) + secondary_unit
543+
self.raw = raw
544+
if not raw:
545+
if primary_unit and space_units.get(primary_unit.lower()) is not None:
546+
primary_unit = space_units.get(primary_unit.lower())
547+
if secondary_unit and space_units.get(secondary_unit.lower()) is not None:
548+
secondary_unit = space_units.get(secondary_unit.lower())
549+
if primary and primary_unit:
550+
self.primary = str(primary) + primary_unit
551+
else:
552+
self.primary = primary
553+
if secondary and secondary_unit:
554+
self.secondary = str(secondary) + secondary_unit
555+
else:
556+
self.secondary = secondary
553557
else:
554-
self.secondary = secondary
558+
self.primary = None
559+
self.secondary = None
555560

556561
DISPOSITION_ARG_MAP = {"catlg": "catalog", "uncatlg": "uncatalog"}
557562
self.normal_disposition = (
@@ -591,68 +596,73 @@ def _build_arg_string(self):
591596
str
592597
String to be used by mvscmd/mvscmdauth.
593598
"""
594-
if not self.disposition:
595-
return ""
596-
mvscmd_string = ",{0}".format(self.disposition) if self.disposition else ""
597-
mvscmd_string = self._append_mvscmd_string(mvscmd_string, "type", self.type)
598-
mvscmd_string = self._append_mvscmd_string(
599-
mvscmd_string, "primary", self.primary
600-
)
601-
mvscmd_string = self._append_mvscmd_string(
602-
mvscmd_string, "secondary", self.secondary
603-
)
604-
mvscmd_string = self._append_mvscmd_string(
605-
mvscmd_string, "normdisp", self.normal_disposition
606-
)
607-
mvscmd_string = self._append_mvscmd_string(
608-
mvscmd_string, "conddisp", self.conditional_disposition
609-
)
610-
mvscmd_string = self._append_mvscmd_string(
611-
mvscmd_string, "blksize", self.block_size
612-
)
613-
mvscmd_string = self._append_mvscmd_string(
614-
mvscmd_string, "dirblks", self.directory_blocks
615-
)
616-
mvscmd_string = self._append_mvscmd_string(
617-
mvscmd_string, "recfm", self.record_format
618-
)
619-
mvscmd_string = self._append_mvscmd_string(
620-
mvscmd_string, "lrecl", self.record_length
621-
)
622-
mvscmd_string = self._append_mvscmd_string(
623-
mvscmd_string, "storclas", self.storage_class
624-
)
625-
mvscmd_string = self._append_mvscmd_string(
626-
mvscmd_string, "dataclas", self.data_class
627-
)
628-
mvscmd_string = self._append_mvscmd_string(
629-
mvscmd_string, "mgmtclas", self.management_class
630-
)
631-
mvscmd_string = self._append_mvscmd_string(
632-
mvscmd_string, "keylen", self.key_length
633-
)
634-
mvscmd_string = self._append_mvscmd_string(
635-
mvscmd_string, "keyoffset", self.key_offset
636-
)
637-
mvscmd_string = self._append_mvscmd_string(
638-
mvscmd_string, "volumes", self.volumes
639-
)
640-
mvscmd_string = self._append_mvscmd_string(
641-
mvscmd_string, "dskeylbl", self.dataset_key_label
642-
)
643-
mvscmd_string = self._append_mvscmd_string(
644-
mvscmd_string, "keylab1", self.key_label1
645-
)
646-
mvscmd_string = self._append_mvscmd_string(
647-
mvscmd_string, "keylab2", self.key_label2
648-
)
649-
mvscmd_string = self._append_mvscmd_string(
650-
mvscmd_string, "keycd1", self.key_encoding1
651-
)
652-
mvscmd_string = self._append_mvscmd_string(
653-
mvscmd_string, "keycd2", self.key_encoding2
654-
)
655-
return mvscmd_string
599+
if self.raw:
600+
mvscmd_string = ",{0}".format(self.disposition) if self.disposition else ""
601+
mvscmd_string += ",raw"
602+
return mvscmd_string
603+
else:
604+
if not self.disposition:
605+
return ""
606+
mvscmd_string = ",{0}".format(self.disposition) if self.disposition else ""
607+
mvscmd_string = self._append_mvscmd_string(mvscmd_string, "type", self.type)
608+
mvscmd_string = self._append_mvscmd_string(
609+
mvscmd_string, "primary", self.primary
610+
)
611+
mvscmd_string = self._append_mvscmd_string(
612+
mvscmd_string, "secondary", self.secondary
613+
)
614+
mvscmd_string = self._append_mvscmd_string(
615+
mvscmd_string, "normdisp", self.normal_disposition
616+
)
617+
mvscmd_string = self._append_mvscmd_string(
618+
mvscmd_string, "conddisp", self.conditional_disposition
619+
)
620+
mvscmd_string = self._append_mvscmd_string(
621+
mvscmd_string, "blksize", self.block_size
622+
)
623+
mvscmd_string = self._append_mvscmd_string(
624+
mvscmd_string, "dirblks", self.directory_blocks
625+
)
626+
mvscmd_string = self._append_mvscmd_string(
627+
mvscmd_string, "recfm", self.record_format
628+
)
629+
mvscmd_string = self._append_mvscmd_string(
630+
mvscmd_string, "lrecl", self.record_length
631+
)
632+
mvscmd_string = self._append_mvscmd_string(
633+
mvscmd_string, "storclas", self.storage_class
634+
)
635+
mvscmd_string = self._append_mvscmd_string(
636+
mvscmd_string, "dataclas", self.data_class
637+
)
638+
mvscmd_string = self._append_mvscmd_string(
639+
mvscmd_string, "mgmtclas", self.management_class
640+
)
641+
mvscmd_string = self._append_mvscmd_string(
642+
mvscmd_string, "keylen", self.key_length
643+
)
644+
mvscmd_string = self._append_mvscmd_string(
645+
mvscmd_string, "keyoffset", self.key_offset
646+
)
647+
mvscmd_string = self._append_mvscmd_string(
648+
mvscmd_string, "volumes", self.volumes
649+
)
650+
mvscmd_string = self._append_mvscmd_string(
651+
mvscmd_string, "dskeylbl", self.dataset_key_label
652+
)
653+
mvscmd_string = self._append_mvscmd_string(
654+
mvscmd_string, "keylab1", self.key_label1
655+
)
656+
mvscmd_string = self._append_mvscmd_string(
657+
mvscmd_string, "keylab2", self.key_label2
658+
)
659+
mvscmd_string = self._append_mvscmd_string(
660+
mvscmd_string, "keycd1", self.key_encoding1
661+
)
662+
mvscmd_string = self._append_mvscmd_string(
663+
mvscmd_string, "keycd2", self.key_encoding2
664+
)
665+
return mvscmd_string
656666

657667

658668
class VolumeDefinition(DataDefinition):

plugins/module_utils/zos_mvs_raw.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ def __init__(
164164
backup=None,
165165
return_content=None,
166166
tmphlq=None,
167+
raw=False,
167168
**kwargs
168169
):
169170
"""
@@ -229,9 +230,16 @@ def __init__(
229230
HLQ to be used for temporary datasets. Defaults to None.
230231
----------
231232
"""
233+
self.raw = raw
232234
self.backup = None
233235
self.return_content = ReturnContent(**(return_content or {}))
234236
self.tmphlq = tmphlq
237+
if raw:
238+
super().__init__(
239+
dataset_name=data_set_name,
240+
raw=True
241+
)
242+
return
235243
primary_unit = space_type
236244
secondary_unit = space_type
237245
key_label1 = None
@@ -301,6 +309,11 @@ def __init__(
301309
key_encoding2=key_encoding2,
302310
)
303311

312+
def __str__(self):
313+
if self.raw:
314+
return f"{self.dataset_name},raw"
315+
return super().__str__()
316+
304317

305318
class RawFileDefinition(FileDefinition):
306319
"""Wrapper around FileDefinition to contain information about

plugins/modules/zos_mvs_raw.py

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@
100100
- When using GDS relative name and it is a positive generation, I(disposition=new) must be used.
101101
type: str
102102
required: false
103+
raw:
104+
description:
105+
- Create a new data set and let the MVS program assign its own default DCB attributes.
106+
- When C(raw=true), all supplied DCB attributes like disposition, space, volumes, SMS, keys, record settings, etc. are ignored.
107+
- Using C(raw) option is not possible for all programs, use this for cases where the MVS program that is called is able to assign
108+
its own default dataset attributes.
109+
type: bool
110+
default: false
103111
type:
104112
description:
105113
- The data set type. Only required when I(disposition=new).
@@ -757,6 +765,14 @@
757765
- When using GDS relative name and it is a positive generation, I(disposition=new) must be used.
758766
type: str
759767
required: false
768+
raw:
769+
description:
770+
- Create a new data set and let the MVS program assign its own default DCB attributes.
771+
- When C(raw=true), all supplied DCB attributes like disposition, space, volumes, SMS, keys, record settings, etc. are ignored.
772+
- Using C(raw) option is not possible for all programs, use this for cases where the MVS program that is called is able to assign
773+
its own default dataset attributes.
774+
type: bool
775+
default: false
760776
type:
761777
description:
762778
- The data set type. Only required when I(disposition=new).
@@ -1382,6 +1398,26 @@
13821398
dd_name: sysin
13831399
content: " LISTCAT ENTRIES('SOME.DATASET.*')"
13841400
1401+
- name: Run ADRDSSU to dump a dataset without having to specify the DCB attributes for dd_data_set by using raw option.
1402+
zos_mvs_raw:
1403+
program_name: ADRDSSU
1404+
auth: true
1405+
verbose: true
1406+
dds:
1407+
- dd_data_set:
1408+
dd_name: OUTDD
1409+
data_set_name: "USER.TEST.DUMP"
1410+
raw: true
1411+
- dd_input:
1412+
dd_name: SYSIN
1413+
content: |
1414+
DUMP DATASET(INCLUDE(USER.TEST.SOURCE)) -
1415+
OUTDDNAME(OUTDD)
1416+
- dd_output:
1417+
dd_name: SYSPRINT
1418+
return_content:
1419+
type: text
1420+
13851421
- name: Full volume dump using ADDRDSU.
13861422
zos_mvs_raw:
13871423
program_name: adrdssu
@@ -1815,6 +1851,7 @@ def run_module():
18151851

18161852
dd_data_set_base = dict(
18171853
data_set_name=dict(type="str"),
1854+
raw=dict(type="bool", default=False),
18181855
disposition=dict(type="str", choices=["new", "shr", "mod", "old"]),
18191856
disposition_normal=dict(
18201857
type="str",
@@ -2079,6 +2116,7 @@ def parse_and_validate_args(params):
20792116

20802117
dd_data_set_base = dict(
20812118
data_set_name=dict(type="data_set", required=True),
2119+
raw=dict(type="bool", default=False),
20822120
disposition=dict(type="str", choices=["new", "shr", "mod", "old"]),
20832121
disposition_normal=dict(
20842122
type="str",
@@ -2741,9 +2779,11 @@ def get_dd_name_and_key(dd):
27412779
key = ""
27422780
if dd.get("dd_data_set"):
27432781
dd_name = dd.get("dd_data_set").get("dd_name")
2782+
raw_flag = dd.get("dd_data_set").get("raw", False)
27442783
data_set_name, disposition = resolve_data_set_names(dd.get("dd_data_set").get("data_set_name"),
27452784
dd.get("dd_data_set").get("disposition"),
2746-
dd.get("dd_data_set").get("type"))
2785+
dd.get("dd_data_set").get("type"),
2786+
raw=raw_flag)
27472787
dd.get("dd_data_set")["data_set_name"] = data_set_name
27482788
dd.get("dd_data_set")["disposition"] = disposition
27492789
key = "dd_data_set"
@@ -2793,7 +2833,7 @@ def set_extra_attributes_in_dd(dd, tmphlq, key):
27932833
return dd
27942834

27952835

2796-
def resolve_data_set_names(dataset, disposition, type):
2836+
def resolve_data_set_names(dataset, disposition, type, raw=False):
27972837
"""Resolve cases for data set names as relative gds or positive
27982838
that could be accepted if disposition is new.
27992839
Parameters
@@ -2811,11 +2851,12 @@ def resolve_data_set_names(dataset, disposition, type):
28112851
str
28122852
The disposition base on the system
28132853
"""
2854+
if raw:
2855+
return dataset, disposition or "shr"
28142856
if disposition:
28152857
disp = disposition
28162858
else:
28172859
disp = "shr"
2818-
28192860
if data_set.DataSet.is_gds_relative_name(dataset):
28202861
if data_set.DataSet.is_gds_positive_relative_name(dataset):
28212862
if disp == "new":
@@ -2841,6 +2882,33 @@ def resolve_data_set_names(dataset, disposition, type):
28412882
return dataset, disp
28422883

28432884

2885+
def validate_raw_parameter(dd_params):
2886+
"""Validate that when raw=true, no other dataset parameters are specified."""
2887+
if dd_params.get('raw'):
2888+
# Parameters that should not be used with raw=true
2889+
incompatible_params = [
2890+
'disposition_normal', 'disposition_abnormal',
2891+
'space_type', 'space_primary', 'space_secondary', 'volumes',
2892+
'sms_management_class', 'sms_storage_class', 'sms_data_class',
2893+
'block_size', 'directory_blocks', 'key_label', 'type',
2894+
'encryption_key_1', 'encryption_key_2', 'key_length', 'key_offset',
2895+
'record_length', 'record_format'
2896+
]
2897+
2898+
specified_params = []
2899+
for param in incompatible_params:
2900+
if dd_params.get(param) is not None:
2901+
specified_params.append(param)
2902+
2903+
if specified_params:
2904+
raise ValueError(
2905+
"The following parameters cannot be used when 'raw=true': {}. "
2906+
"When using raw datasets, the program determines all dataset attributes. "
2907+
"Either remove these parameters or set raw=false.".format(
2908+
', '.join(specified_params))
2909+
)
2910+
2911+
28442912
def build_data_definition(dd):
28452913
"""Build a DataDefinition object for a particular DD parameter.
28462914
@@ -2857,6 +2925,7 @@ def build_data_definition(dd):
28572925
"""
28582926
data_definition = None
28592927
if dd.get("dd_data_set"):
2928+
validate_raw_parameter(dd.get("dd_data_set"))
28602929
data_definition = RawDatasetDefinition(
28612930
**(dd.get("dd_data_set")))
28622931
if data_definition.backup:

0 commit comments

Comments
 (0)