1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

pkgng: add tests for chroot and rootdir params

Refactor install tasks into an include file so they
can be reused and tested with various parameters.
This commit is contained in:
Ross Williams 2021-10-13 13:56:08 +00:00
parent 220b7e08b6
commit ad42951b66
2 changed files with 73 additions and 86 deletions

View file

@ -10,50 +10,8 @@
##
## pkgng - example - state=present for single package
##
- name: Verify package sentinel file is not present
stat:
path: '{{ pkgng_test_pkg_sentinelfile_path }}'
get_attributes: no
get_checksum: no
get_mime: no
register: pkgng_example1_stat_before
- name: Install package
pkgng:
name: '{{ pkgng_test_pkg_name }}'
register: pkgng_example1
- name: Remove package (checkmode)
pkgng:
name: '{{ pkgng_test_pkg_name }}'
state: absent
check_mode: yes
register: pkgng_example1_checkmode
- name: Install package (idempotent, cached)
pkgng:
name: '{{ pkgng_test_pkg_name }}'
cached: yes
register: pkgng_example1_idempotent_cached
- name: Verify package sentinel file is present
stat:
path: '{{ pkgng_test_pkg_sentinelfile_path }}'
get_attributes: no
get_checksum: no
get_mime: no
register: pkgng_example1_stat_after
- name: Ensure pkgng installs package correctly
assert:
that:
- not pkgng_example1_stat_before.stat.exists
- pkgng_example1.changed
- pkgng_example1_checkmode.changed
- not pkgng_example1_idempotent_cached.changed
- not pkgng_example1_idempotent_cached.stdout is match("Updating \w+ repository catalogue\.\.\.")
- pkgng_example1_stat_after.stat.exists
- pkgng_example1_stat_after.stat.executable
- name: 'state=present for single package'
include_tasks: install_single_package.yml
##
## pkgng - example - state=latest for already up-to-date package
@ -508,51 +466,26 @@
- name: Setup testjail
include: setup-testjail.yml
- name: Verify package sentinel file is not present
stat:
path: '/usr/jails/testjail{{ pkgng_test_pkg_sentinelfile_path }}'
get_attributes: no
get_checksum: no
get_mime: no
register: pkgng_jail_example1_stat_before
- name: Install package in jail as rootdir
include_tasks: install_single_package.yml
vars:
pkgng_test_rootdir: /usr/jails/testjail
pkgng_test_install_prefix: /usr/jails/testjail
pkgng_test_install_cleanup: yes
- name: Install package in jail
pkgng:
name: '{{ pkgng_test_pkg_name }}'
jail: testjail
register: pkgng_jail_example1
include_tasks: install_single_package.yml
vars:
pkgng_test_jail: testjail
pkgng_test_install_prefix: /usr/jails/testjail
pkgng_test_install_cleanup: yes
- name: Remove package (checkmode)
pkgng:
name: '{{ pkgng_test_pkg_name }}'
state: absent
jail: testjail
check_mode: yes
register: pkgng_jail_example1_checkmode
- name: Install package (idempotent)
pkgng:
name: '{{ pkgng_test_pkg_name }}'
jail: testjail
register: pkgng_jail_example1_idempotent
- name: Verify package sentinel file is present
stat:
path: '/usr/jails/testjail{{ pkgng_test_pkg_sentinelfile_path }}'
get_attributes: no
get_checksum: no
get_mime: no
register: pkgng_jail_example1_stat_after
- name: Ensure pkgng installs package correctly
assert:
that:
- not pkgng_jail_example1_stat_before.stat.exists
- pkgng_jail_example1.changed
- pkgng_jail_example1_checkmode.changed
- not pkgng_jail_example1_idempotent.changed
- pkgng_jail_example1_stat_after.stat.exists
- pkgng_jail_example1_stat_after.stat.executable
- name: Install package in jail as chroot
include_tasks: install_single_package.yml
vars:
pkgng_test_chroot: /usr/jails/testjail
pkgng_test_install_prefix: /usr/jails/testjail
pkgng_test_install_cleanup: yes
always:
- name: Stop and remove testjail
failed_when: false

View file

@ -0,0 +1,54 @@
---
- name: Verify package sentinel file is not present
stat:
path: '{{ pkgng_test_install_prefix | default("") }}{{ pkgng_test_pkg_sentinelfile_path }}'
get_attributes: no
get_checksum: no
get_mime: no
register: pkgng_install_stat_before
- name: Install package
pkgng: &pkgng_install_params
name: '{{ pkgng_test_pkg_name }}'
jail: '{{ pkgng_test_jail | default(omit) }}'
chroot: '{{ pkgng_test_chroot | default(omit) }}'
rootdir: '{{ pkgng_test_rootdir | default(omit) }}'
register: pkgng_install
- name: Remove package (checkmode)
pkgng:
<<: *pkgng_install_params
state: absent
check_mode: yes
register: pkgng_install_checkmode
- name: Install package (idempotent, cached)
pkgng:
<<: *pkgng_install_params
cached: yes
register: pkgng_install_idempotent_cached
- name: Verify package sentinel file is present
stat:
path: '{{ pkgng_test_install_prefix | default("") }}{{ pkgng_test_pkg_sentinelfile_path }}'
get_attributes: no
get_checksum: no
get_mime: no
register: pkgng_install_stat_after
- name: Remove test package (if requested)
pkgng:
<<: *pkgng_install_params
state: absent
when: 'pkgng_test_install_cleanup | default(False)'
- name: Ensure pkgng installs package correctly
assert:
that:
- not pkgng_install_stat_before.stat.exists
- pkgng_install.changed
- pkgng_install_checkmode.changed
- not pkgng_install_idempotent_cached.changed
- not pkgng_install_idempotent_cached.stdout is match("Updating \w+ repository catalogue\.\.\.")
- pkgng_install_stat_after.stat.exists
- pkgng_install_stat_after.stat.executable