Skip to content

Commit

Permalink
[1.9.0] zos_apf remove try expect pass to better exception handling (#…
Browse files Browse the repository at this point in the history
…1036)

* Removed except pass

* Added empty strings

* Added changelog

* Corrected changelog

* Modified if statement to honor current behavior

* Update 1036-apf-try-except.yml

* Update 1036-apf-try-except.yml
  • Loading branch information
fernandofloresg authored Nov 14, 2023
1 parent 5feec01 commit 6cd4f7c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
4 changes: 4 additions & 0 deletions changelogs/fragments/1036-apf-try-except.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
minor_changes:
- zos_apf - Improves exception handling if there is a failure
parsing the command response when operation selected is list.
(https://github.com/ansible-collections/ibm_zos_core/pull/1036).
40 changes: 19 additions & 21 deletions plugins/modules/zos_apf.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,29 +520,27 @@ def main():
operRc = ret.rc
result['stderr'] = operErr
result['rc'] = operRc
result['stdout'] = operOut
if operation == 'list':
try:
dsRx = ""
volRx = ""
if library:
dsRx = re.compile(library)
if volume:
volRx = re.compile(volume)
if sms:
sms = "*SMS*"
if dsRx or volRx or sms:
if not library:
library = ""
if not volume:
volume = ""
if sms:
sms = "*SMS*"
if library or volume or sms:
try:
data = json.loads(operOut)
operOut = ""
for d in data[2:]:
ds = d.get('ds')
vol = d.get('vol')
if (dsRx and dsRx.match(ds)) or (volRx and volRx.match(vol)) or (sms and sms == vol):
operOut = operOut + "{0} {1}\n".format(vol, ds)
except Exception:
pass

result['stdout'] = operOut

except json.JSONDecodeError:
module.exit_json(**result)
for d in data[2:]:
ds = d.get('ds')
vol = d.get('vol')
try:
if (library and re.match(library, ds)) or (volume and re.match(volume, vol)) or (sms and sms == vol):
result['stdout'] = "{0} {1}\n".format(vol, ds)
except re.error:
module.exit_json(**result)
module.exit_json(**result)


Expand Down

0 comments on commit 6cd4f7c

Please sign in to comment.