summaryrefslogtreecommitdiffstats
path: root/awx_collection
diff options
context:
space:
mode:
authorAlan Rominger <arominge@redhat.com>2023-10-24 20:29:16 +0200
committerGitHub <noreply@github.com>2023-10-24 20:29:16 +0200
commitb6b167627ca59a85e81dbc871233717ca692846c (patch)
tree55f3b023796dd14f9252a2f4b3a4d72ae34e75ac /awx_collection
parentFix "upgrade in progress" status page not showing up while migration is in pr... (diff)
downloadawx-b6b167627ca59a85e81dbc871233717ca692846c.tar.xz
awx-b6b167627ca59a85e81dbc871233717ca692846c.zip
Fix Boolean values defaulting to False in collection (#14493)
* Fix Boolean values defaulting to False in collection * Remove null values in other cases, fix null handling for WFJT nodes * Only remove null values if it is a boolean field * Reset changes to WFJT node field processing * Use test content from sean-m-sullivan to fix lookups in assert
Diffstat (limited to 'awx_collection')
-rw-r--r--awx_collection/plugins/module_utils/controller_api.py9
-rw-r--r--awx_collection/tests/integration/targets/host/tasks/main.yml19
-rw-r--r--awx_collection/tests/integration/targets/schedule/tasks/main.yml9
3 files changed, 37 insertions, 0 deletions
diff --git a/awx_collection/plugins/module_utils/controller_api.py b/awx_collection/plugins/module_utils/controller_api.py
index 0c5c191655..166d43c49e 100644
--- a/awx_collection/plugins/module_utils/controller_api.py
+++ b/awx_collection/plugins/module_utils/controller_api.py
@@ -980,6 +980,15 @@ class ControllerAPIModule(ControllerModule):
def create_or_update_if_needed(
self, existing_item, new_item, endpoint=None, item_type='unknown', on_create=None, on_update=None, auto_exit=True, associations=None
):
+ # Remove boolean values of certain specific types
+ # this is needed so that boolean fields will not get a false value when not provided
+ for key in list(new_item.keys()):
+ if key in self.argument_spec:
+ param_spec = self.argument_spec[key]
+ if 'type' in param_spec and param_spec['type'] == 'bool':
+ if new_item[key] is None:
+ new_item.pop(key)
+
if existing_item:
return self.update_if_needed(existing_item, new_item, on_update=on_update, auto_exit=auto_exit, associations=associations)
else:
diff --git a/awx_collection/tests/integration/targets/host/tasks/main.yml b/awx_collection/tests/integration/targets/host/tasks/main.yml
index d7752ca661..2b5d66ff8b 100644
--- a/awx_collection/tests/integration/targets/host/tasks/main.yml
+++ b/awx_collection/tests/integration/targets/host/tasks/main.yml
@@ -42,6 +42,16 @@
that:
- "result is not changed"
+- name: Modify the host as a no-op
+ host:
+ name: "{{ host_name }}"
+ inventory: "{{ inv_name }}"
+ register: result
+
+- assert:
+ that:
+ - "result is not changed"
+
- name: Delete a Host
host:
name: "{{ host_name }}"
@@ -68,6 +78,15 @@
that:
- "result is changed"
+- name: Use lookup to check that host was enabled
+ ansible.builtin.set_fact:
+ host_enabled_test: "lookup('awx.awx.controller_api', 'hosts/{{result.id}}/').enabled"
+
+- name: Newly created host should have API default value for enabled
+ assert:
+ that:
+ - host_enabled_test
+
- name: Delete a Host
host:
name: "{{ result.id }}"
diff --git a/awx_collection/tests/integration/targets/schedule/tasks/main.yml b/awx_collection/tests/integration/targets/schedule/tasks/main.yml
index df7e2d88e3..6f9eca1b33 100644
--- a/awx_collection/tests/integration/targets/schedule/tasks/main.yml
+++ b/awx_collection/tests/integration/targets/schedule/tasks/main.yml
@@ -76,6 +76,15 @@
that:
- result is changed
+ - name: Use lookup to check that schedules was enabled
+ ansible.builtin.set_fact:
+ schedules_enabled_test: "lookup('awx.awx.controller_api', 'schedules/{{result.id}}/').enabled"
+
+ - name: Newly created schedules should have API default value for enabled
+ assert:
+ that:
+ - schedules_enabled_test
+
- name: Build a real schedule with exists
schedule:
name: "{{ sched1 }}"