Skip to content

Commit d0fcaa5

Browse files
[Enhancement][zos_operator_action_query] Module interface update (#2218)
* Added changes to the options in zos_operator_action_query * Modified tests for test_zos_operator_action_query regarding option names * Updated literal default value to true * Updated ocurrences of message to msg * Updated test with new msg_ instead of message_ * Updated unit tests and date * Updated date in unit tests * Updated zos_operator_action_query with aliases * Added a missing comma * Ensured that all values are always returned * Updated zos_operator_action_query * Added changelog * Corrected doc
1 parent 3e7ec31 commit d0fcaa5

File tree

4 files changed

+174
-132
lines changed

4 files changed

+174
-132
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
breaking_changes:
2+
- zos_job_query - Option ``message_filter`` is deprecated in favor of ``msg_filter``. Option ``message_id`` is deprecated in favor of ``msg_id``.
3+
Return value ``message_id`` is deprecated in favor of ``msg_id``. Return value ``message_text`` is deprecated in favor of ``msg_txt``.
4+
(https://github.com/ansible-collections/ibm_zos_core/pull/2218).

plugins/modules/zos_operator_action_query.py

Lines changed: 61 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
- "Demetrios Dimatos (@ddimatos)"
3131
- "Ivan Moreno (@rexemin)"
3232
- "Rich Parker (@richp405)"
33+
- "Fernando Flores (@fernandofloresg)"
3334
3435
options:
3536
system:
@@ -41,7 +42,7 @@
4142
- A trailing asterisk, (*) wildcard is supported.
4243
type: str
4344
required: false
44-
message_id:
45+
msg_id:
4546
description:
4647
- Return outstanding messages requiring operator action awaiting a
4748
reply for a particular message identifier.
@@ -50,6 +51,7 @@
5051
- A trailing asterisk, (*) wildcard is supported.
5152
type: str
5253
required: false
54+
aliases: [ message_id ]
5355
job_name:
5456
description:
5557
- Return outstanding messages requiring operator action awaiting a reply
@@ -59,19 +61,20 @@
5961
- A trailing asterisk, (*) wildcard is supported.
6062
type: str
6163
required: false
62-
message_filter:
64+
msg_filter:
6365
description:
6466
- Return outstanding messages requiring operator action awaiting a
6567
reply that match a regular expression (regex) filter.
6668
- If the message filter is not specified, all outstanding messages
6769
are returned regardless of their content.
6870
type: dict
6971
required: false
72+
aliases: [ message_filter ]
7073
suboptions:
7174
filter:
7275
description:
7376
- Specifies the substring or regex to match to the outstanding messages,
74-
see I(use_regex).
77+
see I(literal).
7578
- All special characters in a filter string that are not a regex are escaped.
7679
- Valid Python regular expressions are supported. See L(the official
7780
documentation,https://docs.python.org/library/re.html) for more information.
@@ -80,16 +83,16 @@
8083
newline."
8184
required: True
8285
type: str
83-
use_regex:
86+
literal:
8487
description:
8588
- Indicates that the value for I(filter) is a regex or a string to match.
86-
- If False, the module assumes that I(filter) is not a regex and
87-
matches the I(filter) substring on the outstanding messages.
88-
- If True, the module creates a regex from the I(filter) string and
89+
- If False, the module creates a regex from the I(filter) string and
8990
matches it to the outstanding messages.
91+
- If True, the module assumes that I(filter) is not a regex and
92+
matches the I(filter) substring on the outstanding messages.
9093
required: False
9194
type: bool
92-
default: False
95+
default: True
9396
seealso:
9497
- module: zos_operator
9598
@@ -116,23 +119,23 @@
116119
117120
- name: Display all outstanding messages whose message id begin with dsi*
118121
zos_operator_action_query:
119-
message_id: dsi*
122+
msg_id: dsi*
120123
121124
- name: Display all outstanding messages that have the text IMS READY in them
122125
zos_operator_action_query:
123-
message_filter:
126+
msg_filter:
124127
filter: IMS READY
125128
126129
- name: Display all outstanding messages where the job name begins with 'mq',
127130
message ID begins with 'dsi', on system 'mv29' and which contain the
128131
pattern 'IMS'
129132
zos_operator_action_query:
130133
job_name: mq*
131-
message_id: dsi*
134+
msg_id: dsi*
132135
system: mv29
133-
message_filter:
136+
msg_filter:
134137
filter: ^.*IMS.*$
135-
use_regex: true
138+
literal: true
136139
"""
137140

138141
RETURN = r"""
@@ -147,13 +150,13 @@
147150
count:
148151
description:
149152
The total number of outstanding messages.
150-
returned: on success
153+
returned: always
151154
type: int
152155
sample: 12
153156
actions:
154157
description:
155158
The list of the outstanding messages.
156-
returned: success
159+
returned: always
157160
type: list
158161
elements: dict
159162
contains:
@@ -183,11 +186,11 @@
183186
returned: on success
184187
type: str
185188
sample: STC01537
186-
message_text:
189+
msg_txt:
187190
description:
188191
Content of the outstanding message requiring operator
189-
action awaiting a reply. If I(message_filter) is set,
190-
I(message_text) will be filtered accordingly.
192+
action awaiting a reply. If I(msg_filter) is set,
193+
I(msg_txt) will be filtered accordingly.
191194
returned: success
192195
type: str
193196
sample: "*399 HWSC0000I *IMS CONNECT READY* IM5HCONN"
@@ -198,7 +201,7 @@
198201
returned: success
199202
type: str
200203
sample: IM5HCONN
201-
message_id:
204+
msg_id:
202205
description:
203206
Message identifier for outstanding message requiring operator
204207
action awaiting a reply.
@@ -212,18 +215,18 @@
212215
"type": 'R',
213216
"system": 'MV27',
214217
"job_id": 'STC01537',
215-
"message_text": '*399 HWSC0000I *IMS CONNECT READY* IM5HCONN',
218+
"msg_txt": '*399 HWSC0000I *IMS CONNECT READY* IM5HCONN',
216219
"job_name": 'IM5HCONN',
217-
"message_id": 'HWSC0000I'
220+
"msg_id": 'HWSC0000I'
218221
},
219222
{
220223
"number": '002',
221224
"type": 'R',
222225
"system": 'MV27',
223226
"job_id": 'STC01533',
224-
"message_text": '*400 DFS3139I IMS INITIALIZED, AUTOMATIC RESTART PROCEEDING IM5H',
227+
"msg_txt": '*400 DFS3139I IMS INITIALIZED, AUTOMATIC RESTART PROCEEDING IM5H',
225228
"job_name": 'IM5HCTRL',
226-
"message_id": 'DFS3139I'
229+
"msg_id": 'DFS3139I'
227230
}
228231
]
229232
"""
@@ -260,19 +263,20 @@ def run_module():
260263
"""
261264
module_args = dict(
262265
system=dict(type="str", required=False),
263-
message_id=dict(type="str", required=False),
266+
msg_id=dict(type="str", required=False, aliases=['message_id']),
264267
job_name=dict(type="str", required=False),
265-
message_filter=dict(
268+
msg_filter=dict(
266269
type="dict",
267270
required=False,
271+
aliases=['message_filter'],
268272
options=dict(
269273
filter=dict(type="str", required=True),
270-
use_regex=dict(default=False, type="bool", required=False)
274+
literal=dict(default=True, type="bool", required=False)
271275
)
272276
)
273277
)
274278

275-
result = dict(changed=False)
279+
result = dict(changed=False, count=0, actions=[])
276280
module = AnsibleModule(argument_spec=module_args, supports_check_mode=False)
277281
requests = []
278282
try:
@@ -321,7 +325,7 @@ def run_module():
321325
cmd="d r,a,jn",
322326
)
323327

324-
merged_list = create_merge_list(cmd_result_a.message, cmd_result_b.message, new_params['message_filter'])
328+
merged_list = create_merge_list(cmd_result_a.message, cmd_result_b.message, new_params['msg_filter'])
325329
requests = find_required_request(merged_list, new_params)
326330
if requests:
327331
result["count"] = len(requests)
@@ -351,9 +355,9 @@ def parse_params(params):
351355
"""
352356
arg_defs = dict(
353357
system=dict(arg_type=system_type, required=False),
354-
message_id=dict(arg_type=message_id_type, required=False),
358+
msg_id=dict(arg_type=msg_id_type, required=False),
355359
job_name=dict(arg_type=job_name_type, required=False),
356-
message_filter=dict(arg_type=message_filter_type, required=False)
360+
msg_filter=dict(arg_type=msg_filter_type, required=False)
357361
)
358362
parser = BetterArgParser(arg_defs)
359363
new_params = parser.parse_args(params)
@@ -380,7 +384,7 @@ def system_type(arg_val, params):
380384
return arg_val.upper()
381385

382386

383-
def message_id_type(arg_val, params):
387+
def msg_id_type(arg_val, params):
384388
"""Message id type.
385389
386390
Parameters
@@ -420,7 +424,7 @@ def job_name_type(arg_val, params):
420424
return arg_val.upper()
421425

422426

423-
def message_filter_type(arg_val, params):
427+
def msg_filter_type(arg_val, params):
424428
"""Message filter type.
425429
426430
Parameters
@@ -442,12 +446,12 @@ def message_filter_type(arg_val, params):
442446
"""
443447
try:
444448
filter_text = arg_val.get("filter")
445-
use_regex = arg_val.get("use_regex")
449+
literal = arg_val.get("literal")
446450

447-
if use_regex:
448-
raw_arg_val = r'{0}'.format(filter_text)
449-
else:
451+
if literal:
450452
raw_arg_val = r'^.*{0}.*$'.format(re.escape(filter_text))
453+
else:
454+
raw_arg_val = r'{0}'.format(filter_text)
451455

452456
re.compile(raw_arg_val)
453457
except re.error:
@@ -503,7 +507,7 @@ def find_required_request(merged_list, params):
503507
return requests
504508

505509

506-
def create_merge_list(message_a, message_b, message_filter):
510+
def create_merge_list(msg_a, msg_b, msg_filter):
507511
"""Merge the return lists that execute both 'd r,a,s' and 'd r,a,jn'.
508512
For example, if we have:
509513
'd r,a,s' response like: "742 R MV28 JOB57578 &742 ARC0055A REPLY 'GO' OR 'CANCEL'"
@@ -512,20 +516,20 @@ def create_merge_list(message_a, message_b, message_filter):
512516
513517
Parameters
514518
----------
515-
message_a : str
519+
msg_a : str
516520
Result coming from command 'd r,a,s'.
517-
message_b : str
521+
msg_b : str
518522
Result coming from command 'd r,a,jn'.
519-
message_filter : str
523+
msg_filter : str
520524
Message filter.
521525
522526
Returns
523527
-------
524528
Union
525-
Merge of the result of message_a and the result of message_b.
529+
Merge of the result of msg_a and the result of msg_b.
526530
"""
527-
list_a = parse_result_a(message_a, message_filter)
528-
list_b = parse_result_b(message_b, message_filter)
531+
list_a = parse_result_a(msg_a, msg_filter)
532+
list_b = parse_result_b(msg_b, msg_filter)
529533
merged_list = merge_list(list_a, list_b)
530534
return merged_list
531535

@@ -546,15 +550,15 @@ def filter_requests(merged_list, params):
546550
Filtered list.
547551
"""
548552
system = params.get("system")
549-
message_id = params.get("message_id")
553+
msg_id = params.get("msg_id")
550554
job_name = params.get("job_name")
551555
newlist = merged_list
552556
if system:
553557
newlist = handle_conditions(newlist, "system", system)
554558
if job_name:
555559
newlist = handle_conditions(newlist, "job_name", job_name)
556-
if message_id:
557-
newlist = handle_conditions(newlist, "message_id", message_id)
560+
if msg_id:
561+
newlist = handle_conditions(newlist, "msg_id", msg_id)
558562
return newlist
559563

560564

@@ -619,26 +623,26 @@ def execute_command(operator_cmd, timeout_s=1, *args, **kwargs):
619623
return OperatorQueryResult(rc, stdout, stderr)
620624

621625

622-
def match_raw_message(msg, message_filter):
626+
def match_raw_message(msg, msg_filter):
623627
"""Match raw message.
624628
625629
Parameters
626630
----------
627631
msg : str
628632
Message to match.
629-
message_filter : str
633+
msg_filter : str
630634
Filter for the message.
631635
632636
Return
633637
------
634638
bool
635639
If the pattern matches msg.
636640
"""
637-
pattern = re.compile(message_filter, re.DOTALL)
641+
pattern = re.compile(msg_filter, re.DOTALL)
638642
return pattern.match(msg)
639643

640644

641-
def parse_result_a(result, message_filter):
645+
def parse_result_a(result, msg_filter):
642646
"""parsing the result that coming from command 'd r,a,s',
643647
there are usually two formats:
644648
- line with job_id: 810 R MV2D JOB58389 &810 ARC0055A REPLY 'GO' OR 'CANCEL'
@@ -649,7 +653,7 @@ def parse_result_a(result, message_filter):
649653
----------
650654
result : str
651655
Result coming from command 'd r,a,s'.
652-
message_filter : str
656+
msg_filter : str
653657
Message filter.
654658
655659
Returns
@@ -668,7 +672,7 @@ def parse_result_a(result, message_filter):
668672
)
669673
for match in match_iter:
670674
# If there was a filter specified, we skip messages that do not match it.
671-
if message_filter is not None and not match_raw_message(match.string, message_filter):
675+
if msg_filter is not None and not match_raw_message(match.string, msg_filter):
672676
continue
673677

674678
dict_temp = {
@@ -679,13 +683,13 @@ def parse_result_a(result, message_filter):
679683
if match.group(4) != "":
680684
dict_temp["job_id"] = match.group(4)
681685
if match.group(5) != "":
682-
dict_temp["message_text"] = match.group(5).strip()
686+
dict_temp["msg_txt"] = match.group(5).strip()
683687
list.append(dict_temp)
684688

685689
return list
686690

687691

688-
def parse_result_b(result, message_filter):
692+
def parse_result_b(result, msg_filter):
689693
"""Parse the result that comes from command 'd r,a,jn', the main purpose
690694
to use this command is to get the job_name and message id, which is not
691695
included in 'd r,a,s'
@@ -694,7 +698,7 @@ def parse_result_b(result, message_filter):
694698
----------
695699
result : str
696700
Result coming from command 'd r,a,jn'.
697-
message_filter : str
701+
msg_filter : str
698702
Message filter.
699703
700704
Returns
@@ -714,13 +718,13 @@ def parse_result_b(result, message_filter):
714718

715719
for match in match_iter:
716720
# If there was a filter specified, we skip messages that do not match it.
717-
if message_filter is not None and not match_raw_message(match.string, message_filter):
721+
if msg_filter is not None and not match_raw_message(match.string, msg_filter):
718722
continue
719723

720724
dict_temp = {
721725
"number": match.group(1),
722726
"job_name": match.group(2),
723-
"message_id": match.group(3),
727+
"msg_id": match.group(3),
724728
}
725729

726730
# Sometimes 'job_name' will be null because the operator action is a

0 commit comments

Comments
 (0)