Skip to content

Commit a483fec

Browse files
[enhancement][mvs_raw]Implement_max_rc_mvs_raw (#1813)
* Add test case and max_rc option * Add fragment * Update 1813-implement_max_rc_mvs_raw.yml * Update plugins/modules/zos_mvs_raw.py Co-authored-by: Fernando Flores <[email protected]> * Update changelogs/fragments/1813-implement_max_rc_mvs_raw.yml Co-authored-by: Fernando Flores <[email protected]> * Fix comments generate defaults and more * Fix documentation * Change documentation * Update 1813-implement_max_rc_mvs_raw.yml * Update changelogs/fragments/1813-implement_max_rc_mvs_raw.yml Co-authored-by: Fernando Flores <[email protected]> --------- Co-authored-by: Fernando Flores <[email protected]>
1 parent bbe133e commit a483fec

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
minor_changes:
2+
- zos_mvs_raw - Added ``max_rc`` option. Now when the user sets ``max_rc``, the module tolerates the failure
3+
if the return code is smaller than the ``max_rc`` specified, however, return value ``changed`` will be False if
4+
the program return code is not 0.
5+
(https://github.com/ansible-collections/ibm_zos_core/pull/1813).
6+

plugins/modules/zos_mvs_raw.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@
5858
required: false
5959
type: bool
6060
default: false
61+
max_rc:
62+
description:
63+
- Specifies the maximum return code allowed for the program output. If the
64+
program generates a return code higher than the specified maximum, the module will fail.
65+
required: false
66+
type: int
67+
default: 0
6168
dds:
6269
description:
6370
- The input data source.
@@ -1852,6 +1859,7 @@ def run_module():
18521859
verbose=dict(type="bool", default=False),
18531860
parm=dict(type="str", required=False),
18541861
tmp_hlq=dict(type="str", required=False, default=None),
1862+
max_rc=dict(type="int", required=False, default=0),
18551863
dds=dict(
18561864
type="list",
18571865
elements="dict",
@@ -1890,6 +1898,7 @@ def run_module():
18901898
program_parm = parms.get("parm")
18911899
authorized = parms.get("auth")
18921900
verbose = parms.get("verbose")
1901+
max_rc = parms.get("max_rc")
18931902
program_response = run_zos_program(
18941903
program=program,
18951904
parm=program_parm,
@@ -1900,13 +1909,18 @@ def run_module():
19001909
)
19011910
response = build_response(program_response.rc, dd_statements, program_response.stdout, program_response.stderr)
19021911
result = combine_dicts(result, response)
1903-
if program_response.rc != 0 :
1912+
1913+
if program_response.rc > max_rc:
19041914
raise ZOSRawError(
19051915
program,
19061916
"{0} {1}".format(program_response.stdout, program_response.stderr),
19071917
)
19081918

1909-
result["changed"] = True
1919+
if program_response.rc != 0:
1920+
result["changed"] = False
1921+
else:
1922+
result["changed"] = True
1923+
19101924
except Exception as e:
19111925
result["backups"] = backups
19121926
module.fail_json(msg=repr(e), **result)
@@ -2085,6 +2099,7 @@ def parse_and_validate_args(params):
20852099
verbose=dict(type="bool", default=False),
20862100
parm=dict(type="str", required=False),
20872101
tmp_hlq=dict(type="qualifier_or_empty", required=False, default=None),
2102+
max_rc=dict(type="int", required=False, default=0),
20882103
dds=dict(
20892104
type="list",
20902105
elements="dict",

tests/functional/modules/test_zos_mvs_raw_func.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,37 @@ def test_data_set_name_special_characters(ansible_zos_module):
978978
if idcams_dataset:
979979
hosts.all.zos_data_set(name=idcams_dataset, state="absent")
980980

981+
@pytest.mark.parametrize("max_rc", [4, 8])
982+
def test_new_disposition_for_data_set_members_max_rc(ansible_zos_module, max_rc):
983+
hosts = ansible_zos_module
984+
results = hosts.all.zos_mvs_raw(
985+
program_name="idcams",
986+
auth=True,
987+
max_rc=max_rc,
988+
dds=[
989+
{
990+
"dd_output":{
991+
"dd_name":"sysprint",
992+
"return_content":{
993+
"type":"text"
994+
}
995+
}
996+
},
997+
{
998+
"dd_input":{
999+
"dd_name":"sysin",
1000+
"content":" DELETE THIS.DATASET.DOES.NOT.EXIST"
1001+
}
1002+
},
1003+
],
1004+
)
1005+
for result in results.contacted.values():
1006+
assert result.get("changed") is False
1007+
assert result.get("ret_code", {}).get("code", -1) == 8
1008+
if max_rc != 8:
1009+
assert result.get("msg") is not None
1010+
assert result.get("failed") is True
1011+
9811012
# ---------------------------------------------------------------------------- #
9821013
# Input DD Tests #
9831014
# ---------------------------------------------------------------------------- #

0 commit comments

Comments
 (0)