From 75212ad73d32434789fda9d57efb5291e26acfa5 Mon Sep 17 00:00:00 2001 From: Ross Williams Date: Wed, 13 Oct 2021 17:51:12 +0000 Subject: [PATCH] pkgng: clean up test package creation Make pkg json manifest more readable. Create package using FreeBSD's `pkg create` instead of manually using tar. This change also simplifies the manifest to a single file for the integration test role. --- .../pkgng/tasks/create-outofdate-pkg.yml | 59 ++++++++++--------- .../targets/pkgng/templates/MANIFEST.json.j2 | 16 +++++ .../COMPACT_MANIFEST.json.j2 | 1 - .../test_package_manifests/MANIFEST.json.j2 | 1 - .../test_package_metadata.j2 | 1 - 5 files changed, 46 insertions(+), 32 deletions(-) create mode 100644 tests/integration/targets/pkgng/templates/MANIFEST.json.j2 delete mode 100644 tests/integration/targets/pkgng/templates/test_package_manifests/COMPACT_MANIFEST.json.j2 delete mode 100644 tests/integration/targets/pkgng/templates/test_package_manifests/MANIFEST.json.j2 delete mode 100644 tests/integration/targets/pkgng/templates/test_package_manifests/test_package_metadata.j2 diff --git a/tests/integration/targets/pkgng/tasks/create-outofdate-pkg.yml b/tests/integration/targets/pkgng/tasks/create-outofdate-pkg.yml index 8eb890217c..2e8cfd8ae9 100644 --- a/tests/integration/targets/pkgng/tasks/create-outofdate-pkg.yml +++ b/tests/integration/targets/pkgng/tasks/create-outofdate-pkg.yml @@ -1,34 +1,35 @@ --- -- 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 temporary directory for package creation + tempfile: + state: directory + register: pkgng_test_outofdate_pkg_tempdir -- 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: Copy intentionally out-of-date package manifest to testhost + template: + src: MANIFEST.json.j2 + # 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.path }}/MANIFEST' - - name: Create temporary directory to assemble test package - file: - state: directory - path: '{{ pkgng_test_outofdate_pkg_tempdir }}' +- name: Create out-of-date test package file + command: + argv: + - pkg + - create + - '--verbose' + - '--out-dir' + - '{{ pkgng_test_outofdate_pkg_tempdir.path }}' + - '--manifest' + - '{{ pkgng_test_outofdate_pkg_tempdir.path }}/MANIFEST' + warn: no - - name: Copy intentionally out-of-date package manifests to testhost - template: - src: test_package_manifests/{{ item }}.json.j2 - # 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: Copy the created package file to the expected location + copy: + remote_src: yes + src: '{{ pkgng_test_outofdate_pkg_tempdir.path }}/{{ pkgng_test_pkg_name }}-0.pkg' + dest: '{{ pkgng_test_outofdate_pkg_path }}' - - 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 }}' +- name: Remove temporary directory + file: + state: absent + path: '{{ pkgng_test_outofdate_pkg_tempdir.path }}' diff --git a/tests/integration/targets/pkgng/templates/MANIFEST.json.j2 b/tests/integration/targets/pkgng/templates/MANIFEST.json.j2 new file mode 100644 index 0000000000..e8537e89bf --- /dev/null +++ b/tests/integration/targets/pkgng/templates/MANIFEST.json.j2 @@ -0,0 +1,16 @@ +{ + "name": "{{ pkgng_test_pkg_name }}", + "origin": "{{ pkgng_test_pkg_category }}/{{ pkgng_test_pkg_name }}", + "version": "{{ pkgng_test_pkg_version | default('0') }}", + "comment": "{{ pkgng_test_pkg_name }} (Ansible Integration Test Package)", + "maintainer": "ansible-devel@googlegroups.com", + "www": "https://github.com/ansible-collections/community.general", + "abi": "FreeBSD:*:*", + "arch": "freebsd:*:*", + "prefix": "/usr/local", + "flatsize":0, + "licenselogic": "single", + "licenses":["GPLv3"], + "desc": "This package is only installed temporarily for integration testing of the community.general.pkgng Ansible module.\nIts version number is 0 so that ANY version of the real package, with the same name, will be considered an upgrade.\nIts architecture and abi are FreeBSD:*:* so that it will install on any version or architecture of FreeBSD,\nthus future-proof as long as the package MANIFEST format does not change\nand a wildcard in the version portion of the abi or arch field is not prohibited.", + "categories":["{{ pkgng_test_pkg_category }}"] +} diff --git a/tests/integration/targets/pkgng/templates/test_package_manifests/COMPACT_MANIFEST.json.j2 b/tests/integration/targets/pkgng/templates/test_package_manifests/COMPACT_MANIFEST.json.j2 deleted file mode 100644 index 3274d88e1f..0000000000 --- a/tests/integration/targets/pkgng/templates/test_package_manifests/COMPACT_MANIFEST.json.j2 +++ /dev/null @@ -1 +0,0 @@ -{{ '{' }}{% include "test_package_metadata.j2" -%}{{ '}' }} diff --git a/tests/integration/targets/pkgng/templates/test_package_manifests/MANIFEST.json.j2 b/tests/integration/targets/pkgng/templates/test_package_manifests/MANIFEST.json.j2 deleted file mode 100644 index 0a91ef16b2..0000000000 --- a/tests/integration/targets/pkgng/templates/test_package_manifests/MANIFEST.json.j2 +++ /dev/null @@ -1 +0,0 @@ -{{ '{' }}{% include "test_package_metadata.j2" -%},"files":{}{{ '}' }} diff --git a/tests/integration/targets/pkgng/templates/test_package_manifests/test_package_metadata.j2 b/tests/integration/targets/pkgng/templates/test_package_manifests/test_package_metadata.j2 deleted file mode 100644 index ee9ead1e64..0000000000 --- a/tests/integration/targets/pkgng/templates/test_package_manifests/test_package_metadata.j2 +++ /dev/null @@ -1 +0,0 @@ -"name":"{{ pkgng_test_pkg_name }}","origin":"{{ pkgng_test_pkg_category }}/{{ pkgng_test_pkg_name }}","version":"0","comment":"{{ pkgng_test_pkg_name }} (Ansible Integration Test Package)","maintainer":"ansible-devel@googlegroups.com","www":"https://github.com/ansible-collections/community.general","abi":"FreeBSD:*:*","arch":"freebsd:*:*","prefix":"/usr/local","flatsize":0,"licenselogic":"single","licenses":["GPLv3"],"desc":"This package is only installed temporarily for integration testing of the community.general.pkgng Ansible module.\nIts version number is 0 so that ANY version of the real package, with the same name, will be considered an upgrade.\nIts architecture and abi are FreeBSD:*:* so that it will install on any version or architecture of FreeBSD,\nthus future-proof as long as the package MANIFEST format does not change\nand a wildcard in the version portion of the abi or arch field is not prohibited.","categories":["{{ pkgng_test_pkg_category }}"]