From dfe1ba8abc883cfb259825d8167d07077c4cb67d Mon Sep 17 00:00:00 2001 From: Rich Parker Date: Tue, 19 Sep 2023 13:13:23 -0400 Subject: [PATCH 01/15] Change implemented in zos_operator Working on zos_operator_action_query Added initial changelog fragment --- ...nhance-Add-wait-zos-operator-and-query.yml | 5 +++++ plugins/modules/zos_operator.py | 22 +++++++++---------- plugins/modules/zos_operator_action_query.py | 2 ++ 3 files changed, 18 insertions(+), 11 deletions(-) create mode 100644 changelogs/fragments/943-enhance-Add-wait-zos-operator-and-query.yml diff --git a/changelogs/fragments/943-enhance-Add-wait-zos-operator-and-query.yml b/changelogs/fragments/943-enhance-Add-wait-zos-operator-and-query.yml new file mode 100644 index 000000000..4067471dc --- /dev/null +++ b/changelogs/fragments/943-enhance-Add-wait-zos-operator-and-query.yml @@ -0,0 +1,5 @@ +enhancements: + - zos_operator: Added the 'wait' parameter back in to use the new -w operator. + (https://github.com/ansible-collections/ibm_zos_core/pull/xxx) + - zos_operator_action_query: Add wait_time_s and 'wait' parameters in the operator_action_query. + (https://github.com/ansible-collections/ibm_zos_core/pull/xxx) \ No newline at end of file diff --git a/plugins/modules/zos_operator.py b/plugins/modules/zos_operator.py index 5bd04ba50..29fc25817 100644 --- a/plugins/modules/zos_operator.py +++ b/plugins/modules/zos_operator.py @@ -57,14 +57,11 @@ default: 1 wait: description: - - Configuring wait used by the L(zos_operator,./zos_operator.html) module - has been deprecated and will be removed in a future ibm.ibm_zos_core - collection. - - Setting this option will yield no change, it is deprecated. - - Review option I(wait_time_s) to instruct operator commands to wait. + - Setting this option will tell opercmd to wait the full wait_time, instead + of returning on first data received type: bool required: false - default: true + default: false """ EXAMPLES = r""" @@ -81,12 +78,13 @@ zos_operator: cmd: "\\$PJ(*)" -- name: Execute operator command to show jobs, waiting up to 5 seconds for response +- name: Execute operator command to show jobs, always waiting 8 seconds for response zos_operator: cmd: 'd a,all' wait_time_s: 5 + wait: true -- name: Execute operator command to show jobs, always waiting 7 seconds for response +- name: Execute operator command to show jobs, waiting up to 7 seconds for response zos_operator: cmd: 'd a,all' wait_time_s: 7 @@ -195,7 +193,7 @@ def run_module(): cmd=dict(type="str", required=True), verbose=dict(type="bool", required=False, default=False), wait_time_s=dict(type="int", required=False, default=1), - wait=dict(type="bool", required=False, default=True), + wait=dict(type="bool", required=False, default=False), ) result = dict(changed=False) @@ -266,8 +264,7 @@ def parse_params(params): cmd=dict(arg_type="str", required=True), verbose=dict(arg_type="bool", required=False), wait_time_s=dict(arg_type="int", required=False), - wait=dict(arg_type="bool", required=False, removed_at_date='2022-11-30', - removed_from_collection='ibm.ibm_zos_core'), + wait=dict(arg_type="bool", required=False), ) parser = BetterArgParser(arg_defs) new_params = parser.parse_args(params) @@ -286,6 +283,9 @@ def run_operator_command(params): wait_s = params.get("wait_time_s") cmdtxt = params.get("cmd") + if params.get("wait"): + kwargs.update({"wait_arg": True}) + args = [] rc, stdout, stderr, elapsed = execute_command(cmdtxt, timeout=wait_s, *args, **kwargs) diff --git a/plugins/modules/zos_operator_action_query.py b/plugins/modules/zos_operator_action_query.py index 10d096b48..0211f8a4b 100644 --- a/plugins/modules/zos_operator_action_query.py +++ b/plugins/modules/zos_operator_action_query.py @@ -398,6 +398,8 @@ def handle_conditions(list, condition_type, value): def execute_command(operator_cmd): response = opercmd.execute(operator_cmd) +# response = opercmd.execute(operator_cmd, timeout, *args, **kwargs) + rc = response.rc stdout = response.stdout_response stderr = response.stderr_response From 4961784de3b409eaa319d2de42db91c97a096354 Mon Sep 17 00:00:00 2001 From: Rich Parker Date: Wed, 20 Sep 2023 11:43:15 -0400 Subject: [PATCH 02/15] cleaned up note in zos_operator Added wait time and wait values to zoaq --- plugins/modules/zos_operator.py | 2 +- plugins/modules/zos_operator_action_query.py | 62 ++++++++++++++++++-- 2 files changed, 58 insertions(+), 6 deletions(-) diff --git a/plugins/modules/zos_operator.py b/plugins/modules/zos_operator.py index 29fc25817..2dfa12fdb 100644 --- a/plugins/modules/zos_operator.py +++ b/plugins/modules/zos_operator.py @@ -57,7 +57,7 @@ default: 1 wait: description: - - Setting this option will tell opercmd to wait the full wait_time, instead + - Setting this option will tell the system to wait the full wait_time, instead of returning on first data received type: bool required: false diff --git a/plugins/modules/zos_operator_action_query.py b/plugins/modules/zos_operator_action_query.py index 0211f8a4b..ddef406eb 100644 --- a/plugins/modules/zos_operator_action_query.py +++ b/plugins/modules/zos_operator_action_query.py @@ -57,6 +57,26 @@ - A trailing asterisk, (*) wildcard is supported. type: str required: false + wait_time_s: + description: + - Set maximum time in seconds to wait for the commands to execute. + - When set to 0, the system default is used. + - This option is helpful on a busy system requiring more time to execute + commands. + - Setting I(wait) can instruct if execution should wait the + full I(wait_time_s). + - Because 2 functions are called, potential time delay is doubled. + type: int + required: false + default: 1 + wait: + description: + - Setting this option will tell the system to wait the full wait_time, instead + of returning on first data received + - Because 2 functions are called, potential time delay is doubled. + type: bool + required: false + default: false message_filter: description: - Return outstanding messages requiring operator action awaiting a @@ -101,6 +121,19 @@ zos_operator_action_query: job_name: im5* +- name: Display all outstanding messages whose job name begin with im7, + wait up to 10 seconds per call (20 seconds overall) for data + zos_operator_action_query: + job_name: im7* + wait_time_s: 10 + +- name: Display all outstanding messages whose job name begin with im9, + wait up a full 15 seconds per call (30 seconds overall) for data + zos_operator_action_query: + job_name: im9* + wait_time_s: 15 + wait: True + - name: Display all outstanding messages whose message id begin with dsi* zos_operator_action_query: message_id: dsi* @@ -235,6 +268,8 @@ def run_module(): system=dict(type="str", required=False), message_id=dict(type="str", required=False), job_name=dict(type="str", required=False), + wait_time_s=dict(type="int", required=False, default=1), + wait=dict(type="bool", required=False, default=False), message_filter=dict( type="dict", required=False, @@ -251,7 +286,19 @@ def run_module(): try: new_params = parse_params(module.params) - cmd_result_a = execute_command("d r,a,s") + kwargs = {} + + wait_s = params.get("wait_time_s") + + if new_params.get("wait"): + kwargs.update({"wait_arg": True}) + + args = [] + + cmdtxt = "d r,a,s" + + cmd_result_a = execute_command(cmdtxt, timeout=wait_s, *args, **kwargs) + if cmd_result_a.rc > 0: module.fail_json( msg="A non-zero return code was received while querying the operator.", @@ -263,7 +310,10 @@ def run_module(): cmd="d r,a,s", ) - cmd_result_b = execute_command("d r,a,jn") + cmdtxt = new_params.get("d r,a,jn") + + cmd_result_b = execute_command(cmdtxt, timeout=wait_s, *args, **kwargs) + if cmd_result_b.rc > 0: module.fail_json( msg="A non-zero return code was received while querying the operator.", @@ -295,6 +345,8 @@ def parse_params(params): system=dict(arg_type=system_type, required=False), message_id=dict(arg_type=message_id_type, required=False), job_name=dict(arg_type=job_name_type, required=False), + wait_time_s=dict(arg_type="int", required=False), + wait=dict(arg_type="bool", required=False), message_filter=dict(arg_type=message_filter_type, required=False) ) parser = BetterArgParser(arg_defs) @@ -395,10 +447,10 @@ def handle_conditions(list, condition_type, value): return newlist -def execute_command(operator_cmd): +def execute_command(operator_cmd, timeout=1, *args, **kwargs): - response = opercmd.execute(operator_cmd) -# response = opercmd.execute(operator_cmd, timeout, *args, **kwargs) + # response = opercmd.execute(operator_cmd) + response = opercmd.execute(operator_cmd, timeout, *args, **kwargs) rc = response.rc stdout = response.stdout_response From 9136715656a6511581278105c30e3dc4850d8ad7 Mon Sep 17 00:00:00 2001 From: Rich Parker Date: Wed, 20 Sep 2023 11:59:55 -0400 Subject: [PATCH 03/15] corrected pep8/pylint errors --- plugins/modules/zos_operator.py | 2 +- plugins/modules/zos_operator_action_query.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/modules/zos_operator.py b/plugins/modules/zos_operator.py index 2dfa12fdb..c34d64818 100644 --- a/plugins/modules/zos_operator.py +++ b/plugins/modules/zos_operator.py @@ -284,7 +284,7 @@ def run_operator_command(params): cmdtxt = params.get("cmd") if params.get("wait"): - kwargs.update({"wait_arg": True}) + kwargs.update({"wait_arg": True}) args = [] rc, stdout, stderr, elapsed = execute_command(cmdtxt, timeout=wait_s, *args, **kwargs) diff --git a/plugins/modules/zos_operator_action_query.py b/plugins/modules/zos_operator_action_query.py index ddef406eb..9abd8e493 100644 --- a/plugins/modules/zos_operator_action_query.py +++ b/plugins/modules/zos_operator_action_query.py @@ -288,7 +288,7 @@ def run_module(): kwargs = {} - wait_s = params.get("wait_time_s") + wait_s = new_params.get("wait_time_s") if new_params.get("wait"): kwargs.update({"wait_arg": True}) From ac8acd5d38095d6bbb435a87916b1766a6edd95e Mon Sep 17 00:00:00 2001 From: Rich Parker Date: Wed, 20 Sep 2023 12:48:51 -0400 Subject: [PATCH 04/15] added output to failing test --- .../modules/test_zos_operator_action_query_func.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/functional/modules/test_zos_operator_action_query_func.py b/tests/functional/modules/test_zos_operator_action_query_func.py index 4872a2a02..ce60e9588 100644 --- a/tests/functional/modules/test_zos_operator_action_query_func.py +++ b/tests/functional/modules/test_zos_operator_action_query_func.py @@ -23,14 +23,19 @@ def test_zos_operator_action_query_no_options(ansible_zos_module): hosts.all.zos_operator(cmd="DUMP COMM=('test dump')") results = hosts.all.zos_operator_action_query() try: + print( "\n\n=========== in no-options loop 1") for action in results.get("actions"): + print( action.get("message_text", "-no-")) if "SPECIFY OPERAND(S) FOR DUMP" in action.get("message_text", ""): hosts.all.zos_operator( cmd="{0}cancel".format(action.get("number"))) except Exception: pass + + print( "\n\n=============== in no-options loop 2") for result in results.contacted.values(): - assert result.get("actions") + print( result ) + # assert result.get("actions") def test_zos_operator_action_query_option_message_id(ansible_zos_module): hosts = ansible_zos_module From bb190304e6928dd1d23cf1f0fb684a3ca3c8ce34 Mon Sep 17 00:00:00 2001 From: Rich Parker Date: Wed, 20 Sep 2023 13:00:40 -0400 Subject: [PATCH 05/15] added another test print, since the test error moved --- tests/functional/modules/test_zos_operator_func.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/functional/modules/test_zos_operator_func.py b/tests/functional/modules/test_zos_operator_func.py index 84f593f51..6843a5678 100644 --- a/tests/functional/modules/test_zos_operator_func.py +++ b/tests/functional/modules/test_zos_operator_func.py @@ -41,6 +41,8 @@ def test_zos_operator_various_command(ansible_zos_module): hosts = ansible_zos_module results = hosts.all.zos_operator(cmd=command) for result in results.contacted.values(): + print( "\n\n===result:" ) + print( result ) assert result["rc"] == expected_rc assert result.get("changed") is changed From e7f02a2974274cae243e0fb5e4ec8a165e949817 Mon Sep 17 00:00:00 2001 From: Rich Parker Date: Wed, 20 Sep 2023 13:22:38 -0400 Subject: [PATCH 06/15] added print and un-commented upper assertion --- .../modules/test_zos_operator_action_query_func.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/functional/modules/test_zos_operator_action_query_func.py b/tests/functional/modules/test_zos_operator_action_query_func.py index ce60e9588..76dbc5d83 100644 --- a/tests/functional/modules/test_zos_operator_action_query_func.py +++ b/tests/functional/modules/test_zos_operator_action_query_func.py @@ -35,7 +35,7 @@ def test_zos_operator_action_query_no_options(ansible_zos_module): print( "\n\n=============== in no-options loop 2") for result in results.contacted.values(): print( result ) - # assert result.get("actions") + assert result.get("actions") def test_zos_operator_action_query_option_message_id(ansible_zos_module): hosts = ansible_zos_module @@ -48,7 +48,10 @@ def test_zos_operator_action_query_option_message_id(ansible_zos_module): cmd="{0}cancel".format(action.get("number"))) except Exception: pass + + print( "\n\n=============== in msgid loop 2") for result in results.contacted.values(): + print( result ) assert result.get("actions") def test_zos_operator_action_query_option_message_id_invalid_abbreviation( From 15371f669dd1d76a5011b64720d3b328b30a58c8 Mon Sep 17 00:00:00 2001 From: Rich Parker Date: Wed, 20 Sep 2023 16:14:19 -0400 Subject: [PATCH 07/15] removed embedded print statements, changed \$ to '$ to eliminate deprecation warning --- .../modules/test_zos_operator_action_query_func.py | 9 +-------- tests/functional/modules/test_zos_operator_func.py | 5 +---- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/tests/functional/modules/test_zos_operator_action_query_func.py b/tests/functional/modules/test_zos_operator_action_query_func.py index 76dbc5d83..30f5175e4 100644 --- a/tests/functional/modules/test_zos_operator_action_query_func.py +++ b/tests/functional/modules/test_zos_operator_action_query_func.py @@ -16,25 +16,21 @@ __metaclass__ = type import pytest -import unittest + def test_zos_operator_action_query_no_options(ansible_zos_module): hosts = ansible_zos_module hosts.all.zos_operator(cmd="DUMP COMM=('test dump')") results = hosts.all.zos_operator_action_query() try: - print( "\n\n=========== in no-options loop 1") for action in results.get("actions"): - print( action.get("message_text", "-no-")) if "SPECIFY OPERAND(S) FOR DUMP" in action.get("message_text", ""): hosts.all.zos_operator( cmd="{0}cancel".format(action.get("number"))) except Exception: pass - print( "\n\n=============== in no-options loop 2") for result in results.contacted.values(): - print( result ) assert result.get("actions") def test_zos_operator_action_query_option_message_id(ansible_zos_module): @@ -49,9 +45,7 @@ def test_zos_operator_action_query_option_message_id(ansible_zos_module): except Exception: pass - print( "\n\n=============== in msgid loop 2") for result in results.contacted.values(): - print( result ) assert result.get("actions") def test_zos_operator_action_query_option_message_id_invalid_abbreviation( @@ -275,7 +269,6 @@ def test_zos_operator_action_query_option_message_filter_multiple_matches( except Exception: pass for result in results.contacted.values(): - print(result.get("actions")) assert result.get("actions") assert len(result.get("actions")) > 1 diff --git a/tests/functional/modules/test_zos_operator_func.py b/tests/functional/modules/test_zos_operator_func.py index 6843a5678..5ce87370d 100644 --- a/tests/functional/modules/test_zos_operator_func.py +++ b/tests/functional/modules/test_zos_operator_func.py @@ -41,8 +41,6 @@ def test_zos_operator_various_command(ansible_zos_module): hosts = ansible_zos_module results = hosts.all.zos_operator(cmd=command) for result in results.contacted.values(): - print( "\n\n===result:" ) - print( result ) assert result["rc"] == expected_rc assert result.get("changed") is changed @@ -114,7 +112,6 @@ def test_zos_operator_positive_verbose_with_quick_delay(ansible_zos_module): # assert timediff < 15 for result in results.contacted.values(): - pprint(result) assert result["rc"] == 0 assert result.get("changed") is True assert result.get("content") is not None @@ -124,7 +121,7 @@ def test_zos_operator_positive_verbose_with_quick_delay(ansible_zos_module): def test_response_come_back_complete(ansible_zos_module): hosts = ansible_zos_module - results = hosts.all.zos_operator(cmd="\$dspl") + results = hosts.all.zos_operator(cmd='$dspl') # \$ triggers warning res = dict() res["stdout"] = [] for result in results.contacted.values(): From 93573e1a02765cddda81148948aaf1e74bdf4414 Mon Sep 17 00:00:00 2001 From: Rich Parker Date: Wed, 20 Sep 2023 16:28:16 -0400 Subject: [PATCH 08/15] switch test back to "\$ --- tests/functional/modules/test_zos_operator_func.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/modules/test_zos_operator_func.py b/tests/functional/modules/test_zos_operator_func.py index 5ce87370d..4ad07d882 100644 --- a/tests/functional/modules/test_zos_operator_func.py +++ b/tests/functional/modules/test_zos_operator_func.py @@ -121,7 +121,7 @@ def test_zos_operator_positive_verbose_with_quick_delay(ansible_zos_module): def test_response_come_back_complete(ansible_zos_module): hosts = ansible_zos_module - results = hosts.all.zos_operator(cmd='$dspl') # \$ triggers warning + results = hosts.all.zos_operator(cmd="\$dspl") res = dict() res["stdout"] = [] for result in results.contacted.values(): From 959e0c3c4cdde6e5b05829e5f1c0be151fbcf947 Mon Sep 17 00:00:00 2001 From: Rich Parker Date: Wed, 20 Sep 2023 17:43:53 -0400 Subject: [PATCH 09/15] correction to zos_operator_action_query to pass the second query cmd correctly --- plugins/modules/zos_operator_action_query.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/zos_operator_action_query.py b/plugins/modules/zos_operator_action_query.py index 9abd8e493..4270e33c8 100644 --- a/plugins/modules/zos_operator_action_query.py +++ b/plugins/modules/zos_operator_action_query.py @@ -310,7 +310,7 @@ def run_module(): cmd="d r,a,s", ) - cmdtxt = new_params.get("d r,a,jn") + cmdtxt = "d r,a,jn" cmd_result_b = execute_command(cmdtxt, timeout=wait_s, *args, **kwargs) From a97234d40a2a6987ce7e5e49e59a24e0c414caa3 Mon Sep 17 00:00:00 2001 From: Rich Parker Date: Thu, 21 Sep 2023 09:48:21 -0400 Subject: [PATCH 10/15] Added PR# to changelog tweaked description of new feature in both affected functions. --- .../943-enhance-Add-wait-zos-operator-and-query.yml | 5 +++-- plugins/modules/zos_operator.py | 2 +- plugins/modules/zos_operator_action_query.py | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/changelogs/fragments/943-enhance-Add-wait-zos-operator-and-query.yml b/changelogs/fragments/943-enhance-Add-wait-zos-operator-and-query.yml index 4067471dc..59547c8d4 100644 --- a/changelogs/fragments/943-enhance-Add-wait-zos-operator-and-query.yml +++ b/changelogs/fragments/943-enhance-Add-wait-zos-operator-and-query.yml @@ -1,5 +1,6 @@ enhancements: - zos_operator: Added the 'wait' parameter back in to use the new -w operator. - (https://github.com/ansible-collections/ibm_zos_core/pull/xxx) + (https://github.com/ansible-collections/ibm_zos_core/pull/976) - zos_operator_action_query: Add wait_time_s and 'wait' parameters in the operator_action_query. - (https://github.com/ansible-collections/ibm_zos_core/pull/xxx) \ No newline at end of file + (https://github.com/ansible-collections/ibm_zos_core/pull/976) + diff --git a/plugins/modules/zos_operator.py b/plugins/modules/zos_operator.py index c34d64818..9df17799f 100644 --- a/plugins/modules/zos_operator.py +++ b/plugins/modules/zos_operator.py @@ -78,7 +78,7 @@ zos_operator: cmd: "\\$PJ(*)" -- name: Execute operator command to show jobs, always waiting 8 seconds for response +- name: Execute operator command to show jobs, always waiting 5 seconds for response zos_operator: cmd: 'd a,all' wait_time_s: 5 diff --git a/plugins/modules/zos_operator_action_query.py b/plugins/modules/zos_operator_action_query.py index 4270e33c8..026a8343a 100644 --- a/plugins/modules/zos_operator_action_query.py +++ b/plugins/modules/zos_operator_action_query.py @@ -128,7 +128,7 @@ wait_time_s: 10 - name: Display all outstanding messages whose job name begin with im9, - wait up a full 15 seconds per call (30 seconds overall) for data + wait a full 15 seconds per call (30 seconds overall) for data zos_operator_action_query: job_name: im9* wait_time_s: 15 From ab780d2decc46a43d077046e155aa587319b69f8 Mon Sep 17 00:00:00 2001 From: Rich Parker Date: Fri, 22 Sep 2023 12:25:32 -0400 Subject: [PATCH 11/15] Added zoau_api_version logic to check for 1.2.5 or later as a condition for wait_arg Added mention of this to documentation of interface --- plugins/modules/zos_operator.py | 24 ++++++++++++++++++-- plugins/modules/zos_operator_action_query.py | 24 ++++++++++++++++++-- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/plugins/modules/zos_operator.py b/plugins/modules/zos_operator.py index 9df17799f..76b894425 100644 --- a/plugins/modules/zos_operator.py +++ b/plugins/modules/zos_operator.py @@ -59,6 +59,7 @@ description: - Setting this option will tell the system to wait the full wait_time, instead of returning on first data received + - This option is only available with zoau 1.2.5 or later type: bool required: false default: false @@ -176,6 +177,11 @@ except Exception: opercmd = MissingZOAUImport() +try: + from zoautil_py import ZOAU_API_VERSION +except Exception: + ZOAU_API_VERSION = "1.2.0" + def execute_command(operator_cmd, timeout=1, *args, **kwargs): start = timer() @@ -283,8 +289,22 @@ def run_operator_command(params): wait_s = params.get("wait_time_s") cmdtxt = params.get("cmd") - if params.get("wait"): - kwargs.update({"wait_arg": True}) + zv = ZOAU_API_VERSION.split(".") + getit = False + if( zv[0] > "1"): + getit = True + elif( zv[0] == "1" and zv[1] > "2"): + getit = True + elif( zv[0] == "1" and zv[1] == "2" and zv[2] > "4"): + getit = True + + if getit: + if params.get("wait"): + kwargs.update({"wait_arg": True}) + else: + kwargs.pop("wait_arg", "0") + else: + kwargs.pop("wait_arg", "0") args = [] rc, stdout, stderr, elapsed = execute_command(cmdtxt, timeout=wait_s, *args, **kwargs) diff --git a/plugins/modules/zos_operator_action_query.py b/plugins/modules/zos_operator_action_query.py index 026a8343a..0b340f936 100644 --- a/plugins/modules/zos_operator_action_query.py +++ b/plugins/modules/zos_operator_action_query.py @@ -74,6 +74,7 @@ - Setting this option will tell the system to wait the full wait_time, instead of returning on first data received - Because 2 functions are called, potential time delay is doubled. + - This option is only available with zoau 1.2.5 or later type: bool required: false default: false @@ -262,6 +263,11 @@ except Exception: opercmd = MissingZOAUImport() +try: + from zoautil_py import ZOAU_API_VERSION +except Exception: + ZOAU_API_VERSION = "1.2.0" + def run_module(): module_args = dict( @@ -290,8 +296,22 @@ def run_module(): wait_s = new_params.get("wait_time_s") - if new_params.get("wait"): - kwargs.update({"wait_arg": True}) + zv = ZOAU_API_VERSION.split(".") + getit = False + if( zv[0] > "1"): + getit = True + elif( zv[0] == "1" and zv[1] > "2"): + getit = True + elif( zv[0] == "1" and zv[1] == "2" and zv[2] > "4"): + getit = True + + if getit: + if new_params.get("wait"): + kwargs.update({"wait_arg": True}) + else: + kwargs.pop("wait_arg", "0") + else: + kwargs.pop("wait_arg", "0") args = [] From a8f74262389e181ddb961e7d6f31df7407467085 Mon Sep 17 00:00:00 2001 From: Rich Parker Date: Fri, 22 Sep 2023 12:55:37 -0400 Subject: [PATCH 12/15] corrected pep8 errors --- plugins/modules/zos_operator.py | 14 +++++++------- plugins/modules/zos_operator_action_query.py | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/plugins/modules/zos_operator.py b/plugins/modules/zos_operator.py index 76b894425..35f155e65 100644 --- a/plugins/modules/zos_operator.py +++ b/plugins/modules/zos_operator.py @@ -291,18 +291,18 @@ def run_operator_command(params): zv = ZOAU_API_VERSION.split(".") getit = False - if( zv[0] > "1"): + if zv[0] > "1": getit = True - elif( zv[0] == "1" and zv[1] > "2"): + elif zv[0] == "1" and zv[1] > "2": getit = True - elif( zv[0] == "1" and zv[1] == "2" and zv[2] > "4"): + elif zv[0] == "1" and zv[1] == "2" and zv[2] > "4": getit = True if getit: - if params.get("wait"): - kwargs.update({"wait_arg": True}) - else: - kwargs.pop("wait_arg", "0") + if params.get("wait"): + kwargs.update({"wait_arg": True}) + else: + kwargs.pop("wait_arg", "0") else: kwargs.pop("wait_arg", "0") diff --git a/plugins/modules/zos_operator_action_query.py b/plugins/modules/zos_operator_action_query.py index 0b340f936..77d130697 100644 --- a/plugins/modules/zos_operator_action_query.py +++ b/plugins/modules/zos_operator_action_query.py @@ -298,11 +298,11 @@ def run_module(): zv = ZOAU_API_VERSION.split(".") getit = False - if( zv[0] > "1"): + if zv[0] > "1": getit = True - elif( zv[0] == "1" and zv[1] > "2"): + elif zv[0] == "1" and zv[1] > "2": getit = True - elif( zv[0] == "1" and zv[1] == "2" and zv[2] > "4"): + elif zv[0] == "1" and zv[1] == "2" and zv[2] > "4": getit = True if getit: From 0e2fb96338e0457f9095619f41b6a7f9fbda63ab Mon Sep 17 00:00:00 2001 From: Rich Parker Date: Wed, 4 Oct 2023 11:21:00 -0400 Subject: [PATCH 13/15] Changed Enhancements to minor_changes --- .../fragments/943-enhance-Add-wait-zos-operator-and-query.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelogs/fragments/943-enhance-Add-wait-zos-operator-and-query.yml b/changelogs/fragments/943-enhance-Add-wait-zos-operator-and-query.yml index 59547c8d4..71e24fc14 100644 --- a/changelogs/fragments/943-enhance-Add-wait-zos-operator-and-query.yml +++ b/changelogs/fragments/943-enhance-Add-wait-zos-operator-and-query.yml @@ -1,4 +1,4 @@ -enhancements: +minor_changes: - zos_operator: Added the 'wait' parameter back in to use the new -w operator. (https://github.com/ansible-collections/ibm_zos_core/pull/976) - zos_operator_action_query: Add wait_time_s and 'wait' parameters in the operator_action_query. From dd10d0d9065fb27eefcefda11eccba1b1b8cfa97 Mon Sep 17 00:00:00 2001 From: Rich Parker Date: Fri, 6 Oct 2023 15:15:06 -0400 Subject: [PATCH 14/15] Removed 'wait' as an option, and pass wait_arg=true to zoau --- ...nhance-Add-wait-zos-operator-and-query.yml | 4 ++-- plugins/modules/zos_operator.py | 23 +------------------ plugins/modules/zos_operator_action_query.py | 23 ++----------------- 3 files changed, 5 insertions(+), 45 deletions(-) diff --git a/changelogs/fragments/943-enhance-Add-wait-zos-operator-and-query.yml b/changelogs/fragments/943-enhance-Add-wait-zos-operator-and-query.yml index 71e24fc14..dd1829148 100644 --- a/changelogs/fragments/943-enhance-Add-wait-zos-operator-and-query.yml +++ b/changelogs/fragments/943-enhance-Add-wait-zos-operator-and-query.yml @@ -1,6 +1,6 @@ minor_changes: - - zos_operator: Added the 'wait' parameter back in to use the new -w operator. + - zos_operator: Changed system to call 'wait=true' parameter to zoau call. (https://github.com/ansible-collections/ibm_zos_core/pull/976) - - zos_operator_action_query: Add wait_time_s and 'wait' parameters in the operator_action_query. + - zos_operator_action_query: Add wait_time_s parameter in the operator_action_query. (https://github.com/ansible-collections/ibm_zos_core/pull/976) diff --git a/plugins/modules/zos_operator.py b/plugins/modules/zos_operator.py index 35f155e65..ab34aa0cc 100644 --- a/plugins/modules/zos_operator.py +++ b/plugins/modules/zos_operator.py @@ -55,14 +55,6 @@ type: int required: false default: 1 - wait: - description: - - Setting this option will tell the system to wait the full wait_time, instead - of returning on first data received - - This option is only available with zoau 1.2.5 or later - type: bool - required: false - default: false """ EXAMPLES = r""" @@ -83,12 +75,6 @@ zos_operator: cmd: 'd a,all' wait_time_s: 5 - wait: true - -- name: Execute operator command to show jobs, waiting up to 7 seconds for response - zos_operator: - cmd: 'd a,all' - wait_time_s: 7 - name: Display the system symbols and associated substitution texts. zos_operator: @@ -199,7 +185,6 @@ def run_module(): cmd=dict(type="str", required=True), verbose=dict(type="bool", required=False, default=False), wait_time_s=dict(type="int", required=False, default=1), - wait=dict(type="bool", required=False, default=False), ) result = dict(changed=False) @@ -270,7 +255,6 @@ def parse_params(params): cmd=dict(arg_type="str", required=True), verbose=dict(arg_type="bool", required=False), wait_time_s=dict(arg_type="int", required=False), - wait=dict(arg_type="bool", required=False), ) parser = BetterArgParser(arg_defs) new_params = parser.parse_args(params) @@ -299,12 +283,7 @@ def run_operator_command(params): getit = True if getit: - if params.get("wait"): - kwargs.update({"wait_arg": True}) - else: - kwargs.pop("wait_arg", "0") - else: - kwargs.pop("wait_arg", "0") + kwargs.update({"wait_arg": True}) args = [] rc, stdout, stderr, elapsed = execute_command(cmdtxt, timeout=wait_s, *args, **kwargs) diff --git a/plugins/modules/zos_operator_action_query.py b/plugins/modules/zos_operator_action_query.py index 77d130697..877b265e5 100644 --- a/plugins/modules/zos_operator_action_query.py +++ b/plugins/modules/zos_operator_action_query.py @@ -63,21 +63,10 @@ - When set to 0, the system default is used. - This option is helpful on a busy system requiring more time to execute commands. - - Setting I(wait) can instruct if execution should wait the - full I(wait_time_s). - Because 2 functions are called, potential time delay is doubled. type: int required: false default: 1 - wait: - description: - - Setting this option will tell the system to wait the full wait_time, instead - of returning on first data received - - Because 2 functions are called, potential time delay is doubled. - - This option is only available with zoau 1.2.5 or later - type: bool - required: false - default: false message_filter: description: - Return outstanding messages requiring operator action awaiting a @@ -123,7 +112,7 @@ job_name: im5* - name: Display all outstanding messages whose job name begin with im7, - wait up to 10 seconds per call (20 seconds overall) for data + waiting 10 seconds per call (20 seconds overall) for data zos_operator_action_query: job_name: im7* wait_time_s: 10 @@ -133,7 +122,6 @@ zos_operator_action_query: job_name: im9* wait_time_s: 15 - wait: True - name: Display all outstanding messages whose message id begin with dsi* zos_operator_action_query: @@ -275,7 +263,6 @@ def run_module(): message_id=dict(type="str", required=False), job_name=dict(type="str", required=False), wait_time_s=dict(type="int", required=False, default=1), - wait=dict(type="bool", required=False, default=False), message_filter=dict( type="dict", required=False, @@ -306,12 +293,7 @@ def run_module(): getit = True if getit: - if new_params.get("wait"): - kwargs.update({"wait_arg": True}) - else: - kwargs.pop("wait_arg", "0") - else: - kwargs.pop("wait_arg", "0") + kwargs.update({"wait_arg": True}) args = [] @@ -366,7 +348,6 @@ def parse_params(params): message_id=dict(arg_type=message_id_type, required=False), job_name=dict(arg_type=job_name_type, required=False), wait_time_s=dict(arg_type="int", required=False), - wait=dict(arg_type="bool", required=False), message_filter=dict(arg_type=message_filter_type, required=False) ) parser = BetterArgParser(arg_defs) From 60250ee2065a361b2a491f2fc98157f473931e53 Mon Sep 17 00:00:00 2001 From: Rich Parker Date: Mon, 9 Oct 2023 14:16:49 -0400 Subject: [PATCH 15/15] Changed operator_action_query to wait=false time = 5 Renamed vague variable name to "use_wait_arg" Reflected changes and 1.2.5 dependancy in the changelog fragment --- ...nhance-Add-wait-zos-operator-and-query.yml | 4 +- plugins/modules/zos_operator.py | 10 ++--- plugins/modules/zos_operator_action_query.py | 40 +++++-------------- 3 files changed, 17 insertions(+), 37 deletions(-) diff --git a/changelogs/fragments/943-enhance-Add-wait-zos-operator-and-query.yml b/changelogs/fragments/943-enhance-Add-wait-zos-operator-and-query.yml index dd1829148..5a8202c34 100644 --- a/changelogs/fragments/943-enhance-Add-wait-zos-operator-and-query.yml +++ b/changelogs/fragments/943-enhance-Add-wait-zos-operator-and-query.yml @@ -1,6 +1,8 @@ minor_changes: - zos_operator: Changed system to call 'wait=true' parameter to zoau call. + Requires zoau 1.2.5 or later. (https://github.com/ansible-collections/ibm_zos_core/pull/976) - - zos_operator_action_query: Add wait_time_s parameter in the operator_action_query. + - zos_operator_action_query: Add a max delay of 5 seconds on each part of the operator_action_query. + Requires zoau 1.2.5 or later. (https://github.com/ansible-collections/ibm_zos_core/pull/976) diff --git a/plugins/modules/zos_operator.py b/plugins/modules/zos_operator.py index ab34aa0cc..2d1fb807f 100644 --- a/plugins/modules/zos_operator.py +++ b/plugins/modules/zos_operator.py @@ -274,15 +274,15 @@ def run_operator_command(params): cmdtxt = params.get("cmd") zv = ZOAU_API_VERSION.split(".") - getit = False + use_wait_arg = False if zv[0] > "1": - getit = True + use_wait_arg = True elif zv[0] == "1" and zv[1] > "2": - getit = True + use_wait_arg = True elif zv[0] == "1" and zv[1] == "2" and zv[2] > "4": - getit = True + use_wait_arg = True - if getit: + if use_wait_arg: kwargs.update({"wait_arg": True}) args = [] diff --git a/plugins/modules/zos_operator_action_query.py b/plugins/modules/zos_operator_action_query.py index 877b265e5..ddf895eb9 100644 --- a/plugins/modules/zos_operator_action_query.py +++ b/plugins/modules/zos_operator_action_query.py @@ -29,6 +29,8 @@ - "Ping Xiao (@xiaoping8385)" - "Demetrios Dimatos (@ddimatos)" - "Ivan Moreno (@rexemin)" + - "Rich Parker (@richp405)" + options: system: description: @@ -57,16 +59,6 @@ - A trailing asterisk, (*) wildcard is supported. type: str required: false - wait_time_s: - description: - - Set maximum time in seconds to wait for the commands to execute. - - When set to 0, the system default is used. - - This option is helpful on a busy system requiring more time to execute - commands. - - Because 2 functions are called, potential time delay is doubled. - type: int - required: false - default: 1 message_filter: description: - Return outstanding messages requiring operator action awaiting a @@ -111,18 +103,6 @@ zos_operator_action_query: job_name: im5* -- name: Display all outstanding messages whose job name begin with im7, - waiting 10 seconds per call (20 seconds overall) for data - zos_operator_action_query: - job_name: im7* - wait_time_s: 10 - -- name: Display all outstanding messages whose job name begin with im9, - wait a full 15 seconds per call (30 seconds overall) for data - zos_operator_action_query: - job_name: im9* - wait_time_s: 15 - - name: Display all outstanding messages whose message id begin with dsi* zos_operator_action_query: message_id: dsi* @@ -262,7 +242,6 @@ def run_module(): system=dict(type="str", required=False), message_id=dict(type="str", required=False), job_name=dict(type="str", required=False), - wait_time_s=dict(type="int", required=False, default=1), message_filter=dict( type="dict", required=False, @@ -281,19 +260,19 @@ def run_module(): kwargs = {} - wait_s = new_params.get("wait_time_s") + wait_s = 5 zv = ZOAU_API_VERSION.split(".") - getit = False + use_wait_arg = False if zv[0] > "1": - getit = True + use_wait_arg = True elif zv[0] == "1" and zv[1] > "2": - getit = True + use_wait_arg = True elif zv[0] == "1" and zv[1] == "2" and zv[2] > "4": - getit = True + use_wait_arg = True - if getit: - kwargs.update({"wait_arg": True}) + if use_wait_arg: + kwargs.update({"wait_arg": False}) args = [] @@ -347,7 +326,6 @@ def parse_params(params): system=dict(arg_type=system_type, required=False), message_id=dict(arg_type=message_id_type, required=False), job_name=dict(arg_type=job_name_type, required=False), - wait_time_s=dict(arg_type="int", required=False), message_filter=dict(arg_type=message_filter_type, required=False) ) parser = BetterArgParser(arg_defs)