mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-30 00:21:23 -07:00
sysrc: refactor (#10417)
Some checks are pending
EOL CI / EOL Sanity (Ⓐ2.16) (push) Waiting to run
EOL CI / EOL Units (Ⓐ2.16+py2.7) (push) Waiting to run
EOL CI / EOL Units (Ⓐ2.16+py3.11) (push) Waiting to run
EOL CI / EOL Units (Ⓐ2.16+py3.6) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.16+alpine3+py:azp/posix/1/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.16+alpine3+py:azp/posix/2/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.16+alpine3+py:azp/posix/3/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.16+fedora38+py:azp/posix/1/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.16+fedora38+py:azp/posix/2/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.16+fedora38+py:azp/posix/3/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.16+opensuse15+py:azp/posix/1/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.16+opensuse15+py:azp/posix/2/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.16+opensuse15+py:azp/posix/3/) (push) Waiting to run
nox / Run extra sanity tests (push) Waiting to run
Some checks are pending
EOL CI / EOL Sanity (Ⓐ2.16) (push) Waiting to run
EOL CI / EOL Units (Ⓐ2.16+py2.7) (push) Waiting to run
EOL CI / EOL Units (Ⓐ2.16+py3.11) (push) Waiting to run
EOL CI / EOL Units (Ⓐ2.16+py3.6) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.16+alpine3+py:azp/posix/1/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.16+alpine3+py:azp/posix/2/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.16+alpine3+py:azp/posix/3/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.16+fedora38+py:azp/posix/1/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.16+fedora38+py:azp/posix/2/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.16+fedora38+py:azp/posix/3/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.16+opensuse15+py:azp/posix/1/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.16+opensuse15+py:azp/posix/2/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.16+opensuse15+py:azp/posix/3/) (push) Waiting to run
nox / Run extra sanity tests (push) Waiting to run
* sysrc: refactor * sysrc: refactor changelog fragment * sysrc: forgot the os import * sysrc: update test to edit the correct file * sysrc: Added copyright info to the test conf file * sysrc: Added full copyright info to the test conf file * sysrc: Detect permission denied when using sysrc * sysrc: Fixed the permission check and 2.7 compatibility * sysrc: Fix typo of import * sysrc: Fix err.find check * sysrc: Add bugfixes changelog fragment * sysrc: Use `StateModuleHelper` * sysrc: updated imports * sysrc: remove re import and set errno.EACCES on the OSError * sysrc: format code properly * sysrc: fix Python 2.7 compatibility and set changed manually * sysrc: add missing name format check Also use `self.module.fail_json` through out * sysrc: Removed os import by accident * sysrc: updated per review, and the way the existing value is retrieved
This commit is contained in:
parent
15d3ea123d
commit
44ca366173
4 changed files with 177 additions and 136 deletions
7
tests/integration/targets/sysrc/files/10394.conf
Normal file
7
tests/integration/targets/sysrc/files/10394.conf
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
|
||||
k1="v1"
|
||||
jail_list="
|
||||
foo
|
||||
bar"
|
|
@ -369,14 +369,79 @@
|
|||
- "value_2 == sysrc_equals_sign_2.value"
|
||||
- "value_2 == conf.spamd_flags"
|
||||
|
||||
##
|
||||
## sysrc - #10004 state=absent when using default settings will report `changed=true`
|
||||
##
|
||||
- name: Test that a key from /etc/defaults/rc.conf is not used to mark changed
|
||||
sysrc:
|
||||
name: dumpdev
|
||||
state: absent
|
||||
path: /tmp/10004.conf
|
||||
register: sysrc_10004_absent
|
||||
failed_when: sysrc_10004_absent.changed
|
||||
|
||||
- name: Test that a delimited key from /etc/defaults/rc.conf is not used to mark changed
|
||||
sysrc:
|
||||
name: rc_conf_files
|
||||
state: value_absent
|
||||
path: /tmp/10004.conf
|
||||
register: sysrc_10004_value_absent
|
||||
failed_when: sysrc_10004_value_absent.changed
|
||||
|
||||
- name: Test that a key from /etc/defaults/rc.conf is not used to mark changed without a path
|
||||
sysrc:
|
||||
name: static_routes
|
||||
state: absent
|
||||
register: sysrc_absent_default
|
||||
failed_when: sysrc_absent_default.changed
|
||||
|
||||
##
|
||||
## sysrc - #10394 Ensure that files with multi-line values work
|
||||
##
|
||||
- name: Copy 10394.conf
|
||||
copy:
|
||||
src: 10394.conf
|
||||
dest: /tmp/10394.conf
|
||||
|
||||
- name: Change value for k1
|
||||
sysrc:
|
||||
name: k1
|
||||
value: v2
|
||||
path: /tmp/10394.conf
|
||||
register: sysrc_10394_changed
|
||||
|
||||
- name: Get file content
|
||||
shell: "cat /tmp/10394.conf"
|
||||
register: sysrc_10394_content
|
||||
|
||||
- name: Ensure sysrc changed k1 from v1 to v2
|
||||
assert:
|
||||
that:
|
||||
- sysrc_10394_changed.changed
|
||||
- >
|
||||
'k1="v2"' in sysrc_10394_content.stdout_lines
|
||||
|
||||
##
|
||||
## sysrc - additional tests
|
||||
##
|
||||
- name: Ensure failure on OID style name since sysrc does not support them
|
||||
sysrc:
|
||||
name: not.valid.var
|
||||
value: test
|
||||
register: sysrc_name_check
|
||||
failed_when:
|
||||
- sysrc_name_check is not failed
|
||||
- >
|
||||
'Name may only contain alpha-numeric and underscore characters' != sysrc_name_check.msg
|
||||
|
||||
always:
|
||||
|
||||
- name: Restore /etc/rc.conf
|
||||
copy:
|
||||
content: "{{ cached_etc_rcconf_content }}"
|
||||
content: "{{ cached_etc_rcconf_content.stdout }}"
|
||||
dest: /etc/rc.conf
|
||||
|
||||
- name: Restore /boot/loader.conf
|
||||
copy:
|
||||
content: "{{ cached_boot_loaderconf_content }}"
|
||||
content: "{{ cached_boot_loaderconf_content.stdout }}"
|
||||
dest: /boot/loader.conf
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue