mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-03-22 21:29:19 +00:00
xfconf: fix boolean return values (#11645)
* xfconf: fix boolean return values * add changelog frag
This commit is contained in:
parent
758a445d97
commit
a09e879ff2
3 changed files with 43 additions and 4 deletions
2
changelogs/fragments/11645-xfconf-bool.yml
Normal file
2
changelogs/fragments/11645-xfconf-bool.yml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- xfconf - representation of boolean properties was not consistent between Python and ``xfconf-query``, leading to broken idempotency (https://github.com/ansible-collections/community.general/pull/11645).
|
||||
|
|
@ -174,6 +174,8 @@ version:
|
|||
version_added: 10.2.0
|
||||
"""
|
||||
|
||||
from ansible.module_utils.parsing.convert_bool import boolean
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.module_helper import StateModuleHelper
|
||||
from ansible_collections.community.general.plugins.module_utils.xfconf import get_xfconf_version, xfconf_runner
|
||||
|
||||
|
|
@ -239,9 +241,6 @@ class XFConfProperty(StateModuleHelper):
|
|||
self.vars.value = None
|
||||
|
||||
def state_present(self):
|
||||
# stringify all values - in the CLI they will all be happy strings anyway
|
||||
# and by doing this here the rest of the code can be agnostic to it
|
||||
self.vars.value = [str(v) for v in self.vars.value]
|
||||
value_type = self.vars.value_type
|
||||
|
||||
values_len = len(self.vars.value)
|
||||
|
|
@ -254,6 +253,14 @@ class XFConfProperty(StateModuleHelper):
|
|||
# or complain if lists' lengths are different
|
||||
self.do_raise('Number of elements in "value" and "value_type" must be the same')
|
||||
|
||||
# stringify all values - in the CLI they will all be happy strings anyway
|
||||
# and by doing this here the rest of the code can be agnostic to it
|
||||
# bool values are normalized to 'true'/'false' to match xfconf-query output format
|
||||
self.vars.value = [
|
||||
("true" if boolean(v) else "false") if vt == "bool" else str(v)
|
||||
for v, vt in zip(self.vars.value, value_type)
|
||||
]
|
||||
|
||||
# calculates if it is an array
|
||||
self.vars.is_array = bool(self.vars.force_array) or isinstance(self.vars.previous_value, list) or values_len > 1
|
||||
|
||||
|
|
|
|||
|
|
@ -78,6 +78,36 @@ test_cases:
|
|||
rc: 0
|
||||
out: ''
|
||||
err: ''
|
||||
- id: test_property_set_property_bool_same_value
|
||||
input:
|
||||
channel: xfce4-session
|
||||
property: /general/SaveOnExit
|
||||
state: present
|
||||
value_type: bool
|
||||
value: false
|
||||
output:
|
||||
changed: false
|
||||
previous_value: 'false'
|
||||
type: bool
|
||||
value: 'false'
|
||||
version: 4.18.1
|
||||
mocks:
|
||||
run_command:
|
||||
- command: [/testbin/xfconf-query, --version]
|
||||
environ: *env-def
|
||||
rc: 0
|
||||
out: *version-output
|
||||
err: ''
|
||||
- command: [/testbin/xfconf-query, --channel, xfce4-session, --property, /general/SaveOnExit]
|
||||
environ: *env-def
|
||||
rc: 0
|
||||
out: "false\n"
|
||||
err: ''
|
||||
- command: [/testbin/xfconf-query, --channel, xfce4-session, --property, /general/SaveOnExit, --create, --type, bool, --set, 'false']
|
||||
environ: *env-def
|
||||
rc: 0
|
||||
out: ''
|
||||
err: ''
|
||||
- id: test_property_set_property_bool_false
|
||||
input:
|
||||
channel: xfce4-session
|
||||
|
|
@ -89,7 +119,7 @@ test_cases:
|
|||
changed: true
|
||||
previous_value: 'true'
|
||||
type: bool
|
||||
value: 'False'
|
||||
value: 'false'
|
||||
version: 4.18.1
|
||||
mocks:
|
||||
run_command:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue