Skip to content

Commit

Permalink
Add exception handling to diff and exist functions (#176)
Browse files Browse the repository at this point in the history
* add logic to actually handle errors

* add exception handling to the exists-function

* add exception handling for all functions

* add exception handling to diff and create calls

* fix linting
  • Loading branch information
rndmh3ro authored Aug 2, 2022
1 parent f0ab886 commit ecc7a47
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions plugins/module_utils/icinga.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,12 @@ def exists(self, find_by="name"):
self.object_id = to_text(urlquote(self.data["object_name"]))
if ret["code"] == 200:
return True
return False
else:
return False

def query(self, query="", resolved=False):
"""
Find all matching obejcts in the director and return the result of the api-call.
Find all matching objects in the director and return the result of the api-call.
Parameters:
query: type str, default "", searchstring to limit the results. By default Director will search in
Expand Down Expand Up @@ -247,7 +248,12 @@ def update(self, state):

changed = False
diff_result = {"before": "", "after": ""}
if self.exists():

try:
exists = self.exists()
except Exception as e:
self.module.fail_json(msg="exception when deleting: " + str(e))
if exists:
diff_result.update({"before": "state: present\n"})
if state == "absent":
if self.module.check_mode:
Expand All @@ -274,7 +280,13 @@ def update(self, state):
)

else:
diff_result = self.diff()
try:
diff_result = self.diff()
except Exception as e:
self.module.fail_json(
msg="exception when diffing: " + str(e)
)

if self.module.check_mode:
if diff_result:
changed = True
Expand Down

0 comments on commit ecc7a47

Please sign in to comment.