Skip to content

Commit

Permalink
Merge pull request freeipa#1319 from rjeffman/fix_show_broad_exception
Browse files Browse the repository at this point in the history
modules: Do not hide errors using IPA *_show command with Exception
  • Loading branch information
t-woerner authored Dec 3, 2024
2 parents 8fc2de1 + 5abb515 commit 227c95e
Show file tree
Hide file tree
Showing 18 changed files with 38 additions and 35 deletions.
6 changes: 3 additions & 3 deletions plugins/modules/ipaautomountmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
'''

from ansible.module_utils.ansible_freeipa_module import (
IPAAnsibleModule, compare_args_ipa
IPAAnsibleModule, compare_args_ipa, ipalib_errors
)


Expand All @@ -124,15 +124,15 @@ def get_automountmap(self, location, name):
location,
{"automountmapname": name, "all": True}
)
except Exception: # pylint: disable=broad-except
except ipalib_errors.NotFound:
return None
return response["result"]

def get_indirect_map_keys(self, location, name):
"""Check if 'name' is an indirect map for 'parentmap'."""
try:
maps = self.ipa_command("automountmap_find", location, {})
except Exception: # pylint: disable=broad-except
except ipalib_errors.NotFound:
return []

result = []
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/ipaconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ def config_show(module):
def get_netbios_name(module):
try:
_result = module.ipa_command_no_name("trustconfig_show", {"all": True})
except Exception: # pylint: disable=broad-except
except ipalib_errors.NotFound:
return None
return _result["result"]["ipantflatname"][0]

Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/ipadelegation.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@


from ansible.module_utils.ansible_freeipa_module import \
IPAAnsibleModule, compare_args_ipa
IPAAnsibleModule, compare_args_ipa, ipalib_errors


def find_delegation(module, name):
"""Find if a delegation with the given name already exist."""
try:
_result = module.ipa_command("delegation_show", name, {"all": True})
except Exception: # pylint: disable=broad-except
except ipalib_errors.NotFound:
# An exception is raised if delegation name is not found.
return None
return _result["result"]
Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/ipaidoverridegroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@


from ansible.module_utils.ansible_freeipa_module import \
IPAAnsibleModule, compare_args_ipa
IPAAnsibleModule, compare_args_ipa, ipalib_errors
from ansible.module_utils import six

if six.PY3:
Expand All @@ -168,7 +168,7 @@ def find_idoverridegroup(module, idview, anchor):
_result = module.ipa_command("idoverridegroup_show", idview,
{"ipaanchoruuid": anchor,
"all": True})
except Exception: # pylint: disable=broad-except
except ipalib_errors.NotFound:
# An exception is raised if idoverridegroup anchor is not found.
return None
return _result["result"]
Expand Down
5 changes: 3 additions & 2 deletions plugins/modules/ipaidoverrideuser.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,8 @@

from ansible.module_utils.ansible_freeipa_module import \
IPAAnsibleModule, compare_args_ipa, gen_add_del_lists, gen_add_list, \
gen_intersection_list, encode_certificate, convert_input_certificates
gen_intersection_list, encode_certificate, convert_input_certificates, \
ipalib_errors
from ansible.module_utils import six

if six.PY3:
Expand All @@ -328,7 +329,7 @@ def find_idoverrideuser(module, idview, anchor):
_result = module.ipa_command("idoverrideuser_show", idview,
{"ipaanchoruuid": anchor,
"all": True})
except Exception: # pylint: disable=broad-except
except ipalib_errors.NotFound:
# An exception is raised if idoverrideuser anchor is not found.
return None

Expand Down
5 changes: 3 additions & 2 deletions plugins/modules/ipaidp.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@


from ansible.module_utils.ansible_freeipa_module import \
IPAAnsibleModule, compare_args_ipa, template_str, urlparse
IPAAnsibleModule, compare_args_ipa, template_str, urlparse, \
ipalib_errors
from ansible.module_utils import six
from copy import deepcopy
import string
Expand Down Expand Up @@ -269,7 +270,7 @@ def find_idp(module, name):
"""Find if a idp with the given name already exist."""
try:
_result = module.ipa_command("idp_show", name, {"all": True})
except Exception: # pylint: disable=broad-except
except ipalib_errors.NotFound:
# An exception is raised if idp name is not found.
return None

Expand Down
5 changes: 3 additions & 2 deletions plugins/modules/ipaidrange.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@


from ansible.module_utils.ansible_freeipa_module import \
IPAAnsibleModule, compare_args_ipa, get_trusted_domain_sid_from_name
IPAAnsibleModule, compare_args_ipa, get_trusted_domain_sid_from_name, \
ipalib_errors
from ansible.module_utils import six

if six.PY3:
Expand All @@ -154,7 +155,7 @@ def find_idrange(module, name):
"""Find if a idrange with the given name already exist."""
try:
_result = module.ipa_command("idrange_show", name, {"all": True})
except Exception: # pylint: disable=broad-except
except ipalib_errors.NotFound:
# An exception is raised if idrange name is not found.
return None
return _result["result"]
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/ipaidview.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def find_idview(module, name):
"""Find if a idview with the given name already exist."""
try:
_result = module.ipa_command("idview_show", name, {"all": True})
except Exception: # pylint: disable=broad-except
except ipalib_errors.NotFound:
# An exception is raised if idview name is not found.
return None
return _result["result"]
Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/ipalocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@


from ansible.module_utils.ansible_freeipa_module import \
IPAAnsibleModule, compare_args_ipa
IPAAnsibleModule, compare_args_ipa, ipalib_errors


def find_location(module, name):
"""Find if a location with the given name already exist."""
try:
_result = module.ipa_command("location_show", name, {"all": True})
except Exception: # pylint: disable=broad-except
except ipalib_errors.NotFound:
# An exception is raised if location name is not found.
return None
return _result["result"]
Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/ipapermission.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,14 @@


from ansible.module_utils.ansible_freeipa_module import \
IPAAnsibleModule, compare_args_ipa, to_text
IPAAnsibleModule, compare_args_ipa, to_text, ipalib_errors


def find_permission(module, name):
"""Find if a permission with the given name already exist."""
try:
_result = module.ipa_command("permission_show", name, {"all": True})
except Exception: # pylint: disable=broad-except
except ipalib_errors.NotFound:
# An exception is raised if permission name is not found.
return None
_res = _result["result"]
Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/ipaprivilege.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@

from ansible.module_utils.ansible_freeipa_module import \
IPAAnsibleModule, compare_args_ipa, gen_add_del_lists, gen_add_list, \
gen_intersection_list
gen_intersection_list, ipalib_errors
from ansible.module_utils import six

if six.PY3:
Expand All @@ -135,7 +135,7 @@ def find_privilege(module, name):
"""Find if a privilege with the given name already exist."""
try:
_result = module.ipa_command("privilege_show", name, {"all": True})
except Exception: # pylint: disable=broad-except
except ipalib_errors.NotFound:
# An exception is raised if privilege name is not found.
return None
return _result["result"]
Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/iparole.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
from ansible.module_utils._text import to_text
from ansible.module_utils.ansible_freeipa_module import \
IPAAnsibleModule, gen_add_del_lists, compare_args_ipa, \
gen_intersection_list, ensure_fqdn
gen_intersection_list, ensure_fqdn, ipalib_errors
from ansible.module_utils import six

if six.PY3:
Expand All @@ -140,7 +140,7 @@ def find_role(module, name):
"""Find if a role with the given name already exist."""
try:
_result = module.ipa_command("role_show", name, {"all": True})
except Exception: # pylint: disable=broad-except
except ipalib_errors.NotFound:
# An exception is raised if role name is not found.
return None
return _result["result"]
Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/ipaselfservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@


from ansible.module_utils.ansible_freeipa_module import \
IPAAnsibleModule, compare_args_ipa
IPAAnsibleModule, compare_args_ipa, ipalib_errors


def find_selfservice(module, name):
"""Find if a selfservice with the given name already exist."""
try:
_result = module.ipa_command("selfservice_show", name, {"all": True})
except Exception: # pylint: disable=broad-except
except ipalib_errors.NotFound:
# An exception is raised if selfservice name is not found.
return None
return _result["result"]
Expand Down
6 changes: 3 additions & 3 deletions plugins/modules/ipaserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,14 @@


from ansible.module_utils.ansible_freeipa_module import \
IPAAnsibleModule, compare_args_ipa, DNSName
IPAAnsibleModule, compare_args_ipa, DNSName, ipalib_errors


def find_server(module, name):
"""Find if a server with the given name already exist."""
try:
_result = module.ipa_command("server_show", name, {"all": True})
except Exception: # pylint: disable=broad-except
except ipalib_errors.NotFound:
# An exception is raised if server name is not found.
return None
return _result["result"]
Expand All @@ -214,7 +214,7 @@ def server_role_status(module, name):
"include_master": True,
"raw": True,
"all": True})
except Exception: # pylint: disable=broad-except
except ipalib_errors.NotFound:
# An exception is raised if server name is not found.
return None
return _result["result"][0]
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/ipaservicedelegationrule.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def find_servicedelegationrule(module, name):
try:
_result = module.ipa_command("servicedelegationrule_show", name,
{"all": True})
except Exception: # pylint: disable=broad-except
except ipalib_errors.NotFound:
# An exception is raised if servicedelegationrule name is not found.
return None
return _result["result"]
Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/ipaservicedelegationtarget.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@

from ansible.module_utils.ansible_freeipa_module import \
IPAAnsibleModule, gen_add_del_lists, gen_add_list, gen_intersection_list, \
servicedelegation_normalize_principals
servicedelegation_normalize_principals, ipalib_errors
from ansible.module_utils import six

if six.PY3:
Expand All @@ -118,7 +118,7 @@ def find_servicedelegationtarget(module, name):
try:
_result = module.ipa_command("servicedelegationtarget_show", name,
{"all": True})
except Exception: # pylint: disable=broad-except
except ipalib_errors.NotFound:
# An exception is raised if servicedelegationtarget name is not found.
return None
return _result["result"]
Expand Down
4 changes: 2 additions & 2 deletions utils/templates/ipamodule+member.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ RETURN = """

from ansible.module_utils.ansible_freeipa_module import \
IPAAnsibleModule, compare_args_ipa, gen_add_del_lists, gen_add_list, \
gen_intersection_list
gen_intersection_list, ipalib_errors
from ansible.module_utils import six

if six.PY3:
Expand All @@ -124,7 +124,7 @@ def find_$name(module, name):
"""Find if a $name with the given name already exist."""
try:
_result = module.ipa_command("$name_show", name, {"all": True})
except Exception: # pylint: disable=broad-except
except ipalib_errors.NotFound:
# An exception is raised if $name name is not found.
return None
return _result["result"]
Expand Down
4 changes: 2 additions & 2 deletions utils/templates/ipamodule.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ RETURN = """


from ansible.module_utils.ansible_freeipa_module import \
IPAAnsibleModule, compare_args_ipa
IPAAnsibleModule, compare_args_ipa, ipalib_errors
from ansible.module_utils import six

if six.PY3:
Expand All @@ -100,7 +100,7 @@ def find_$name(module, name):
"""Find if a $name with the given name already exist."""
try:
_result = module.ipa_command("$name_show", name, {"all": True})
except Exception: # pylint: disable=broad-except
except ipalib_errors.NotFound:
# An exception is raised if $name name is not found.
return None
return _result["result"]
Expand Down

0 comments on commit 227c95e

Please sign in to comment.