diff --git a/changelogs/fragments/400-fixes-verbose-trailing-lines.yml b/changelogs/fragments/400-fixes-verbose-trailing-lines.yml new file mode 100644 index 000000000..7acd6e7cb --- /dev/null +++ b/changelogs/fragments/400-fixes-verbose-trailing-lines.yml @@ -0,0 +1,7 @@ +bugfixes: + - > + zos_operator - was updated to correct missing verbosity content + when the option verbose was set to True. + zos_operator - was updated to correct the trailing lines that would appear + in the result content. + (https://github.com/ansible-collections/ibm_zos_core/pull/400). \ No newline at end of file diff --git a/plugins/modules/zos_operator.py b/plugins/modules/zos_operator.py index c8151c855..4b93bf8f3 100644 --- a/plugins/modules/zos_operator.py +++ b/plugins/modules/zos_operator.py @@ -39,12 +39,8 @@ required: true verbose: description: - - Return diagnostic messages that lists and describes the execution of the - operator commands. - - Return security trace messages that help you understand and diagnose the - execution of the operator commands - - Return trace instructions displaying how the the command's operation is - read, evaluated and executed. + - Return diagnostic messages that describes the commands execution, + options, buffer and response size. type: bool required: false default: false @@ -194,7 +190,7 @@ def execute_command(operator_cmd, timeout=1, *args, **kwargs): start = timer() - response = opercmd.execute(operator_cmd, timeout, args, kwargs) + response = opercmd.execute(operator_cmd, timeout, *args, **kwargs) end = timer() rc = response.rc stdout = response.stdout_response @@ -241,7 +237,8 @@ def run_module(): tstr = rc_message.get("stdout") if tstr is not None: for s in tstr.split("\n"): - result["content"].append(s) + if s: + result["content"].append(s) if ssctr < 5: short_str.append(s) ssctr += 1 @@ -249,7 +246,8 @@ def run_module(): tstr = rc_message.get("stderr") if tstr is not None: for s in tstr.split("\n"): - result["content"].append(s) + if s: + result["content"].append(s) if ssctr < 5: short_str.append(s) ssctr += 1 diff --git a/tests/functional/modules/test_zos_operator_func.py b/tests/functional/modules/test_zos_operator_func.py index b84bb693c..fad34cf78 100644 --- a/tests/functional/modules/test_zos_operator_func.py +++ b/tests/functional/modules/test_zos_operator_func.py @@ -68,20 +68,25 @@ def test_zos_operator_positive_path_verbose(ansible_zos_module): assert result["rc"] == 0 assert result.get("changed") is True assert result.get("content") is not None + # Traverse the content list for a known verbose keyword and track state + if any('BGYSC0804I' in str for str in result.get("content")): + is_verbose = True + assert is_verbose -# def test_zos_operator_positive_verbose_with_full_delay(ansible_zos_module): -# hosts = ansible_zos_module -# wait_time = 1 -# results = hosts.all.zos_operator( -# cmd="ENTER A LONG RUNNING CMD", verbose=True, wait_time_s=wait_time -# ) +def test_zos_operator_positive_verbose_with_full_delay(ansible_zos_module): + "Long running command should take over 30 seconds" + hosts = ansible_zos_module + wait_time = 10 + results = hosts.all.zos_operator( + cmd="RO *ALL,LOG 'dummy syslog message'", verbose=True, wait_time_s=wait_time + ) -# for result in results.contacted.values(): -# assert result["rc"] == 0 -# assert result.get("changed") is False -# assert result.get("content") is not None -# assert result.get("elapsed") > wait_time + for result in results.contacted.values(): + assert result["rc"] == 0 + assert result.get("changed") is True + assert result.get("content") is not None + assert result.get("elapsed") > wait_time def test_zos_operator_positive_verbose_with_quick_delay(ansible_zos_module):