Skip to content

Commit 3586dd3

Browse files
authored
Bug fix to correct job log returining and other edge cases (#688)
* Update zos_job_submit to handle some edge cases and return the job log nearly always Signed-off-by: ddimatos <dimatos@gmail.com> * Linting correction Signed-off-by: ddimatos <dimatos@gmail.com> * Add changelog fragement for pr 683 Signed-off-by: ddimatos <dimatos@gmail.com> * Clean up comments in code Signed-off-by: ddimatos <dimatos@gmail.com> * Update restructured text for modules and changelog fragment Signed-off-by: ddimatos <dimatos@gmail.com> * Add support to check for security exception to job submit module Signed-off-by: ddimatos <dimatos@gmail.com> * Add additonal logic for jobs that use typerun=scan Signed-off-by: ddimatos <dimatos@gmail.com> * Update chnagelog fragment Signed-off-by: ddimatos <dimatos@gmail.com> * Correct run on sentence Signed-off-by: ddimatos <dimatos@gmail.com> --------- Signed-off-by: ddimatos <dimatos@gmail.com>
1 parent 364ac7e commit 3586dd3

File tree

7 files changed

+350
-77
lines changed

7 files changed

+350
-77
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
bugfixes:
2+
- zos_job_submit - Fixes the issue when invalid JCL syntax is submitted that a
3+
stack trace would result in the response, issue 623.
4+
(https://github.com/ansible-collections/ibm_zos_core/pull/683)
5+
- zos_job_submit - Fixes the issue when a job is purged by the system that a
6+
stack trace would result in the response, issue 681.
7+
(https://github.com/ansible-collections/ibm_zos_core/pull/683)
8+
- zos_job_submit - Fixes the issue where the response did not include the
9+
job log when a non-zero return code would occur, issue 655.
10+
(https://github.com/ansible-collections/ibm_zos_core/pull/683)
11+
- zos_job_submit - Fixes the issue when resources (data sets) identified in JCL
12+
did not exist such that a stack trace would result in the response, issue 624.
13+
(https://github.com/ansible-collections/ibm_zos_core/pull/683)
14+
- zos_job_submit - Fixes the issue when `wait_time_s` was set to 0 that would
15+
result in a `type` error that a stack trace would result in the response,
16+
issue 670. (https://github.com/ansible-collections/ibm_zos_core/pull/683)
17+
- zos_job_submit - Fixes the issue when a job encounters a security exception no
18+
job log would would result in the response, issue 684.
19+
(https://github.com/ansible-collections/ibm_zos_core/pull/683)
20+
- zos_job_submit - Fixes the issue when a job is configured for a syntax check
21+
using TYPRUN=SCAN that it would wait the full duration set by `wait_time_s`
22+
to return a response, issue 685.
23+
(https://github.com/ansible-collections/ibm_zos_core/pull/683)
24+
- zos_job_submit - Fixes the issue when a job is configured for a syntax check
25+
using TYPRUN=SCAN that no job log would result in the response, issue 685.
26+
(https://github.com/ansible-collections/ibm_zos_core/pull/683)
27+
trivial:
28+
- zos_job_submit - Update documentation to for deprecated `wait` option and
29+
expand on the `wait_time_s` description, issue 670.
30+
(https://github.com/ansible-collections/ibm_zos_core/pull/683)
31+
- zos_job_submit - Update documentation to describing the significance of '?'
32+
for the 'ret_code' properties 'msg_text', 'msg_code' and 'msg', issue 685.
33+
(https://github.com/ansible-collections/ibm_zos_core/pull/683)
34+
- zos_operator - Update restructured text to include the updated examples.
35+
(https://github.com/ansible-collections/ibm_zos_core/pull/683)

docs/source/modules/zos_job_submit.rst

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ zos_job_submit -- Submit JCL
1616

1717
Synopsis
1818
--------
19-
- Submit JCL from DATA_SET , USS, or LOCAL location.
20-
- Submit a job and optionally monitor for its execution.
21-
- Optionally wait a designated time until the job finishes.
19+
- Submit JCL from a data set, USS, or from the controller.
20+
- Submit a job and optionally monitor for completion.
21+
- Optionally, wait a designated time until the job finishes.
2222
- For an uncataloged dataset, specify the volume serial number.
2323

2424

@@ -32,7 +32,7 @@ Parameters
3232
src
3333
The source file or data set containing the JCL to submit.
3434

35-
It could be physical sequential data set or a partitioned data set qualified by a member or a path. (e.g "USER.TEST","USER.JCL(TEST)")
35+
It could be a physical sequential data set, a partitioned data set qualified by a member or a path. (e.g "USER.TEST","USER.JCL(TEST)")
3636

3737
Or a USS file. (e.g "/u/tester/demo/sample.jcl")
3838

@@ -58,20 +58,20 @@ location
5858
5959

6060
wait
61-
Configuring wait used by the `zos_job_submit <./zos_job_submit.html>`_ module has been deprecated and will be removed in ibm.ibm_zos_core collection.
61+
Setting this option will yield no change, it is deprecated. There is no no need to set *wait*; setting *wait_times_s* is the correct way to configure the amount of tme to wait for a job to execute.
6262

63-
Setting this option will yield no change, it is deprecated.
63+
Configuring wait used by the `zos_job_submit <./zos_job_submit.html>`_ module has been deprecated and will be removed in ibm.ibm_zos_core collection.
6464

65-
See option ``wait_time_s``.
65+
See option *wait_time_s*.
6666

6767
| **required**: False
6868
| **type**: bool
6969
7070

7171
wait_time_s
72-
When *wait* is true, the module will wait for the number of seconds for Job completion.
72+
Option *wait_time_s* is the total time that module `zos_job_submit <./zos_job_submit.html>`_ will wait for a submitted job to complete. The time begins when the module is executed on the managed node.
7373

74-
User can set the wait time manually with this option.
74+
*wait_time_s* is measured in seconds and must be a value greater than 0 and less than 86400.
7575

7676
| **required**: False
7777
| **type**: int
@@ -100,7 +100,7 @@ volume
100100

101101
When configured, the `zos_job_submit <./zos_job_submit.html>`_ will try to catalog the data set for the volume serial. If it is not able to, the module will fail.
102102

103-
Ignored for USS and LOCAL.
103+
Ignored for *location=USS* and *location=LOCAL*.
104104

105105
| **required**: False
106106
| **type**: str
@@ -548,18 +548,18 @@ jobs
548548
}
549549
550550
msg
551-
Return code resulting from the job submission.
551+
Return code resulting from the job submission. Jobs that take longer to assign a value can have a value of '?'.
552552

553553
| **type**: str
554554
| **sample**: CC 0000
555555
556556
msg_code
557-
Return code extracted from the `msg` so that it can be evaluated as a string.
557+
Return code extracted from the `msg` so that it can be evaluated as a string. Jobs that take longer to assign a value can have a value of '?'.
558558

559559
| **type**: str
560560
561561
msg_txt
562-
Returns additional information related to the job.
562+
Returns additional information related to the job. Jobs that take longer to assign a value can have a value of '?'.
563563

564564
| **type**: str
565565
| **sample**: The job completion code (CC) was not available in the job output, please review the job log."

docs/source/modules/zos_operator.rst

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,12 @@ wait_time_s
5959
6060

6161
wait
62-
Configuring wait used by the `zos_operator <./zos_operator.html>`_ module has been deprecated and will be removed in ibm.ibm_zos_core collection.
62+
Configuring wait used by the `zos_operator <./zos_operator.html>`_ module has been deprecated and will be removed in a future ibm.ibm_zos_core collection.
6363

6464
Setting this option will yield no change, it is deprecated.
6565

66+
Review option *wait_time_s* to instruct operator commands to wait.
67+
6668
| **required**: False
6769
| **type**: bool
6870
| **default**: True
@@ -76,13 +78,13 @@ Examples
7678
.. code-block:: yaml+jinja
7779

7880

79-
- name: Execute an operator command to show active jobs
81+
- name: Execute an operator command to show device status and allocation
8082
zos_operator:
81-
cmd: 'd u,all'
83+
cmd: 'd u'
8284

83-
- name: Execute an operator command to show active jobs with verbose information
85+
- name: Execute an operator command to show device status and allocation with verbose information
8486
zos_operator:
85-
cmd: 'd u,all'
87+
cmd: 'd u'
8688
verbose: true
8789

8890
- name: Execute an operator command to purge all job logs (requires escaping)
@@ -91,12 +93,12 @@ Examples
9193

9294
- name: Execute operator command to show jobs, waiting up to 5 seconds for response
9395
zos_operator:
94-
cmd: 'd u,all'
96+
cmd: 'd a,all'
9597
wait_time_s: 5
9698

9799
- name: Execute operator command to show jobs, always waiting 7 seconds for response
98100
zos_operator:
99-
cmd: 'd u,all'
101+
cmd: 'd a,all'
100102
wait_time_s: 7
101103

102104

plugins/action/zos_job_submit.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,20 @@ def run(self, tmp=None, task_vars=None):
135135
)
136136
)
137137

138+
def delete_dict_entries(entries, dictionary):
139+
""" Deletes entries from a dictionary when provided key and dictionary.
140+
141+
Arguments:
142+
entries (tuple) - entries to delete from dictionary
143+
dictionary (dic) - dictionary to remove entries
144+
"""
145+
for key in entries:
146+
if key in dictionary:
147+
del dictionary[key]
148+
149+
# Currently the direction is undecided if we should continue to use the
150+
# community action plugins or transition to SFTP, so this code
151+
# can remain should we want to clean up unrelated response values.
152+
# entries = ('checksum', 'dest', 'gid', 'group', 'md5sum', 'mode', 'owner', 'size', 'src', 'state', 'uid')
153+
# delete_dict_entries(entries, result)
138154
return result

plugins/module_utils/job.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,13 @@ def job_output(job_id=None, owner=None, job_name=None, dd_name=None, duration=0,
3535
"""Get the output from a z/OS job based on various search criteria.
3636
3737
Keyword Arguments:
38-
job_id {str} -- The job ID to search for (default: {None})
39-
owner {str} -- The owner of the job (default: {None})
40-
job_name {str} -- The job name search for (default: {None})
41-
dd_name {str} -- The data definition to retrieve (default: {None})
38+
job_id (str) -- The job ID to search for (default: {None})
39+
owner (str) -- The owner of the job (default: {None})
40+
job_name (str) -- The job name search for (default: {None})
41+
dd_name (str) -- The data definition to retrieve (default: {None})
42+
duration (int) -- The time the submitted job ran for
43+
timeout (int) - how long to wait in seconds for a job to complete
44+
start_time (int) - time the JCL started its submission
4245
4346
Returns:
4447
list[dict] -- The output information for a list of jobs matching specified criteria.
@@ -220,7 +223,8 @@ def _get_job_status(job_id="*", owner="*", job_name="*", dd_name=None, duration=
220223
job["ret_code"] = {}
221224
job["ret_code"]["msg"] = entry.status + " " + entry.rc
222225
job["ret_code"]["msg_code"] = entry.rc
223-
job["ret_code"]["code"] = ""
226+
# Why was this set to an empty string?
227+
job["ret_code"]["code"] = None
224228
if len(entry.rc) > 0:
225229
if entry.rc.isdigit():
226230
job["ret_code"]["code"] = int(entry.rc)
@@ -312,7 +316,7 @@ def _get_job_status(job_id="*", owner="*", job_name="*", dd_name=None, duration=
312316
job["ret_code"]["msg"] = tmptext.strip()
313317
job["ret_code"]["msg_code"] = None
314318
job["ret_code"]["code"] = None
315-
if len(list_of_dds) > 1:
319+
if len(list_of_dds) > 0:
316320
# The duration should really only be returned for job submit but the code
317321
# is used job_output as well, for now we can ignore this point unless
318322
# we want to offer a wait_time_s for job output which might be reasonable.

0 commit comments

Comments
 (0)