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..5a8202c34 --- /dev/null +++ b/changelogs/fragments/943-enhance-Add-wait-zos-operator-and-query.yml @@ -0,0 +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 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 5bd04ba50..2d1fb807f 100644 --- a/plugins/modules/zos_operator.py +++ b/plugins/modules/zos_operator.py @@ -55,16 +55,6 @@ type: int required: false 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. - type: bool - required: false - default: true """ EXAMPLES = r""" @@ -81,16 +71,11 @@ 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 5 seconds for response zos_operator: cmd: 'd a,all' wait_time_s: 5 -- name: Execute operator command to show jobs, always waiting 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: cmd: 'D SYMBOLS' @@ -178,6 +163,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() @@ -195,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=True), ) result = dict(changed=False) @@ -266,8 +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, removed_at_date='2022-11-30', - removed_from_collection='ibm.ibm_zos_core'), ) parser = BetterArgParser(arg_defs) new_params = parser.parse_args(params) @@ -286,6 +273,18 @@ def run_operator_command(params): wait_s = params.get("wait_time_s") cmdtxt = params.get("cmd") + zv = ZOAU_API_VERSION.split(".") + use_wait_arg = False + if zv[0] > "1": + use_wait_arg = True + elif zv[0] == "1" and zv[1] > "2": + use_wait_arg = True + elif zv[0] == "1" and zv[1] == "2" and zv[2] > "4": + use_wait_arg = True + + if use_wait_arg: + 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..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: @@ -229,6 +231,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( @@ -251,7 +258,28 @@ def run_module(): try: new_params = parse_params(module.params) - cmd_result_a = execute_command("d r,a,s") + kwargs = {} + + wait_s = 5 + + zv = ZOAU_API_VERSION.split(".") + use_wait_arg = False + if zv[0] > "1": + use_wait_arg = True + elif zv[0] == "1" and zv[1] > "2": + use_wait_arg = True + elif zv[0] == "1" and zv[1] == "2" and zv[2] > "4": + use_wait_arg = True + + if use_wait_arg: + kwargs.update({"wait_arg": False}) + + 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 +291,10 @@ def run_module(): cmd="d r,a,s", ) - cmd_result_b = execute_command("d r,a,jn") + cmdtxt = "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.", @@ -395,9 +426,11 @@ 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) rc = response.rc stdout = response.stdout_response stderr = response.stderr_response 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..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,7 +16,7 @@ __metaclass__ = type import pytest -import unittest + def test_zos_operator_action_query_no_options(ansible_zos_module): hosts = ansible_zos_module @@ -29,6 +29,7 @@ def test_zos_operator_action_query_no_options(ansible_zos_module): cmd="{0}cancel".format(action.get("number"))) except Exception: pass + for result in results.contacted.values(): assert result.get("actions") @@ -43,6 +44,7 @@ def test_zos_operator_action_query_option_message_id(ansible_zos_module): cmd="{0}cancel".format(action.get("number"))) except Exception: pass + for result in results.contacted.values(): assert result.get("actions") @@ -267,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 84f593f51..4ad07d882 100644 --- a/tests/functional/modules/test_zos_operator_func.py +++ b/tests/functional/modules/test_zos_operator_func.py @@ -112,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