mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
Add module to manipulate KDE config files using kwriteconfig (#6182)
* Add module to manipulate KDE config files using kwriteconfig * Fix license issues * Apply suggestions from code review Co-authored-by: Felix Fontein <felix@fontein.de> * Add smeso as kdeconfig.py maintainer * Fix attributes fragment name * Fix test * Do not use shutil.chown It isn't available on old Python versions * Apply suggestions from code review Co-authored-by: Felix Fontein <felix@fontein.de> --------- Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
59e58079cb
commit
997761878c
6 changed files with 698 additions and 0 deletions
5
tests/integration/targets/kdeconfig/aliases
Normal file
5
tests/integration/targets/kdeconfig/aliases
Normal file
|
@ -0,0 +1,5 @@
|
|||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
azp/posix/2
|
7
tests/integration/targets/kdeconfig/meta/main.yml
Normal file
7
tests/integration/targets/kdeconfig/meta/main.yml
Normal file
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
dependencies:
|
||||
- setup_remote_tmp_dir
|
38
tests/integration/targets/kdeconfig/tasks/files/kwriteconf_fake
Executable file
38
tests/integration/targets/kdeconfig/tasks/files/kwriteconf_fake
Executable file
|
@ -0,0 +1,38 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Copyright (c) 2023, Salvatore Mesoraca <s.mesoraca16@gmail.com>
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
# This script is not supposed to correctly emulate
|
||||
# kwriteconf output format.
|
||||
# It only tries to emulate its behaviour from the
|
||||
# point of view of the Ansible module.
|
||||
# Which is: write something that depends on the arguments
|
||||
# to the output file, unless we already wrote that before.
|
||||
|
||||
set -e
|
||||
|
||||
args=""
|
||||
prev_was_file=0
|
||||
for var in "$@"; do
|
||||
if [ $prev_was_file -eq 1 ]; then
|
||||
fname="$var"
|
||||
prev_was_file=0
|
||||
else
|
||||
args="$args $var"
|
||||
fi
|
||||
if [ "$var" = "--file" ]; then
|
||||
prev_was_file=1
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "x$fname" = "x" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -e "$fname" ]; then
|
||||
grep -qF "$args" "$fname" && exit 0
|
||||
fi
|
||||
|
||||
echo "$args" >> "$fname"
|
369
tests/integration/targets/kdeconfig/tasks/main.yml
Normal file
369
tests/integration/targets/kdeconfig/tasks/main.yml
Normal file
|
@ -0,0 +1,369 @@
|
|||
---
|
||||
####################################################################
|
||||
# WARNING: These are designed specifically for Ansible tests #
|
||||
# and should not be used as examples of how to write Ansible roles #
|
||||
####################################################################
|
||||
|
||||
# Copyright (c) 2023, Salvatore Mesoraca <s.mesoraca16@gmail.com>
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
- name: Set paths
|
||||
set_fact:
|
||||
output_file: "{{ remote_tmp_dir }}/kdeconf"
|
||||
kwriteconf_fake: "{{ remote_tmp_dir }}/kwriteconf"
|
||||
|
||||
- name: Install fake kwriteconf
|
||||
copy:
|
||||
dest: "{{ kwriteconf_fake }}"
|
||||
src: kwriteconf_fake
|
||||
mode: 0755
|
||||
|
||||
- name: Simple test
|
||||
kdeconfig:
|
||||
path: "{{ output_file }}"
|
||||
values:
|
||||
- group: test
|
||||
key: test1
|
||||
value: test2
|
||||
kwriteconfig_path: "{{ kwriteconf_fake }}"
|
||||
register: result_simple
|
||||
ignore_errors: true
|
||||
|
||||
- name: Simple test - checks
|
||||
assert:
|
||||
that:
|
||||
- result_simple is changed
|
||||
- result_simple is not failed
|
||||
|
||||
- name: Simple test - idempotence
|
||||
kdeconfig:
|
||||
path: "{{ output_file }}"
|
||||
values:
|
||||
- group: test
|
||||
key: test1
|
||||
value: test2
|
||||
kwriteconfig_path: "{{ kwriteconf_fake }}"
|
||||
register: result_simple_idem
|
||||
ignore_errors: true
|
||||
|
||||
- name: Simple test - idempotence - checks
|
||||
assert:
|
||||
that:
|
||||
- result_simple_idem is not changed
|
||||
- result_simple_idem is not failed
|
||||
|
||||
- name: Reset
|
||||
file:
|
||||
path: "{{ output_file }}"
|
||||
state: absent
|
||||
|
||||
- name: Group and groups are mutually exclusive
|
||||
kdeconfig:
|
||||
path: "{{ output_file }}"
|
||||
values:
|
||||
- group: test
|
||||
groups: [test2]
|
||||
key: test1
|
||||
value: test2
|
||||
kwriteconfig_path: "{{ kwriteconf_fake }}"
|
||||
register: result_group_mutex
|
||||
ignore_errors: true
|
||||
|
||||
- name: Group and groups are mutually exclusive - checks
|
||||
assert:
|
||||
that:
|
||||
- result_group_mutex is not changed
|
||||
- result_group_mutex is failed
|
||||
- "result_group_mutex.msg == 'parameters are mutually exclusive: group|groups found in values'"
|
||||
|
||||
- name: value and bool_value are mutually exclusive
|
||||
kdeconfig:
|
||||
path: "{{ output_file }}"
|
||||
values:
|
||||
- group: test
|
||||
key: test1
|
||||
value: test2
|
||||
bool_value: true
|
||||
kwriteconfig_path: "{{ kwriteconf_fake }}"
|
||||
register: result_val_mutex
|
||||
ignore_errors: true
|
||||
|
||||
- name: value and bool_value are mutually exclusive - checks
|
||||
assert:
|
||||
that:
|
||||
- result_val_mutex is not changed
|
||||
- result_val_mutex is failed
|
||||
- "result_val_mutex.msg == 'parameters are mutually exclusive: value|bool_value found in values'"
|
||||
|
||||
- name: bool_value must be bool
|
||||
kdeconfig:
|
||||
path: "{{ output_file }}"
|
||||
values:
|
||||
- group: test
|
||||
key: test1
|
||||
bool_value: thisisastring
|
||||
kwriteconfig_path: "{{ kwriteconf_fake }}"
|
||||
register: result_val_bool
|
||||
ignore_errors: true
|
||||
|
||||
- name: bool_value must be bool - checks
|
||||
assert:
|
||||
that:
|
||||
- result_val_bool is not changed
|
||||
- result_val_bool is failed
|
||||
- "'is not a valid boolean' in result_val_bool.msg"
|
||||
|
||||
- name: Multiple groups test
|
||||
kdeconfig:
|
||||
path: "{{ output_file }}"
|
||||
values:
|
||||
- groups:
|
||||
- test
|
||||
- test1
|
||||
- test2
|
||||
key: test3
|
||||
value: test4
|
||||
kwriteconfig_path: "{{ kwriteconf_fake }}"
|
||||
register: result_groups
|
||||
ignore_errors: true
|
||||
|
||||
- name: Multiple groups test - checks
|
||||
assert:
|
||||
that:
|
||||
- result_groups is changed
|
||||
- result_groups is not failed
|
||||
|
||||
- name: Multiple groups test - idempotence
|
||||
kdeconfig:
|
||||
path: "{{ output_file }}"
|
||||
values:
|
||||
- groups:
|
||||
- test
|
||||
- test1
|
||||
- test2
|
||||
key: test3
|
||||
value: test4
|
||||
kwriteconfig_path: "{{ kwriteconf_fake }}"
|
||||
register: result_groups_idem
|
||||
ignore_errors: true
|
||||
|
||||
- name: Multiple groups test - idempotence - checks
|
||||
assert:
|
||||
that:
|
||||
- result_groups_idem is not changed
|
||||
- result_groups_idem is not failed
|
||||
|
||||
- name: Reset
|
||||
file:
|
||||
path: "{{ output_file }}"
|
||||
state: absent
|
||||
|
||||
- name: Bool test
|
||||
kdeconfig:
|
||||
path: "{{ output_file }}"
|
||||
values:
|
||||
- group: test
|
||||
key: test1
|
||||
bool_value: true
|
||||
kwriteconfig_path: "{{ kwriteconf_fake }}"
|
||||
register: result_bool
|
||||
ignore_errors: true
|
||||
|
||||
- name: Simple test - checks
|
||||
assert:
|
||||
that:
|
||||
- result_bool is changed
|
||||
- result_bool is not failed
|
||||
|
||||
- name: Bool test - idempotence
|
||||
kdeconfig:
|
||||
path: "{{ output_file }}"
|
||||
values:
|
||||
- group: test
|
||||
key: test1
|
||||
bool_value: on
|
||||
kwriteconfig_path: "{{ kwriteconf_fake }}"
|
||||
register: result_bool_idem
|
||||
ignore_errors: true
|
||||
|
||||
- name: Bool test - idempotence - checks
|
||||
assert:
|
||||
that:
|
||||
- result_bool_idem is not changed
|
||||
- result_bool_idem is not failed
|
||||
|
||||
- name: Reset
|
||||
file:
|
||||
path: "{{ output_file }}"
|
||||
state: absent
|
||||
|
||||
- name: check_mode test
|
||||
kdeconfig:
|
||||
path: "{{ output_file }}"
|
||||
values:
|
||||
- group: test
|
||||
key: test1
|
||||
value: test2
|
||||
- groups: [testx, testy]
|
||||
key: testz
|
||||
bool_value: on
|
||||
kwriteconfig_path: "{{ kwriteconf_fake }}"
|
||||
register: result_checkmode
|
||||
ignore_errors: true
|
||||
check_mode: true
|
||||
diff: true
|
||||
|
||||
- name: check_mode test file contents
|
||||
slurp:
|
||||
src: "{{ output_file }}"
|
||||
register: check_mode_contents
|
||||
ignore_errors: true
|
||||
|
||||
- name: check_mode test - checks
|
||||
assert:
|
||||
that:
|
||||
- result_checkmode is changed
|
||||
- result_checkmode is not failed
|
||||
- check_mode_contents is failed
|
||||
|
||||
- name: check_mode test - apply
|
||||
kdeconfig:
|
||||
path: "{{ output_file }}"
|
||||
values:
|
||||
- group: test
|
||||
key: test1
|
||||
value: test2
|
||||
- groups: [testx, testy]
|
||||
key: testz
|
||||
bool_value: on
|
||||
kwriteconfig_path: "{{ kwriteconf_fake }}"
|
||||
register: result_checkmode_apply
|
||||
ignore_errors: true
|
||||
check_mode: false
|
||||
diff: true
|
||||
|
||||
- name: check_mode test - apply - checks
|
||||
assert:
|
||||
that:
|
||||
- result_checkmode_apply is changed
|
||||
- result_checkmode_apply is not failed
|
||||
- "result_checkmode_apply['diff']['after'] == result_checkmode['diff']['after']"
|
||||
- "result_checkmode_apply['diff']['before'] == result_checkmode['diff']['before']"
|
||||
|
||||
- name: check_mode test - idempotence
|
||||
kdeconfig:
|
||||
path: "{{ output_file }}"
|
||||
values:
|
||||
- group: test
|
||||
key: test1
|
||||
value: test2
|
||||
- groups: [testx, testy]
|
||||
key: testz
|
||||
bool_value: on
|
||||
kwriteconfig_path: "{{ kwriteconf_fake }}"
|
||||
register: result_checkmode2
|
||||
ignore_errors: true
|
||||
check_mode: true
|
||||
|
||||
- name: check_mode test - idempotence - checks
|
||||
assert:
|
||||
that:
|
||||
- result_checkmode2 is not changed
|
||||
- result_checkmode2 is not failed
|
||||
|
||||
- name: Reset
|
||||
file:
|
||||
path: "{{ output_file }}"
|
||||
state: absent
|
||||
|
||||
- name: Unicode test
|
||||
kdeconfig:
|
||||
path: "{{ output_file }}"
|
||||
values:
|
||||
- group: tesòt
|
||||
key: testè1
|
||||
value: testù2
|
||||
kwriteconfig_path: "{{ kwriteconf_fake }}"
|
||||
register: result_unicode
|
||||
ignore_errors: true
|
||||
|
||||
- name: Unicode test - checks
|
||||
assert:
|
||||
that:
|
||||
- result_unicode is changed
|
||||
- result_unicode is not failed
|
||||
|
||||
- name: Reset
|
||||
file:
|
||||
path: "{{ output_file }}"
|
||||
state: absent
|
||||
|
||||
- name: Missing groups
|
||||
kdeconfig:
|
||||
path: "{{ output_file }}"
|
||||
values:
|
||||
- key: test1
|
||||
value: test2
|
||||
kwriteconfig_path: "{{ kwriteconf_fake }}"
|
||||
register: result_mgroup
|
||||
ignore_errors: true
|
||||
|
||||
- name: Missing groups - checks
|
||||
assert:
|
||||
that:
|
||||
- result_mgroup is not changed
|
||||
- result_mgroup is failed
|
||||
- "result_mgroup.msg == 'one of the following is required: group, groups found in values'"
|
||||
|
||||
- name: Missing key
|
||||
kdeconfig:
|
||||
path: "{{ output_file }}"
|
||||
values:
|
||||
- group: test1
|
||||
value: test2
|
||||
kwriteconfig_path: "{{ kwriteconf_fake }}"
|
||||
register: result_mkey
|
||||
ignore_errors: true
|
||||
|
||||
- name: Missing key - checks
|
||||
assert:
|
||||
that:
|
||||
- result_mkey is not changed
|
||||
- result_mkey is failed
|
||||
- "result_mkey.msg == 'missing required arguments: key found in values'"
|
||||
|
||||
- name: Missing value
|
||||
kdeconfig:
|
||||
path: "{{ output_file }}"
|
||||
values:
|
||||
- group: test1
|
||||
key: test2
|
||||
kwriteconfig_path: "{{ kwriteconf_fake }}"
|
||||
register: result_mvalue
|
||||
ignore_errors: true
|
||||
|
||||
- name: Missing value - checks
|
||||
assert:
|
||||
that:
|
||||
- result_mvalue is not changed
|
||||
- result_mvalue is failed
|
||||
- "result_mvalue.msg == 'one of the following is required: value, bool_value found in values'"
|
||||
|
||||
- name: Empty key
|
||||
kdeconfig:
|
||||
path: "{{ output_file }}"
|
||||
values:
|
||||
- group: test1
|
||||
key:
|
||||
value: test2
|
||||
kwriteconfig_path: "{{ kwriteconf_fake }}"
|
||||
register: result_ekey
|
||||
ignore_errors: true
|
||||
|
||||
- name: Empty key - checks
|
||||
assert:
|
||||
that:
|
||||
- result_ekey is not changed
|
||||
- result_ekey is failed
|
||||
- "result_ekey.msg == \"'key' cannot be empty\""
|
Loading…
Add table
Add a link
Reference in a new issue