Blame SOURCES/ansible-freeipa-0.1.8-ansible_freeipa_module-Fix-comparison-of-bool-parameters-in-compare_args_ipa_rhbz#1784514.patch

d9912c
From 3780a9a00e77ae0fd2944b36adad446d094fc90f Mon Sep 17 00:00:00 2001
d9912c
From: Thomas Woerner <twoerner@redhat.com>
d9912c
Date: Tue, 11 Feb 2020 10:34:39 +0100
d9912c
Subject: [PATCH] ansible_freeipa_module: Fix comparison of bool parameters in
d9912c
 compare_args_ipa
d9912c
d9912c
Bool types are not iterable. Therefore the comparison using sets was failing
d9912c
with a TypeError. This prevented to change the bool parameters for hosts.
d9912c
d9912c
A test for the host module has been added to verify that the bool parameters
d9912c
can be modified.
d9912c
d9912c
New test:
d9912c
d9912c
  tests/host/test_host_bool_params.yml
d9912c
d9912c
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1784514
d9912c
---
d9912c
 .../module_utils/ansible_freeipa_module.py    |  18 ++-
d9912c
 tests/host/test_host_bool_params.yml          | 119 ++++++++++++++++++
d9912c
 2 files changed, 133 insertions(+), 4 deletions(-)
d9912c
 create mode 100644 tests/host/test_host_bool_params.yml
d9912c
d9912c
diff --git a/plugins/module_utils/ansible_freeipa_module.py b/plugins/module_utils/ansible_freeipa_module.py
d9912c
index 8154a12..9e97b88 100644
d9912c
--- a/plugins/module_utils/ansible_freeipa_module.py
d9912c
+++ b/plugins/module_utils/ansible_freeipa_module.py
d9912c
@@ -222,10 +222,20 @@ def compare_args_ipa(module, args, ipa):
d9912c
                     arg = [to_text(_arg) for _arg in arg]
d9912c
                 if isinstance(ipa_arg[0], unicode) and isinstance(arg[0], int):
d9912c
                     arg = [to_text(_arg) for _arg in arg]
d9912c
-            # module.warn("%s <=> %s" % (arg, ipa_arg))
d9912c
-            if set(arg) != set(ipa_arg):
d9912c
-                # module.warn("DIFFERENT")
d9912c
-                return False
d9912c
+            # module.warn("%s <=> %s" % (repr(arg), repr(ipa_arg)))
d9912c
+            try:
d9912c
+                arg_set = set(arg)
d9912c
+                ipa_arg_set = set(ipa_arg)
d9912c
+            except TypeError:
d9912c
+                if arg != ipa_arg:
d9912c
+                    # module.warn("%s != %s" % (repr(arg), repr(ipa_arg)))
d9912c
+                    return False
d9912c
+            else:
d9912c
+                if arg_set != ipa_arg_set:
d9912c
+                    # module.warn("%s != %s" % (repr(arg), repr(ipa_arg)))
d9912c
+                    return False
d9912c
+
d9912c
+        # module.warn("%s == %s" % (repr(arg), repr(ipa_arg)))
d9912c
 
d9912c
     return True
d9912c
 
d9912c
diff --git a/tests/host/test_host_bool_params.yml b/tests/host/test_host_bool_params.yml
d9912c
new file mode 100644
d9912c
index 0000000..824ea99
d9912c
--- /dev/null
d9912c
+++ b/tests/host/test_host_bool_params.yml
d9912c
@@ -0,0 +1,119 @@
d9912c
+---
d9912c
+- name: Test host bool parameters
d9912c
+  hosts: ipaserver
d9912c
+  become: true
d9912c
+
d9912c
+  tasks:
d9912c
+  - name: Get Domain from server name
d9912c
+    set_fact:
d9912c
+      ipaserver_domain: "{{ groups.ipaserver[0].split('.')[1:] | join ('.') }}"
d9912c
+    when: ipaserver_domain is not defined
d9912c
+
d9912c
+  - name: Set host1_fqdn .. host6_fqdn
d9912c
+    set_fact:
d9912c
+      host1_fqdn: "{{ 'host1.' + ipaserver_domain }}"
d9912c
+
d9912c
+  - name: Host absent
d9912c
+    ipahost:
d9912c
+      ipaadmin_password: MyPassword123
d9912c
+      name:
d9912c
+      - "{{ host1_fqdn }}"
d9912c
+      update_dns: yes
d9912c
+      state: absent
d9912c
+
d9912c
+  - name: Host "{{ host1_fqdn }}" present with requires_pre_auth, ok_as_delegate and ok_to_auth_as_delegate
d9912c
+    ipahost:
d9912c
+      ipaadmin_password: MyPassword123
d9912c
+      name: "{{ host1_fqdn }}"
d9912c
+      force: yes
d9912c
+      requires_pre_auth: yes
d9912c
+      ok_as_delegate: yes
d9912c
+      ok_to_auth_as_delegate: yes
d9912c
+    register: result
d9912c
+    failed_when: not result.changed
d9912c
+
d9912c
+  - name: Host "{{ host1_fqdn }}" present with requires_pre_auth, ok_as_delegate and ok_to_auth_as_delegate again
d9912c
+    ipahost:
d9912c
+      ipaadmin_password: MyPassword123
d9912c
+      name: "{{ host1_fqdn }}"
d9912c
+      requires_pre_auth: yes
d9912c
+      ok_as_delegate: yes
d9912c
+      ok_to_auth_as_delegate: yes
d9912c
+    register: result
d9912c
+    failed_when: result.changed
d9912c
+
d9912c
+  - name: Host "{{ host1_fqdn }}" present with requires_pre_auth, ok_as_delegate and ok_to_auth_as_delegate set to no
d9912c
+    ipahost:
d9912c
+      ipaadmin_password: MyPassword123
d9912c
+      name: "{{ host1_fqdn }}"
d9912c
+      requires_pre_auth: no
d9912c
+      ok_as_delegate: no
d9912c
+      ok_to_auth_as_delegate: no
d9912c
+    register: result
d9912c
+    failed_when: not result.changed
d9912c
+
d9912c
+  - name: Host "{{ host1_fqdn }}" present with requires_pre_auth, ok_as_delegate and ok_to_auth_as_delegate set to no again
d9912c
+    ipahost:
d9912c
+      ipaadmin_password: MyPassword123
d9912c
+      name: "{{ host1_fqdn }}"
d9912c
+      requires_pre_auth: no
d9912c
+      ok_as_delegate: no
d9912c
+      ok_to_auth_as_delegate: no
d9912c
+    register: result
d9912c
+    failed_when: result.changed
d9912c
+
d9912c
+  - name: Host "{{ host1_fqdn }}" present with requires_pre_auth
d9912c
+    ipahost:
d9912c
+      ipaadmin_password: MyPassword123
d9912c
+      name: "{{ host1_fqdn }}"
d9912c
+      requires_pre_auth: yes
d9912c
+    register: result
d9912c
+    failed_when: not result.changed
d9912c
+
d9912c
+  - name: Host "{{ host1_fqdn }}" present with requires_pre_auth again
d9912c
+    ipahost:
d9912c
+      ipaadmin_password: MyPassword123
d9912c
+      name: "{{ host1_fqdn }}"
d9912c
+      requires_pre_auth: yes
d9912c
+    register: result
d9912c
+    failed_when: result.changed
d9912c
+
d9912c
+  - name: Host "{{ host1_fqdn }}" present with ok_as_delegate
d9912c
+    ipahost:
d9912c
+      ipaadmin_password: MyPassword123
d9912c
+      name: "{{ host1_fqdn }}"
d9912c
+      ok_as_delegate: yes
d9912c
+    register: result
d9912c
+    failed_when: not result.changed
d9912c
+
d9912c
+  - name: Host "{{ host1_fqdn }}" present with ok_as_delegate again
d9912c
+    ipahost:
d9912c
+      ipaadmin_password: MyPassword123
d9912c
+      name: "{{ host1_fqdn }}"
d9912c
+      ok_as_delegate: yes
d9912c
+    register: result
d9912c
+    failed_when: result.changed
d9912c
+
d9912c
+  - name: Host "{{ host1_fqdn }}" present with ok_to_auth_as_delegate
d9912c
+    ipahost:
d9912c
+      ipaadmin_password: MyPassword123
d9912c
+      name: "{{ host1_fqdn }}"
d9912c
+      ok_to_auth_as_delegate: yes
d9912c
+    register: result
d9912c
+    failed_when: not result.changed
d9912c
+
d9912c
+  - name: Host "{{ host1_fqdn }}" present with ok_to_auth_as_delegate again
d9912c
+    ipahost:
d9912c
+      ipaadmin_password: MyPassword123
d9912c
+      name: "{{ host1_fqdn }}"
d9912c
+      ok_to_auth_as_delegate: yes
d9912c
+    register: result
d9912c
+    failed_when: result.changed
d9912c
+
d9912c
+  - name: Host absent
d9912c
+    ipahost:
d9912c
+      ipaadmin_password: MyPassword123
d9912c
+      name:
d9912c
+      - "{{ host1_fqdn }}"
d9912c
+      update_dns: yes
d9912c
+      state: absent