Skip to content

Commit cd98d4a

Browse files
authored
[Enhancement] SYSIN DDs support for zos_job_output (#2207)
* adding sysin support * Adding the test case * changelog addition * sanity issue resolving * removing redundant files * review comments incorporation
1 parent 532f744 commit cd98d4a

File tree

4 files changed

+76
-5
lines changed

4 files changed

+76
-5
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
minor_changes:
2+
- zos_job_output - Adds support to query SYSIN DDs from a job with new option input.
3+
(https://github.com/ansible-collections/ibm_zos_core/pull/2207)

plugins/module_utils/job.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
])
5959

6060

61-
def job_output(job_id=None, owner=None, job_name=None, dd_name=None, dd_scan=True, duration=0, timeout=0, start_time=timer()):
61+
def job_output(job_id=None, owner=None, job_name=None, dd_name=None, sysin=False, dd_scan=True, duration=0, timeout=0, start_time=timer()):
6262
"""Get the output from a z/OS job based on various search criteria.
6363
6464
Keyword Parameters
@@ -71,6 +71,8 @@ def job_output(job_id=None, owner=None, job_name=None, dd_name=None, dd_scan=Tru
7171
The job name search for (default: {None}).
7272
dd_name : str
7373
The data definition to retrieve (default: {None}).
74+
sysin : bool
75+
The input DD to retrieve SYSIN value (default: {False}).
7476
dd_scan : bool
7577
Whether or not to pull information from the dd's for this job {default: {True}}.
7678
duration : int
@@ -112,6 +114,7 @@ def job_output(job_id=None, owner=None, job_name=None, dd_name=None, dd_scan=Tru
112114
job_name=job_name,
113115
dd_name=dd_name,
114116
duration=duration,
117+
sysin=sysin,
115118
dd_scan=dd_scan,
116119
timeout=timeout,
117120
start_time=start_time
@@ -128,6 +131,7 @@ def job_output(job_id=None, owner=None, job_name=None, dd_name=None, dd_scan=Tru
128131
owner=owner,
129132
job_name=job_name,
130133
dd_name=dd_name,
134+
sysin=sysin,
131135
dd_scan=dd_scan,
132136
duration=duration,
133137
timeout=timeout,
@@ -287,7 +291,7 @@ def _parse_steps(job_str):
287291
return stp
288292

289293

290-
def _get_job_status(job_id="*", owner="*", job_name="*", dd_name=None, dd_scan=True, duration=0, timeout=0, start_time=timer()):
294+
def _get_job_status(job_id="*", owner="*", job_name="*", dd_name=None, sysin=False, dd_scan=True, duration=0, timeout=0, start_time=timer()):
291295
"""Get job status.
292296
293297
Parameters
@@ -300,6 +304,8 @@ def _get_job_status(job_id="*", owner="*", job_name="*", dd_name=None, dd_scan=T
300304
The job name search for (default: {None}).
301305
dd_name : str
302306
The data definition to retrieve (default: {None}).
307+
sysin : bool
308+
The input DD SYSIN (default: {False}).
303309
dd_scan : bool
304310
Whether or not to pull information from the dd's for this job {default: {True}}.
305311
duration : int
@@ -405,7 +411,7 @@ def _get_job_status(job_id="*", owner="*", job_name="*", dd_name=None, dd_scan=T
405411
list_of_dds = []
406412

407413
try:
408-
list_of_dds = jobs.list_dds(entry.job_id)
414+
list_of_dds = jobs.list_dds(entry.job_id, sysin=sysin)
409415
except exceptions.DDQueryException:
410416
is_dd_query_exception = True
411417

@@ -424,7 +430,7 @@ def _get_job_status(job_id="*", owner="*", job_name="*", dd_name=None, dd_scan=T
424430
try:
425431
# Note, in the event of an exception, eg job has TYPRUN=HOLD
426432
# list_of_dds will still be populated with valuable content
427-
list_of_dds = jobs.list_dds(entry.job_id)
433+
list_of_dds = jobs.list_dds(entry.job_id, sysin=sysin)
428434
is_jesjcl = True if search_dictionaries("dd_name", "JESJCL", list_of_dds) else False
429435
is_job_error_status = True if entry.status in JOB_ERROR_STATUSES else False
430436
except exceptions.DDQueryException:

plugins/modules/zos_job_output.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
like "*".
3434
- If there is no ddname, or if ddname="?", output of all the ddnames under
3535
the given job will be displayed.
36+
- If SYSIN DDs are needed, C(input) should be set to C(true).
3637
version_added: "1.0.0"
3738
author:
3839
- "Jack Ho (@jacklotusho)"
@@ -61,6 +62,12 @@
6162
(e.g "JESJCL", "?")
6263
type: str
6364
required: false
65+
input:
66+
description:
67+
- Whether to include SYSIN DDs as part of the output.
68+
type: bool
69+
default: false
70+
required: false
6471
6572
attributes:
6673
action:
@@ -90,6 +97,11 @@
9097
job_name: "*"
9198
owner: "IBMUSER"
9299
ddname: "?"
100+
101+
- name: Query a job's output including SYSIN DDs
102+
zos_job_output:
103+
job_id: "JOB00548"
104+
input: true
93105
"""
94106

95107
RETURN = r"""
@@ -496,6 +508,7 @@ def run_module():
496508
job_name=dict(type="str", required=False),
497509
owner=dict(type="str", required=False),
498510
ddname=dict(type="str", required=False),
511+
input=dict(type="bool", required=False, default=False),
499512
)
500513

501514
module = AnsibleModule(argument_spec=module_args, supports_check_mode=True)
@@ -505,6 +518,7 @@ def run_module():
505518
job_name=dict(type="job_identifier", required=False),
506519
owner=dict(type="str", required=False),
507520
ddname=dict(type="str", required=False),
521+
input=dict(type="bool", required=False, default=False),
508522
)
509523

510524
try:
@@ -521,13 +535,14 @@ def run_module():
521535
job_name = module.params.get("job_name")
522536
owner = module.params.get("owner")
523537
ddname = module.params.get("ddname")
538+
sysin = module.params.get("input")
524539

525540
if not job_id and not job_name and not owner:
526541
module.fail_json(msg="Please provide a job_id or job_name or owner")
527542

528543
try:
529544
results = {}
530-
results["jobs"] = job_output(job_id=job_id, owner=owner, job_name=job_name, dd_name=ddname)
545+
results["jobs"] = job_output(job_id=job_id, owner=owner, job_name=job_name, dd_name=ddname, sysin=sysin)
531546
results["changed"] = False
532547
except zoau_exceptions.JobFetchException as fetch_exception:
533548
module.fail_json(

tests/functional/modules/test_zos_job_output_func.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,19 @@
3030
//
3131
"""
3232

33+
JCL_FILE_CONTENTS_SYSIN = """//SYSINS JOB (T043JM,JM00,1,0,0,0),'SYSINS - JRM',CLASS=R,
34+
// MSGCLASS=X,MSGLEVEL=1,NOTIFY=OMVSADM
35+
//STEP1 EXEC PGM=BPXBATCH,PARM='SH sleep 1'
36+
//STDOUT DD SYSOUT=*
37+
//STDERR DD SYSOUT=*
38+
//LISTCAT EXEC PGM=IDCAMS,REGION=4M
39+
//SYSPRINT DD SYSOUT=*
40+
//SYSIN DD *
41+
LISTCAT ENTRIES('TEST.DATASET.JCL') ALL
42+
/*
43+
//
44+
"""
45+
3346
TEMP_PATH = "/tmp/jcl"
3447

3548
def test_zos_job_output_no_job_id(ansible_zos_module):
@@ -149,6 +162,40 @@ def test_zos_job_output_job_exists_with_filtered_ddname(ansible_zos_module):
149162
hosts.all.file(path=TEMP_PATH, state="absent")
150163

151164

165+
def test_zos_job_output_job_exists_with_sysin(ansible_zos_module):
166+
try:
167+
hosts = ansible_zos_module
168+
hosts.all.file(path=TEMP_PATH, state="directory")
169+
hosts.all.zos_data_set(
170+
name="TEST.DATASET.JCL",
171+
type="PS",
172+
state="present"
173+
)
174+
hosts.all.shell(
175+
cmd=f"echo {quote(JCL_FILE_CONTENTS_SYSIN)} > {TEMP_PATH}/SYSIN"
176+
)
177+
result = hosts.all.zos_job_submit(
178+
src=f"{TEMP_PATH}/SYSIN", location="uss", volume=None
179+
)
180+
hosts.all.file(path=TEMP_PATH, state="absent")
181+
sysin = "True"
182+
results = hosts.all.zos_job_output(job_name="SYSINS", input=sysin)
183+
for result in results.contacted.values():
184+
print(result)
185+
assert result.get("changed") is False
186+
for job in result.get("jobs"):
187+
assert len(job.get("ddnames")) >= 1
188+
sysin_found = False
189+
for ddname_entry in job.get("ddnames"):
190+
if ddname_entry.get("ddname") == "SYSIN":
191+
sysin_found = True
192+
break
193+
assert sysin_found
194+
finally:
195+
hosts.all.zos_data_set(name="TEST.DATASET.JCL", state="absent")
196+
hosts.all.file(path=TEMP_PATH, state="absent")
197+
198+
152199
def test_zos_job_submit_job_id_and_owner_included(ansible_zos_module):
153200
hosts = ansible_zos_module
154201
results = hosts.all.zos_job_output(job_id="STC00*", owner="MASTER")

0 commit comments

Comments
 (0)