mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
pkgng: refactor tests for task reuse
Several tests need to install an out-of-date package to test whether upgrades occur successfully, so this commit refactors out the generation of the test package. Also, factor out things like the name and path of the test package so that is more maintainable should the target test package (currently `zsh`) ever need to change.
This commit is contained in:
parent
d075c83ff2
commit
8805f408d6
3 changed files with 79 additions and 55 deletions
|
@ -0,0 +1,34 @@
|
|||
---
|
||||
- name: Check if out-of-date test package has already been created
|
||||
stat:
|
||||
path: '{{ pkgng_test_outofdate_pkg_path }}'
|
||||
register: pkgng_test_outofdate_pkg_stat
|
||||
|
||||
- name: Create out-of-date test package
|
||||
when: not pkgng_test_outofdate_pkg_stat.stat.exists
|
||||
block:
|
||||
- set_fact:
|
||||
pkgng_test_outofdate_pkg_tempdir: '{{ pkgng_test_outofdate_pkg_path }}__tempdir'
|
||||
|
||||
- name: Create temporary directory to assemble test package
|
||||
file:
|
||||
state: directory
|
||||
path: '{{ pkgng_test_outofdate_pkg_tempdir }}'
|
||||
|
||||
- name: Copy intentionally out-of-date package manifests to testhost
|
||||
copy:
|
||||
src: zsh_test_package_manifests/{{ item }}
|
||||
# Plus-sign must be added at the destination
|
||||
# CI doesn't like files with '+' in them in the repository
|
||||
dest: '{{ pkgng_test_outofdate_pkg_tempdir }}/+{{ item }}'
|
||||
loop:
|
||||
- COMPACT_MANIFEST
|
||||
- MANIFEST
|
||||
|
||||
- name: Create out-of-date test package file
|
||||
command: 'tar -C {{ pkgng_test_outofdate_pkg_tempdir }} -cJf {{ pkgng_test_outofdate_pkg_path }} +COMPACT_MANIFEST +MANIFEST'
|
||||
|
||||
- name: Remove temporary directory
|
||||
file:
|
||||
state: absent
|
||||
path: '{{ pkgng_test_outofdate_pkg_tempdir }}'
|
|
@ -2,35 +2,35 @@
|
|||
##
|
||||
## pkgng - example - state=present for single package
|
||||
##
|
||||
- name: Verify zsh binary is not present
|
||||
- name: Verify package sentinel file is not present
|
||||
stat:
|
||||
path: /usr/local/bin/zsh
|
||||
path: '{{ pkgng_test_pkg_sentinelfile_path }}'
|
||||
get_attributes: no
|
||||
get_checksum: no
|
||||
get_mime: no
|
||||
register: pkgng_example1_stat_before
|
||||
|
||||
- name: Install zsh
|
||||
- name: Install package
|
||||
pkgng:
|
||||
name: zsh
|
||||
name: '{{ pkgng_test_pkg_name }}'
|
||||
register: pkgng_example1
|
||||
|
||||
- name: Remove zsh (checkmode)
|
||||
- name: Remove package (checkmode)
|
||||
pkgng:
|
||||
name: zsh
|
||||
name: '{{ pkgng_test_pkg_name }}'
|
||||
state: absent
|
||||
check_mode: yes
|
||||
register: pkgng_example1_checkmode
|
||||
|
||||
- name: Install zsh (idempotent, cached)
|
||||
- name: Install package (idempotent, cached)
|
||||
pkgng:
|
||||
name: zsh
|
||||
name: '{{ pkgng_test_pkg_name }}'
|
||||
cached: yes
|
||||
register: pkgng_example1_idempotent_cached
|
||||
|
||||
- name: Verify zsh binary is present
|
||||
- name: Verify package sentinel file is present
|
||||
stat:
|
||||
path: /usr/local/bin/zsh
|
||||
path: '{{ pkgng_test_pkg_sentinelfile_path }}'
|
||||
get_attributes: no
|
||||
get_checksum: no
|
||||
get_mime: no
|
||||
|
@ -50,9 +50,9 @@
|
|||
##
|
||||
## pkgng - example - state=latest for already up-to-date package
|
||||
##
|
||||
- name: Upgrade zsh (idempotent)
|
||||
- name: Upgrade package (idempotent)
|
||||
pkgng:
|
||||
name: zsh
|
||||
name: '{{ pkgng_test_pkg_name }}'
|
||||
state: latest
|
||||
register: pkgng_example2
|
||||
|
||||
|
@ -61,37 +61,38 @@
|
|||
that:
|
||||
- not pkgng_example2.changed
|
||||
|
||||
##
|
||||
## pkgng - example - state=absent for single package
|
||||
##
|
||||
- name: Verify zsh binary is present
|
||||
- name: Verify package sentinel file is present
|
||||
stat:
|
||||
path: /usr/local/bin/zsh
|
||||
path: '{{ pkgng_test_pkg_sentinelfile_path }}'
|
||||
get_attributes: no
|
||||
get_checksum: no
|
||||
get_mime: no
|
||||
register: pkgng_example3_stat_before
|
||||
|
||||
- name: Install zsh (checkmode)
|
||||
- name: Install package (checkmode)
|
||||
pkgng:
|
||||
name: zsh
|
||||
name: '{{ pkgng_test_pkg_name }}'
|
||||
check_mode: yes
|
||||
register: pkgng_example3_checkmode
|
||||
|
||||
- name: Remove zsh
|
||||
- name: Remove package
|
||||
pkgng:
|
||||
name: zsh
|
||||
name: '{{ pkgng_test_pkg_name }}'
|
||||
state: absent
|
||||
register: pkgng_example3
|
||||
|
||||
- name: Remove zsh (idempotent)
|
||||
- name: Remove package (idempotent)
|
||||
pkgng:
|
||||
name: zsh
|
||||
name: '{{ pkgng_test_pkg_name }}'
|
||||
state: absent
|
||||
register: pkgng_example3_idempotent
|
||||
|
||||
- name: Verify zsh binary is not present
|
||||
- name: Verify package sentinel file is not present
|
||||
stat:
|
||||
path: /usr/local/bin/zsh
|
||||
path: '{{ pkgng_test_pkg_sentinelfile_path }}'
|
||||
get_attributes: no
|
||||
get_checksum: no
|
||||
get_mime: no
|
||||
|
@ -113,7 +114,7 @@
|
|||
- name: Install intentionally out-of-date package and upgrade it
|
||||
#
|
||||
# NOTE: The out-of-date package provided is a minimal,
|
||||
# no-contents test package that declares zsh with
|
||||
# no-contents test package that declares {{ pkgng_test_pkg_name }} with
|
||||
# a version of 0, so it should always be upgraded.
|
||||
#
|
||||
# This test might fail at some point in the
|
||||
|
@ -122,26 +123,11 @@
|
|||
# older package formats.
|
||||
#
|
||||
block:
|
||||
- name: Create temporary directory to assemble test package
|
||||
file:
|
||||
state: directory
|
||||
path: /tmp/zsh_test_package
|
||||
|
||||
- name: Copy intentionally out-of-date package manifests to testhost
|
||||
copy:
|
||||
src: zsh_test_package_manifests/{{ item }}
|
||||
# Plus-sign must be added at the destination
|
||||
# CI doesn't like files with '+' in them in the repository
|
||||
dest: /tmp/zsh_test_package/+{{ item }}
|
||||
loop:
|
||||
- COMPACT_MANIFEST
|
||||
- MANIFEST
|
||||
|
||||
- name: Create out-of-date test package
|
||||
command: tar -C /tmp/zsh_test_package -cJf /tmp/zsh-0__test.pkg +COMPACT_MANIFEST +MANIFEST
|
||||
import_tasks: create-outofdate-pkg.yml
|
||||
|
||||
- name: Install out-of-date test package
|
||||
command: pkg add /tmp/zsh-0__test.pkg
|
||||
command: 'pkg add {{ pkgng_test_outofdate_pkg_path }}'
|
||||
register: pkgng_example4_prepare
|
||||
|
||||
- name: Check for any available package upgrades (checkmode)
|
||||
|
@ -153,26 +139,26 @@
|
|||
|
||||
- name: Check for available package upgrade (checkmode)
|
||||
pkgng:
|
||||
name: zsh
|
||||
name: '{{ pkgng_test_pkg_name }}'
|
||||
state: latest
|
||||
check_mode: yes
|
||||
register: pkgng_example4_checkmode
|
||||
|
||||
- name: Upgrade out-of-date package
|
||||
pkgng:
|
||||
name: zsh
|
||||
name: '{{ pkgng_test_pkg_name }}'
|
||||
state: latest
|
||||
register: pkgng_example4
|
||||
|
||||
- name: Upgrade out-of-date package (idempotent)
|
||||
pkgng:
|
||||
name: zsh
|
||||
name: '{{ pkgng_test_pkg_name }}'
|
||||
state: latest
|
||||
register: pkgng_example4_idempotent
|
||||
|
||||
- name: Remove test out-of-date package
|
||||
pkgng:
|
||||
name: zsh
|
||||
name: '{{ pkgng_test_pkg_name }}'
|
||||
state: absent
|
||||
|
||||
- name: Ensure pkgng upgrades package correctly
|
||||
|
@ -185,7 +171,7 @@
|
|||
- not pkgng_example4_idempotent.changed
|
||||
|
||||
##
|
||||
## pkgng - example - Install zsh in jail
|
||||
## pkgng - example - Install single package in jail
|
||||
##
|
||||
- name: Test within jail
|
||||
#
|
||||
|
@ -197,37 +183,37 @@
|
|||
- name: Setup testjail
|
||||
include: setup-testjail.yml
|
||||
|
||||
- name: Verify zsh binary is not present
|
||||
- name: Verify package sentinel file is not present
|
||||
stat:
|
||||
path: /usr/jails/testjail/usr/local/bin/zsh
|
||||
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 zsh
|
||||
- name: Install package in jail
|
||||
pkgng:
|
||||
name: zsh
|
||||
name: '{{ pkgng_test_pkg_name }}'
|
||||
jail: testjail
|
||||
register: pkgng_jail_example1
|
||||
|
||||
- name: Remove zsh (checkmode)
|
||||
- name: Remove package (checkmode)
|
||||
pkgng:
|
||||
name: zsh
|
||||
name: '{{ pkgng_test_pkg_name }}'
|
||||
state: absent
|
||||
jail: testjail
|
||||
check_mode: yes
|
||||
register: pkgng_jail_example1_checkmode
|
||||
|
||||
- name: Install zsh (idempotent)
|
||||
- name: Install package (idempotent)
|
||||
pkgng:
|
||||
name: zsh
|
||||
name: '{{ pkgng_test_pkg_name }}'
|
||||
jail: testjail
|
||||
register: pkgng_jail_example1_idempotent
|
||||
|
||||
- name: Verify zsh binary is present
|
||||
- name: Verify package sentinel file is present
|
||||
stat:
|
||||
path: /usr/jails/testjail/usr/local/bin/zsh
|
||||
path: '/usr/jails/testjail{{ pkgng_test_pkg_sentinelfile_path }}'
|
||||
get_attributes: no
|
||||
get_checksum: no
|
||||
get_mime: no
|
||||
|
|
4
tests/integration/targets/pkgng/vars/main.yml
Normal file
4
tests/integration/targets/pkgng/vars/main.yml
Normal file
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
pkgng_test_outofdate_pkg_path: "/tmp/zsh-0__test.pkg"
|
||||
pkgng_test_pkg_name: zsh
|
||||
pkgng_test_pkg_sentinelfile_path: /usr/local/bin/zsh
|
Loading…
Reference in a new issue