Skip to content
Snippets Groups Projects
Unverified Commit 9dcff9a3 authored by Thomas Woerner's avatar Thomas Woerner Committed by GitHub
Browse files

Merge pull request #851 from rjeffman/dnszone_fix_bool_behavior

Fix handling of boolean values for FreeIPA 4.9.10+
parents e500c133 a5306b2d
No related branches found
No related tags found
No related merge requests found
...@@ -88,9 +88,15 @@ else: ...@@ -88,9 +88,15 @@ else:
""" """
Split a version string A.B.C, into a tuple. Split a version string A.B.C, into a tuple.
This will not work for `rc`, `dev` or similar version string. This will not work for `rc`, `dev` or similar.
""" """
return tuple(re.split("[-_.]", version_str)) # noqa: W605 try:
_version = tuple(
(int(x) for x in re.split("[-_.]", version_str))
)
except ValueError:
_version = tuple(re.split("[-_.]", version_str))
return _version
from ipalib import api from ipalib import api
from ipalib import errors as ipalib_errors # noqa from ipalib import errors as ipalib_errors # noqa
...@@ -866,7 +872,10 @@ else: ...@@ -866,7 +872,10 @@ else:
# Check if param_name is actually a param # Check if param_name is actually a param
if param_name in self.ansible_module.params: if param_name in self.ansible_module.params:
value = self.ansible_module.params_get(param_name) value = self.ansible_module.params_get(param_name)
if isinstance(value, bool): if (
self.ansible_module.ipa_check_version("<", "4.9.10")
and isinstance(value, bool)
):
value = "TRUE" if value else "FALSE" value = "TRUE" if value else "FALSE"
# Since param wasn't a param check if it's a method name # Since param wasn't a param check if it's a method name
......
...@@ -441,7 +441,11 @@ def main(): ...@@ -441,7 +441,11 @@ def main():
elif ( elif (
isinstance(value, (tuple, list)) and arg_type == "bool" isinstance(value, (tuple, list)) and arg_type == "bool"
): ):
exit_args[k] = (value[0] == "TRUE") # FreeIPA 4.9.10+ and 4.10 use proper mapping for
# boolean values, so we need to convert it to str
# for comparison.
# See: https://github.com/freeipa/freeipa/pull/6294
exit_args[k] = (str(value[0]).upper() == "TRUE")
else: else:
if arg_type not in type_map: if arg_type not in type_map:
raise ValueError( raise ValueError(
......
...@@ -344,7 +344,13 @@ def main(): ...@@ -344,7 +344,13 @@ def main():
if state in ['enabled', 'disabled']: if state in ['enabled', 'disabled']:
if existing_resource is not None: if existing_resource is not None:
is_enabled = existing_resource["idnszoneactive"][0] # FreeIPA 4.9.10+ and 4.10 use proper mapping for
# boolean values, so we need to convert it to str
# for comparison.
# See: https://github.com/freeipa/freeipa/pull/6294
is_enabled = (
str(existing_resource["idnszoneactive"][0]).upper()
)
else: else:
ansible_module.fail_json( ansible_module.fail_json(
msg="dnsforwardzone '%s' not found." % (name)) msg="dnsforwardzone '%s' not found." % (name))
......
...@@ -418,7 +418,11 @@ class DNSZoneModule(IPAAnsibleModule): ...@@ -418,7 +418,11 @@ class DNSZoneModule(IPAAnsibleModule):
is_zone_active = False is_zone_active = False
else: else:
zone = response["result"] zone = response["result"]
is_zone_active = "TRUE" in zone.get("idnszoneactive") # FreeIPA 4.9.10+ and 4.10 use proper mapping for boolean vaalues.
# See: https://github.com/freeipa/freeipa/pull/6294
is_zone_active = (
str(zone.get("idnszoneactive")[0]).upper() == "TRUE"
)
return zone, is_zone_active return zone, is_zone_active
......
...@@ -472,18 +472,26 @@ def main(): ...@@ -472,18 +472,26 @@ def main():
# hbacrule_enable is not failing on an enabled hbacrule # hbacrule_enable is not failing on an enabled hbacrule
# Therefore it is needed to have a look at the ipaenabledflag # Therefore it is needed to have a look at the ipaenabledflag
# in res_find. # in res_find.
if "ipaenabledflag" not in res_find or \ # FreeIPA 4.9.10+ and 4.10 use proper mapping for
res_find["ipaenabledflag"][0] != "TRUE": # boolean values, so we need to convert it to str
# for comparison.
# See: https://github.com/freeipa/freeipa/pull/6294
enabled_flag = str(res_find.get("ipaenabledflag", [False])[0])
if enabled_flag.upper() != "TRUE":
commands.append([name, "hbacrule_enable", {}]) commands.append([name, "hbacrule_enable", {}])
elif state == "disabled": elif state == "disabled":
if res_find is None: if res_find is None:
ansible_module.fail_json(msg="No hbacrule '%s'" % name) ansible_module.fail_json(msg="No hbacrule '%s'" % name)
# hbacrule_disable is not failing on an disabled hbacrule # hbacrule_disable is not failing on an enabled hbacrule
# Therefore it is needed to have a look at the ipaenabledflag # Therefore it is needed to have a look at the ipaenabledflag
# in res_find. # in res_find.
if "ipaenabledflag" not in res_find or \ # FreeIPA 4.9.10+ and 4.10 use proper mapping for
res_find["ipaenabledflag"][0] != "FALSE": # boolean values, so we need to convert it to str
# for comparison.
# See: https://github.com/freeipa/freeipa/pull/6294
enabled_flag = str(res_find.get("ipaenabledflag", [False])[0])
if enabled_flag.upper() != "FALSE":
commands.append([name, "hbacrule_disable", {}]) commands.append([name, "hbacrule_disable", {}])
else: else:
......
...@@ -656,8 +656,12 @@ def main(): ...@@ -656,8 +656,12 @@ def main():
# sudorule_enable is not failing on an enabled sudorule # sudorule_enable is not failing on an enabled sudorule
# Therefore it is needed to have a look at the ipaenabledflag # Therefore it is needed to have a look at the ipaenabledflag
# in res_find. # in res_find.
if "ipaenabledflag" not in res_find or \ # FreeIPA 4.9.10+ and 4.10 use proper mapping for
res_find["ipaenabledflag"][0] != "TRUE": # boolean values, so we need to convert it to str
# for comparison.
# See: https://github.com/freeipa/freeipa/pull/6294
enabled_flag = str(res_find.get("ipaenabledflag", [False])[0])
if enabled_flag.upper() != "TRUE":
commands.append([name, "sudorule_enable", {}]) commands.append([name, "sudorule_enable", {}])
elif state == "disabled": elif state == "disabled":
...@@ -666,8 +670,12 @@ def main(): ...@@ -666,8 +670,12 @@ def main():
# sudorule_disable is not failing on an disabled sudorule # sudorule_disable is not failing on an disabled sudorule
# Therefore it is needed to have a look at the ipaenabledflag # Therefore it is needed to have a look at the ipaenabledflag
# in res_find. # in res_find.
if "ipaenabledflag" not in res_find or \ # FreeIPA 4.9.10+ and 4.10 use proper mapping for
res_find["ipaenabledflag"][0] != "FALSE": # boolean values, so we need to convert it to str
# for comparison.
# See: https://github.com/freeipa/freeipa/pull/6294
enabled_flag = str(res_find.get("ipaenabledflag", [False])[0])
if enabled_flag.upper() != "FALSE":
commands.append([name, "sudorule_disable", {}]) commands.append([name, "sudorule_disable", {}])
else: else:
......
...@@ -64,18 +64,26 @@ class TestDNSZone(AnsibleFreeIPATestCase): ...@@ -64,18 +64,26 @@ class TestDNSZone(AnsibleFreeIPATestCase):
def test_dnszone_disable(self): def test_dnszone_disable(self):
"""TC-30: Disable DNS Zone.""" """TC-30: Disable DNS Zone."""
zone26 = "26testzone.test" zone26 = "26testzone.test"
self.check_details(["Active zone: TRUE"], "dnszone-find", [zone26]) self.check_details(
["Active zone: (TRUE|True)"], "dnszone-find", [zone26]
)
# Disable dns zone # Disable dns zone
self.run_playbook(BASE_PATH + "dnszone_disable.yaml") self.run_playbook(BASE_PATH + "dnszone_disable.yaml")
self.check_details(["Active zone: FALSE"], "dnszone-find", [zone26]) self.check_details(
["Active zone: (FALSE|False)"], "dnszone-find", [zone26]
)
def test_dnszone_enable(self): def test_dnszone_enable(self):
"""TC-31: Enable DNS Zone.""" """TC-31: Enable DNS Zone."""
zone26 = "26testzone.test" zone26 = "26testzone.test"
self.check_details(["Active zone: FALSE"], "dnszone-find", [zone26]) self.check_details(
["Active zone: (FALSE|False)"], "dnszone-find", [zone26]
)
# Enable dns zone # Enable dns zone
self.run_playbook(BASE_PATH + "dnszone_enable.yaml") self.run_playbook(BASE_PATH + "dnszone_enable.yaml")
self.check_details(["Active zone: TRUE"], "dnszone-find", [zone26]) self.check_details(
["Active zone: (TRUE|True)"], "dnszone-find", [zone26]
)
def test_dnszone_name_from_ip(self): def test_dnszone_name_from_ip(self):
"""TC-35: Add dns zone with reverse zone IP. Bug#1845056.""" """TC-35: Add dns zone with reverse zone IP. Bug#1845056."""
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
import os import os
import pytest import pytest
import re
import subprocess import subprocess
import tempfile import tempfile
import testinfra import testinfra
...@@ -314,6 +315,10 @@ class AnsibleFreeIPATestCase(TestCase): ...@@ -314,6 +315,10 @@ class AnsibleFreeIPATestCase(TestCase):
expected_msg in result.stderr.decode("utf8") expected_msg in result.stderr.decode("utf8")
) )
@staticmethod
def __is_text_on_data(text, data):
return re.search(text, data) is not None
def check_details(self, expected_output, cmd, extra_cmds=None): def check_details(self, expected_output, cmd, extra_cmds=None):
cmd = "ipa " + cmd cmd = "ipa " + cmd
if extra_cmds: if extra_cmds:
...@@ -322,10 +327,16 @@ class AnsibleFreeIPATestCase(TestCase): ...@@ -322,10 +327,16 @@ class AnsibleFreeIPATestCase(TestCase):
res = self.master.run(cmd) res = self.master.run(cmd)
if res.rc != 0: if res.rc != 0:
for output in expected_output: for output in expected_output:
assert output in res.stderr assert self.__is_text_on_data(output, res.stderr), (
f"\n{'='*40}\nExpected: {output}\n{'='*40}\n"
+ f"Output:\n{res.stderr}{'='*40}\n"
)
else: else:
for output in expected_output: for output in expected_output:
assert output in res.stdout assert self.__is_text_on_data(output, res.stdout), (
f"\n{'='*40}\nExpected: {output}\n{'='*40}\n"
+ f"Output:\n{res.stdout}{'='*40}\n"
)
kdestroy(self.master) kdestroy(self.master)
def check_notexists(self, members, cmd, extra_cmds=None): def check_notexists(self, members, cmd, extra_cmds=None):
...@@ -335,7 +346,10 @@ class AnsibleFreeIPATestCase(TestCase): ...@@ -335,7 +346,10 @@ class AnsibleFreeIPATestCase(TestCase):
kinit_admin(self.master) kinit_admin(self.master)
res = self.master.run(cmd) res = self.master.run(cmd)
for member in members: for member in members:
assert member not in res.stdout assert not self.__is_text_on_data(member, res.stdout), (
f"\n{'='*40}\nExpected: {member}\n{'='*40}\n"
+ f"Output:\n{res.stdout}{'='*40}\n"
)
kdestroy(self.master) kdestroy(self.master)
def mark_xfail_using_ansible_freeipa_version(self, version, reason): def mark_xfail_using_ansible_freeipa_version(self, version, reason):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment