diff --git a/tests/integration/targets/pkgng/tasks/freebsd.yml b/tests/integration/targets/pkgng/tasks/freebsd.yml index a826212040..f5274d5c5d 100644 --- a/tests/integration/targets/pkgng/tasks/freebsd.yml +++ b/tests/integration/targets/pkgng/tasks/freebsd.yml @@ -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 diff --git a/tests/integration/targets/pkgng/tasks/install_single_package.yml b/tests/integration/targets/pkgng/tasks/install_single_package.yml new file mode 100644 index 0000000000..7115b8a8a1 --- /dev/null +++ b/tests/integration/targets/pkgng/tasks/install_single_package.yml @@ -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