Skip to content
Snippets Groups Projects
Commit 694c7178 authored by Rafael Guterres Jeffman's avatar Rafael Guterres Jeffman
Browse files

ipapwpolicy: Modify handling of usercheck and dictcheck

Modified handling of boolean values by using Ansible's 'boolean()' check
function so that a string can be used and either a bool value is
accepted or an empty string.

As the error message was changed to use the same Ansible message, tests
were also updated.
parent 083396e1
No related branches found
No related tags found
No related merge requests found
......@@ -151,7 +151,7 @@ RETURN = """
"""
from ansible.module_utils.ansible_freeipa_module import \
IPAAnsibleModule, compare_args_ipa
IPAAnsibleModule, compare_args_ipa, boolean
def find_pwpolicy(module, name):
......@@ -359,17 +359,12 @@ def main():
gracelimit = int_or_empty_param(gracelimit, "gracelimit")
def bool_or_empty_param(value, param): # pylint: disable=R1710
# As of Ansible 2.14, values True, False, Yes an No, with variable
# capitalization are accepted by Ansible.
if not value:
if value is None or value == "":
return value
if value in ["TRUE", "True", "true", "YES", "Yes", "yes"]:
return True
if value in ["FALSE", "False", "false", "NO", "No", "no"]:
return False
ansible_module.fail_json(
msg="Invalid value '%s' for argument '%s'." % (value, param)
)
try:
return boolean(value)
except TypeError as terr:
ansible_module.fail_json(msg="Param '%s': %s" % (param, str(terr)))
dictcheck = bool_or_empty_param(dictcheck, "dictcheck")
usercheck = bool_or_empty_param(usercheck, "usercheck")
......
......@@ -103,7 +103,7 @@
name: ops
dictcheck: "error"
register: result
failed_when: result.changed or (result.failed and "Invalid value 'error' for argument 'dictcheck" not in result.msg)
failed_when: result.changed or (result.failed and "is not a valid boolean" not in result.msg)
when: ipa_version is version("4.9", ">=")
- name: Ensure invalid values for usercheck raise proper error.
......@@ -113,7 +113,7 @@
name: ops
usercheck: "error"
register: result
failed_when: result.changed or (result.failed and "Invalid value 'error' for argument 'usercheck'" not in result.msg)
failed_when: result.changed or (result.failed and "is not a valid boolean" not in result.msg)
when: ipa_version is version("4.9", ">=")
- name: Ensure invalid values for gracelimit raise proper error.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment