mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-27 10:40:22 -07:00
[PR #3943/12c0220c backport][stable-4] Add option "options" to snap module (#4076)
* Add option "options" to snap module (#3943) * Add functionality proposed in https://github.com/ansible-collections/community.general/issues/666 * Fix pylint errors mentioned in CI pipeline * Fix pylint errors mentioned in CI pipeline (continued) * Update plugins/modules/packaging/os/snap.py Co-authored-by: Felix Fontein <felix@fontein.de> * Apply suggestions from code review Co-authored-by: Felix Fontein <felix@fontein.de> * Added tests Fixed error occurring when called without options Added changelog snippet * Remove changelog entry as suggested in review Co-authored-by: Felix Fontein <felix@fontein.de> * Apply suggestions from code review Co-authored-by: Felix Fontein <felix@fontein.de> * rewrite `if len(overall_options_changed) > 0` in a more Pythonic way un-indent `if len(overall_options_changed) > 0` to only be executed after the options of all snaps have been checked * better placement of local variable `overall_options_changed` * Re-arrange code to reduce indentation level (suggested by reviewer) * Re-arrange code to reduce indentation level (suggested by reviewer, continued) * Re-arrange code to reduce indentation level (suggested by reviewer, continued) Raise exception if option map returned by `snap set` contains list container (suggested by reviewer) Handle Python2 type `long` correctly (suggested by reviewer) Co-authored-by: Felix Fontein <felix@fontein.de> (cherry picked from commit12c0220c59
) * Fix version_added. (cherry picked from commit62d519de10
) Co-authored-by: marcus67 <marcus.rickert@web.de> Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
0f98b63944
commit
d27c06faeb
3 changed files with 236 additions and 25 deletions
|
@ -5,38 +5,38 @@
|
|||
####################################################################
|
||||
|
||||
- block:
|
||||
- name: Make sure package is not installed
|
||||
- name: Make sure package is not installed (hello-world)
|
||||
community.general.snap:
|
||||
name: hello-world
|
||||
state: absent
|
||||
|
||||
- name: Install package (check mode)
|
||||
- name: Install package (hello-world) (check mode)
|
||||
community.general.snap:
|
||||
name: hello-world
|
||||
state: present
|
||||
register: install_check
|
||||
check_mode: true
|
||||
|
||||
- name: Install package
|
||||
- name: Install package (hello-world)
|
||||
community.general.snap:
|
||||
name: hello-world
|
||||
state: present
|
||||
register: install
|
||||
|
||||
- name: Install package again (check mode)
|
||||
- name: Install package again (hello-world) (check mode)
|
||||
community.general.snap:
|
||||
name: hello-world
|
||||
state: present
|
||||
register: install_again_check
|
||||
check_mode: true
|
||||
|
||||
- name: Install package again
|
||||
- name: Install package again (hello-world)
|
||||
community.general.snap:
|
||||
name: hello-world
|
||||
state: present
|
||||
register: install_again
|
||||
|
||||
- name: Assert package has been installed just once
|
||||
- name: Assert package has been installed just once (hello-world)
|
||||
assert:
|
||||
that:
|
||||
- install is changed
|
||||
|
@ -44,38 +44,38 @@
|
|||
- install_again is not changed
|
||||
- install_again_check is not changed
|
||||
|
||||
- name: Check package has been installed correctly
|
||||
- name: Check package has been installed correctly (hello-world)
|
||||
command: hello-world
|
||||
environment:
|
||||
PATH: /var/lib/snapd/snap/bin/
|
||||
|
||||
- name: Remove package (check mode)
|
||||
- name: Remove package (hello-world) (check mode)
|
||||
community.general.snap:
|
||||
name: hello-world
|
||||
state: absent
|
||||
register: remove_check
|
||||
check_mode: true
|
||||
|
||||
- name: Remove package
|
||||
- name: Remove package (hello-world)
|
||||
community.general.snap:
|
||||
name: hello-world
|
||||
state: absent
|
||||
register: remove
|
||||
|
||||
- name: Remove package again (check mode)
|
||||
- name: Remove package again (hello-world) (check mode)
|
||||
community.general.snap:
|
||||
name: hello-world
|
||||
state: absent
|
||||
register: remove_again_check
|
||||
check_mode: true
|
||||
|
||||
- name: Remove package again
|
||||
- name: Remove package again (hello-world)
|
||||
community.general.snap:
|
||||
name: hello-world
|
||||
state: absent
|
||||
register: remove_again
|
||||
|
||||
- name: Assert package has been removed just once
|
||||
- name: Assert package has been removed just once (hello-world)
|
||||
assert:
|
||||
that:
|
||||
- remove is changed
|
||||
|
@ -83,12 +83,12 @@
|
|||
- remove_again is not changed
|
||||
- remove_again_check is not changed
|
||||
|
||||
- name: Make sure package from classic snap is not installed
|
||||
- name: Make sure package from classic snap is not installed (nvim)
|
||||
community.general.snap:
|
||||
name: nvim
|
||||
state: absent
|
||||
|
||||
- name: Install package from classic snap
|
||||
- name: Install package from classic snap (nvim)
|
||||
community.general.snap:
|
||||
name: nvim
|
||||
state: present
|
||||
|
@ -96,14 +96,14 @@
|
|||
register: classic_install
|
||||
|
||||
# testing classic idempotency
|
||||
- name: Install package from classic snap again
|
||||
- name: Install package from classic snap again (nvim)
|
||||
community.general.snap:
|
||||
name: nvim
|
||||
state: present
|
||||
classic: true
|
||||
register: classic_install_again
|
||||
|
||||
- name: Assert package has been installed just once
|
||||
- name: Assert package has been installed just once (nvim)
|
||||
assert:
|
||||
that:
|
||||
- classic_install is changed
|
||||
|
@ -111,22 +111,79 @@
|
|||
|
||||
# this is just testing if a package which has been installed
|
||||
# with true classic can be removed without setting classic to true
|
||||
- name: Remove package from classic snap without setting classic to true
|
||||
- name: Remove package from classic snap without setting classic to true (nvim)
|
||||
community.general.snap:
|
||||
name: nvim
|
||||
state: absent
|
||||
register: classic_remove_without_true_classic
|
||||
|
||||
- name: Remove package from classic snap with setting classic to true
|
||||
- name: Remove package from classic snap with setting classic to true (nvim)
|
||||
community.general.snap:
|
||||
name: nvim
|
||||
state: absent
|
||||
classic: true
|
||||
register: classic_remove_with_true_classic
|
||||
|
||||
- name: Assert package has been removed without setting classic to true
|
||||
- name: Assert package has been removed without setting classic to true (nvim)
|
||||
assert:
|
||||
that:
|
||||
- classic_remove_without_true_classic is changed
|
||||
- classic_remove_with_true_classic is not changed
|
||||
|
||||
|
||||
- name: Make sure package is not installed (uhttpd)
|
||||
community.general.snap:
|
||||
name: uhttpd
|
||||
state: absent
|
||||
|
||||
- name: Install package (uhttpd)
|
||||
community.general.snap:
|
||||
name: uhttpd
|
||||
state: present
|
||||
register: install
|
||||
|
||||
- name: Install package (uhttpd)
|
||||
community.general.snap:
|
||||
name: uhttpd
|
||||
state: present
|
||||
options:
|
||||
- "listening-port=8080"
|
||||
register: install_with_option
|
||||
|
||||
- name: Install package again with option (uhttpd)
|
||||
community.general.snap:
|
||||
name: uhttpd
|
||||
state: present
|
||||
options:
|
||||
- "listening-port=8080"
|
||||
register: install_with_option_again
|
||||
|
||||
- name: Install package again with different options (uhttpd)
|
||||
community.general.snap:
|
||||
name: uhttpd
|
||||
state: present
|
||||
options:
|
||||
- "listening-port=8088"
|
||||
- "document-root-dir=/tmp"
|
||||
register: install_with_option_changed
|
||||
|
||||
- name: Remove package (uhttpd)
|
||||
community.general.snap:
|
||||
name: uhttpd
|
||||
state: absent
|
||||
register: remove
|
||||
|
||||
- name: Assert package has been installed with options just once and only changed options trigger a change (uhttpd)
|
||||
assert:
|
||||
that:
|
||||
- install is changed
|
||||
- install_with_option is changed
|
||||
- "install_with_option.options_changed[0] == 'uhttpd:listening-port=8080'"
|
||||
- install_with_option_again is not changed
|
||||
- install_with_option_changed is changed
|
||||
- "'uhttpd:listening-port=8088' in install_with_option_changed.options_changed"
|
||||
- "'uhttpd:document-root-dir=/tmp' in install_with_option_changed.options_changed"
|
||||
- "'uhttpd:listening-port=8080' not in install_with_option_changed.options_changed"
|
||||
- remove is changed
|
||||
|
||||
when: has_snap
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue