Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes zos_operator verbosity and excessive lines in content returned #400

Merged
merged 6 commits into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions changelogs/fragments/400-fixes-verbose-trailing-lines.yml
Original file line number Diff line number Diff line change
@@ -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).
16 changes: 7 additions & 9 deletions plugins/modules/zos_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -241,15 +237,17 @@ 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
ssctr = 0
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
Expand Down
27 changes: 16 additions & 11 deletions tests/functional/modules/test_zos_operator_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down