Skip to content

Commit 0a6c24c

Browse files
AndreMarcel99fernandofloresgAndré Marcel Gutiérrez Benítez
authored
[Enabler][2148]update_zos_job_query_module (#2204)
* Change interface * Remove lines * Update documentation * Move steps out of ret_code * Adjust documentation for steps and module * Replace steps on test suite * Fix documentation * Add fragment * Update changelogs/fragments/2204-Update_zos_job_query_module.yml Co-authored-by: Fernando Flores <[email protected]> * Fix null for none --------- Co-authored-by: Fernando Flores <[email protected]> Co-authored-by: André Marcel Gutiérrez Benítez <[email protected]>
1 parent afe0662 commit 0a6c24c

File tree

4 files changed

+272
-54
lines changed

4 files changed

+272
-54
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
breaking_changes:
2+
- zos_job_query - Return value ``message`` is deprecated in favor of ``msg``. Return value ``steps`` are no longer under `` but is now included under jobs.
3+
(https://github.com/ansible-collections/ibm_zos_core/pull/2204).

plugins/module_utils/job.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ def _get_job_status(job_id="*", owner="*", job_name="*", dd_name=None, dd_scan=T
381381
job["queue_position"] = entry.queue_position
382382
job["program_name"] = entry.program_name
383383
job["class"] = ""
384-
job["ret_code"]["steps"] = []
384+
job["steps"] = []
385385
job["ddnames"] = []
386386
job["duration"] = duration
387387
if hasattr(entry, "execution_time"):
@@ -493,7 +493,7 @@ def _get_job_status(job_id="*", owner="*", job_name="*", dd_name=None, dd_scan=T
493493

494494
dd["content"] = tmpcont.split("\n")
495495

496-
job["ret_code"]["steps"].extend(_parse_steps(tmpcont))
496+
job["steps"].extend(_parse_steps(tmpcont))
497497

498498
job["ddnames"].append(dd)
499499
if len(job["class"]) < 1:

plugins/modules/zos_job_query.py

Lines changed: 63 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
True if the state was changed, otherwise False.
109109
returned: always
110110
type: bool
111+
sample: True
111112
jobs:
112113
description:
113114
The output information for a list of jobs matching specified criteria.
@@ -153,21 +154,21 @@
153154
The job entry subsystem that MVS uses to do work.
154155
type: str
155156
sample: STL1
156-
cpu_time:
157+
origin_node:
157158
description:
158-
Sum of the CPU time used by each job step, in microseconds.
159-
type: int
160-
sample: 5
159+
Origin node that submitted the job.
160+
type: str
161+
sample: "STL1"
161162
execution_node:
162163
description:
163164
Execution node that picked the job and executed it.
164165
type: str
165166
sample: "STL1"
166-
origin_node:
167+
cpu_time:
167168
description:
168-
Origin node that submitted the job.
169-
type: str
170-
sample: "STL1"
169+
Sum of the CPU time used by each job step, in microseconds.
170+
type: int
171+
sample: 5
171172
ret_code:
172173
description:
173174
Return code output collected from job log.
@@ -210,19 +211,35 @@
210211
The CC returned for this step in the DD section.
211212
type: int
212213
sample: 0
213-
214214
sample:
215215
ret_code: {
216216
"msg": "CC 0000",
217217
"msg_code": "0000",
218218
"msg_txt": "",
219-
"code": 0,
220-
"steps": [
221-
{ "step_name": "STEP0001",
222-
"step_cc": 0
223-
}
224-
]
219+
"code": 0
225220
}
221+
steps:
222+
description:
223+
Series of JCL steps that were executed and their return codes.
224+
type: list
225+
elements: dict
226+
contains:
227+
step_name:
228+
description:
229+
Name of the step shown as "was executed" in the DD section.
230+
type: str
231+
sample: "STEP0001"
232+
step_cc:
233+
description:
234+
The CC returned for this step in the DD section.
235+
type: int
236+
sample: 0
237+
sample:
238+
"steps": [
239+
{ "step_name": "STEP0001",
240+
"step_cc": 0
241+
}
242+
]
226243
job_class:
227244
description:
228245
Job class for this job.
@@ -277,14 +294,20 @@
277294
"job_name": "LINKJOB",
278295
"owner": "ADMIN",
279296
"job_id": "JOB01427",
280-
"ret_code": "null",
281-
"job_class": "K",
282297
"content_type": "JOB",
283-
"svc_class": "?",
298+
"ret_code": { "msg" : "CC", "msg_code" : "0000", "code" : "0", msg_txt : "CC" },
299+
"steps": [
300+
{ "step_name": "STEP0001",
301+
"step_cc": 0
302+
}
303+
],
304+
"job_class": "STC",
305+
"svc_class": "null",
284306
"priority": 1,
285307
"asid": 0,
286308
"creation_date": "2023-05-03",
287309
"creation_time": "12:13:00",
310+
"program_name": "BPXBATCH",
288311
"queue_position": 3,
289312
"execution_time": "00:00:02",
290313
"system": "STL1",
@@ -298,7 +321,8 @@
298321
"owner": "ADMIN",
299322
"job_id": "JOB16577",
300323
"content_type": "JOB",
301-
"ret_code": { "msg": "CANCELED", "code": "null" },
324+
"ret_code": { "msg" : "CANCELED", "msg_code" : "null", "code" : "null", msg_txt : "CANCELED" },
325+
"steps" : [],
302326
"job_class": "A",
303327
"svc_class": "E",
304328
"priority": 0,
@@ -307,14 +331,15 @@
307331
"creation_time": "12:14:00",
308332
"queue_position": 0,
309333
"execution_time": "00:00:03",
334+
"program_name": "null",
310335
"system": "STL1",
311336
"subsystem": "STL1",
312337
"cpu_time": 1414,
313338
"execution_node": "STL1",
314339
"origin_node": "STL1"
315340
},
316341
]
317-
message:
342+
msg:
318343
description:
319344
Message returned on failure.
320345
type: str
@@ -349,7 +374,7 @@ def run_module():
349374
job_id=dict(type="str", required=False),
350375
)
351376

352-
result = dict(changed=False, message="")
377+
result = dict(changed=False)
353378

354379
module = AnsibleModule(argument_spec=module_args, supports_check_mode=True)
355380

@@ -379,6 +404,7 @@ def run_module():
379404
jobs_raw = query_jobs(name, id, owner)
380405
if jobs_raw:
381406
jobs = parsing_jobs(jobs_raw)
407+
result["changed"] = True
382408
else:
383409
jobs = None
384410

@@ -436,8 +462,8 @@ def parsing_jobs(jobs_raw):
436462
Parsed jobs.
437463
"""
438464
jobs = []
439-
ret_code = {}
440465
for job in jobs_raw:
466+
ret_code = job.get("ret_code")
441467
# Easier to see than checking for an empty string, JOB NOT FOUND was
442468
# replaced with None in the jobs.py and msg_txt field describes the job query instead
443469
if job.get("ret_code") is None:
@@ -449,30 +475,32 @@ def parsing_jobs(jobs_raw):
449475

450476
if "AC" in status_raw:
451477
# the job is active
452-
ret_code = None
478+
ret_code["msg"] = None
479+
ret_code["msg_code"] = None
480+
ret_code["code"] = None
481+
ret_code["msg_txt"] = None
482+
453483
elif "CC" in status_raw:
454484
# status = 'Completed normally'
455-
ret_code = {
456-
"msg": status_raw,
457-
"code": job.get("ret_code").get("code"),
458-
}
485+
ret_code["msg"] = status_raw
486+
459487
elif "ABEND" in status_raw:
460488
# status = 'Ended abnormally'
461-
ret_code = {
462-
"msg": status_raw,
463-
"code": job.get("ret_code").get("code"),
464-
}
489+
ret_code["msg"] = status_raw
490+
465491
elif "ABENDU" in status_raw:
466492
# status = 'Ended abnormally'
467-
ret_code = {"msg": status_raw, "code": job.get("ret_code").get("code")}
493+
ret_code["msg"] = status_raw
468494

469495
elif "CANCELED" in status_raw or "JCLERR" in status_raw or "JCL ERROR" in status_raw or "JOB NOT FOUND" in status_raw:
470496
# status = status_raw
471-
ret_code = {"msg": status_raw, "code": None}
497+
ret_code["msg"] = status_raw
498+
ret_code["code"] = None
499+
ret_code["msg_code"] = None
472500

473501
else:
474502
# status = 'Unknown'
475-
ret_code = {"msg": status_raw, "code": job.get("ret_code").get("code")}
503+
ret_code["msg"] = status_raw
476504

477505
job_dict = {
478506
"job_name": job.get("job_name"),
@@ -485,6 +513,7 @@ def parsing_jobs(jobs_raw):
485513
"execution_node": job.get("execution_node"),
486514
"origin_node": job.get("origin_node"),
487515
"ret_code": ret_code,
516+
"steps": job.get("steps"),
488517
"job_class": job.get("job_class"),
489518
"svc_class": job.get("svc_class"),
490519
"priority": job.get("priority"),

0 commit comments

Comments
 (0)