Skip to content

Commit fc54021

Browse files
[Bug][zos_mvs_raw] Consistently fail if return code is not zero (#1774)
* Added fix * Added test fix * Added changelog ffragment * Changed if statement and addedd test assertion * Update changelogs/fragments/1774-zos_mvs_raw-verbose-fail.yml Co-authored-by: Ketan Kelkar <[email protected]> --------- Co-authored-by: Ketan Kelkar <[email protected]>
1 parent 8152f45 commit fc54021

File tree

3 files changed

+32
-10
lines changed

3 files changed

+32
-10
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
bugfixes:
2+
- zos_mvs_raw - If a program failed with a non-zero return code and verbose was false, the module would succeed.
3+
Whereas, if the program failed and verbose was true the module would fail.
4+
Fix now has a consistent behavior and fails in both cases.
5+
(https://github.com/ansible-collections/ibm_zos_core/pull/1774).
6+
- zos_mvs_raw - Module would obfuscate the return code from the program when failing returning 8 instead.
7+
Fix now returns the proper return code from the program.
8+
(https://github.com/ansible-collections/ibm_zos_core/pull/1774).

plugins/modules/zos_mvs_raw.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
author:
2323
- "Xiao Yuan Ma (@bjmaxy)"
2424
- "Blake Becker (@blakeinate)"
25+
- "Oscar Fernando Flores (@fernandofloresg)"
2526
short_description: Run a z/OS program.
2627
description:
2728
- Run a z/OS program.
@@ -1897,21 +1898,21 @@ def run_module():
18971898
verbose=verbose,
18981899
tmphlq=tmphlq,
18991900
)
1900-
if program_response.rc != 0 and program_response.stderr:
1901+
response = build_response(program_response.rc, dd_statements, program_response.stdout)
1902+
result = combine_dicts(result, response)
1903+
if program_response.rc != 0 :
19011904
raise ZOSRawError(
19021905
program,
19031906
"{0} {1}".format(program_response.stdout, program_response.stderr),
19041907
)
19051908

1906-
response = build_response(program_response.rc, dd_statements, program_response.stdout)
19071909
result["changed"] = True
19081910
except Exception as e:
19091911
result["backups"] = backups
19101912
module.fail_json(msg=repr(e), **result)
19111913
else:
19121914
result = dict(changed=True, dd_names=[], ret_code=dict(code=0))
1913-
to_return = combine_dicts(result, response)
1914-
module.exit_json(**to_return)
1915+
module.exit_json(**result)
19151916
# ---------------------------------------------------------------------------- #
19161917

19171918

tests/functional/modules/test_zos_mvs_raw_func.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,13 @@ def test_failing_name_format(ansible_zos_module):
5959
for result in results.contacted.values():
6060
assert "ValueError" in result.get("msg")
6161

62-
63-
def test_disposition_new(ansible_zos_module):
62+
@pytest.mark.parametrize(
63+
# Added this verbose to test issue https://github.com/ansible-collections/ibm_zos_core/issues/1359
64+
# Where a program will fail if rc != 0 only if verbose was True.
65+
"verbose",
66+
[True, False],
67+
)
68+
def test_disposition_new(ansible_zos_module, verbose):
6469
idcams_dataset = None
6570
try:
6671
hosts = ansible_zos_module
@@ -71,6 +76,7 @@ def test_disposition_new(ansible_zos_module):
7176
results = hosts.all.zos_mvs_raw(
7277
program_name="idcams",
7378
auth=True,
79+
verbose=verbose,
7480
dds=[
7581
{
7682
"dd_data_set":{
@@ -94,6 +100,7 @@ def test_disposition_new(ansible_zos_module):
94100
for result in results.contacted.values():
95101
assert result.get("ret_code", {}).get("code", -1) == 0
96102
assert len(result.get("dd_names", [])) > 0
103+
assert result.get("failed", False) is False
97104
finally:
98105
hosts.all.zos_data_set(name=default_data_set, state="absent")
99106
if idcams_dataset:
@@ -2236,7 +2243,7 @@ def test_authorized_program_run_unauthorized(ansible_zos_module):
22362243
dds=[],
22372244
)
22382245
for result in results.contacted.values():
2239-
assert result.get("ret_code", {}).get("code", -1) == 8
2246+
assert result.get("ret_code", {}).get("code", -1) == 36
22402247
assert len(result.get("dd_names", [])) == 0
22412248
assert "BGYSC0236E" in result.get("msg", "")
22422249
finally:
@@ -2254,21 +2261,27 @@ def test_unauthorized_program_run_authorized(ansible_zos_module):
22542261
dds=[],
22552262
)
22562263
for result in results.contacted.values():
2257-
assert result.get("ret_code", {}).get("code", -1) == 8
2264+
assert result.get("ret_code", {}).get("code", -1) == 15
22582265
assert len(result.get("dd_names", [])) == 0
22592266
assert "BGYSC0215E" in result.get("msg", "")
22602267
finally:
22612268
hosts.all.zos_data_set(name=default_data_set, state="absent")
22622269

2263-
2264-
def test_authorized_program_run_authorized(ansible_zos_module):
2270+
@pytest.mark.parametrize(
2271+
# Added this verbose to test issue https://github.com/ansible-collections/ibm_zos_core/issues/1359
2272+
# Where a program will fail if rc != 0 only if verbose was True.
2273+
"verbose",
2274+
[True, False],
2275+
)
2276+
def test_authorized_program_run_authorized(ansible_zos_module, verbose):
22652277
try:
22662278
hosts = ansible_zos_module
22672279
default_data_set = get_tmp_ds_name()
22682280
hosts.all.zos_data_set(name=default_data_set, state="absent")
22692281
results = hosts.all.zos_mvs_raw(
22702282
program_name="idcams",
22712283
auth=True,
2284+
verbose=True,
22722285
dds=[
22732286
{
22742287
"dd_output":{

0 commit comments

Comments
 (0)