From df686dcbd3b85e076c291c3e202a4e1f53c50b65 Mon Sep 17 00:00:00 2001 From: Mark Goddard Date: Thu, 11 Nov 2021 12:02:29 +0000 Subject: [PATCH 1/4] Add pulp_repository tests --- tests/roles | 1 + tests/test_deb_repository.yml | 81 +++++++++++++++++++++++++++++++++++ tests/test_rpm_repository.yml | 79 ++++++++++++++++++++++++++++++++++ 3 files changed, 161 insertions(+) create mode 120000 tests/roles create mode 100644 tests/test_deb_repository.yml create mode 100644 tests/test_rpm_repository.yml diff --git a/tests/roles b/tests/roles new file mode 120000 index 0000000..d8c4472 --- /dev/null +++ b/tests/roles @@ -0,0 +1 @@ +../roles \ No newline at end of file diff --git a/tests/test_deb_repository.yml b/tests/test_deb_repository.yml new file mode 100644 index 0000000..57e6354 --- /dev/null +++ b/tests/test_deb_repository.yml @@ -0,0 +1,81 @@ +--- +- name: Test pulp_repository + gather_facts: false + hosts: localhost + vars: + pulp_url: http://localhost:8080 + pulp_username: admin + pulp_password: password + pulp_validate_certs: true + tasks: + - include_role: + name: pulp_repository + vars: + pulp_repository_deb_repos: + - name: test_deb_repo + url: "https://fixtures.pulpproject.org/debian/" + distributions: "ragnarok" + policy: immediate + state: present + + - name: Query repository + pulp.squeezer.deb_repository: + pulp_url: "{{ pulp_url }}" + username: "{{ pulp_username }}" + password: "{{ pulp_password }}" + validate_certs: "{{ pulp_validate_certs }}" + name: test_deb_repo + register: repo_result + + - name: Verify repository creation + assert: + that: + - repo_result.repository.name == "test_deb_repo" + + - name: Query remote + pulp.squeezer.deb_remote: + pulp_url: "{{ pulp_url }}" + username: "{{ pulp_username }}" + password: "{{ pulp_password }}" + validate_certs: "{{ pulp_validate_certs }}" + name: test_deb_repo-remote + register: remote_result + + - name: Verify remote creation + assert: + that: + - remote_result.remote.name == "test_deb_repo-remote" + - remote_result.remote.url == "https://fixtures.pulpproject.org/debian/" + - remote_result.remote.distributions == "ragnarok" + - remote_result.remote.policy == "immediate" + + - include_role: + name: pulp_repository + vars: + pulp_repository_deb_repos: + - name: test_deb_repo + state: absent + + - name: Query repositories + pulp.squeezer.deb_repository: + pulp_url: "{{ pulp_url }}" + username: "{{ pulp_username }}" + password: "{{ pulp_password }}" + validate_certs: "{{ pulp_validate_certs }}" + register: deb_repositories + + - name: Verify repository deletion + assert: + that: deb_repositories.repositories | length == 0 + + - name: Query remotes + pulp.squeezer.deb_remote: + pulp_url: "{{ pulp_url }}" + username: "{{ pulp_username }}" + password: "{{ pulp_password }}" + validate_certs: "{{ pulp_validate_certs }}" + register: deb_remotes + + - name: Verify remote deletion + assert: + that: deb_remotes.remotes | length == 0 diff --git a/tests/test_rpm_repository.yml b/tests/test_rpm_repository.yml new file mode 100644 index 0000000..b19b861 --- /dev/null +++ b/tests/test_rpm_repository.yml @@ -0,0 +1,79 @@ +--- +- name: Test pulp_repository + gather_facts: false + hosts: localhost + vars: + pulp_url: http://localhost:8080 + pulp_username: admin + pulp_password: password + pulp_validate_certs: true + tasks: + - include_role: + name: pulp_repository + vars: + pulp_repository_rpm_repos: + - name: test_rpm_repo + url: "https://fixtures.pulpproject.org/rpm-unsigned/" + policy: immediate + state: present + + - name: Query repository + pulp.squeezer.rpm_repository: + pulp_url: "{{ pulp_url }}" + username: "{{ pulp_username }}" + password: "{{ pulp_password }}" + validate_certs: "{{ pulp_validate_certs }}" + name: test_rpm_repo + register: repo_result + + - name: Verify repository creation + assert: + that: + - repo_result.repository.name == "test_rpm_repo" + + - name: Query remote + pulp.squeezer.rpm_remote: + pulp_url: "{{ pulp_url }}" + username: "{{ pulp_username }}" + password: "{{ pulp_password }}" + validate_certs: "{{ pulp_validate_certs }}" + name: test_rpm_repo-remote + register: remote_result + + - name: Verify remote creation + assert: + that: + - remote_result.remote.name == "test_rpm_repo-remote" + - remote_result.remote.url == "https://fixtures.pulpproject.org/rpm-unsigned/" + - remote_result.remote.policy == "immediate" + + - include_role: + name: pulp_repository + vars: + pulp_repository_rpm_repos: + - name: test_rpm_repo + state: absent + + - name: Query repositories + pulp.squeezer.rpm_repository: + pulp_url: "{{ pulp_url }}" + username: "{{ pulp_username }}" + password: "{{ pulp_password }}" + validate_certs: "{{ pulp_validate_certs }}" + register: rpm_repositories + + - name: Verify repository deletion + assert: + that: rpm_repositories.repositories | length == 0 + + - name: Query remotes + pulp.squeezer.rpm_remote: + pulp_url: "{{ pulp_url }}" + username: "{{ pulp_username }}" + password: "{{ pulp_password }}" + validate_certs: "{{ pulp_validate_certs }}" + register: rpm_remotes + + - name: Verify remote deletion + assert: + that: rpm_remotes.remotes | length == 0 From b1a78bd767e02b8defb0656793f47e50f1df7e4f Mon Sep 17 00:00:00 2001 From: Mark Goddard Date: Mon, 6 Dec 2021 10:42:23 +0000 Subject: [PATCH 2/4] Add pulp_distribution tests * test distribution from repository * test distribution from repository version * test distribution from another distribution --- tests/test_deb_distribution.yml | 185 ++++++++++++++++++++++++++++++++ tests/test_rpm_distribution.yml | 184 +++++++++++++++++++++++++++++++ 2 files changed, 369 insertions(+) create mode 100644 tests/test_deb_distribution.yml create mode 100644 tests/test_rpm_distribution.yml diff --git a/tests/test_deb_distribution.yml b/tests/test_deb_distribution.yml new file mode 100644 index 0000000..831060c --- /dev/null +++ b/tests/test_deb_distribution.yml @@ -0,0 +1,185 @@ +--- +- name: Test pulp_distribution + gather_facts: false + hosts: localhost + vars: + pulp_url: http://localhost:8080 + pulp_username: admin + pulp_password: password + pulp_validate_certs: true + tasks: + - include_role: + name: pulp_repository + vars: + pulp_repository_deb_repos: + - name: test_deb_repo + url: "https://fixtures.pulpproject.org/debian/" + distributions: "ragnarok" + policy: immediate + state: present + + - include_role: + name: pulp_publication + vars: + pulp_publication_deb: + - repository: test_deb_repo + state: present + + - include_role: + name: pulp_distribution + vars: + pulp_distribution_deb: + - name: test_deb_distribution + base_path: test_deb_distribution + repository: test_deb_repo + state: present + - name: test_deb_distribution_version_1 + base_path: test_deb_distribution_version_1 + repository: test_deb_repo + version: 1 + state: present + + # FIXME: This currently fails due to + # https://github.com/stackhpc/ansible-collection-pulp/issues/34. + # - include_role: + # name: pulp_distribution + # vars: + # pulp_distribution_deb: + # - name: test_deb_distribution_distribution + # base_path: test_deb_distribution_distribution + # distribution: test_deb_distribution + # state: present + + - name: Query repository + pulp.squeezer.deb_repository: + pulp_url: "{{ pulp_url }}" + username: "{{ pulp_username }}" + password: "{{ pulp_password }}" + validate_certs: "{{ pulp_validate_certs }}" + name: test_deb_repo + register: repo_result + + - name: Query publication + pulp.squeezer.deb_publication: + pulp_url: "{{ pulp_url }}" + username: "{{ pulp_username }}" + password: "{{ pulp_password }}" + validate_certs: "{{ pulp_validate_certs }}" + repository: test_deb_repo + version: 1 + register: pub_result + + - name: Query distribution + pulp.squeezer.deb_distribution: + pulp_url: "{{ pulp_url }}" + username: "{{ pulp_username }}" + password: "{{ pulp_password }}" + validate_certs: "{{ pulp_validate_certs }}" + name: test_deb_distribution + register: dist_result + + - name: Query distribution version 1 + pulp.squeezer.deb_distribution: + pulp_url: "{{ pulp_url }}" + username: "{{ pulp_username }}" + password: "{{ pulp_password }}" + validate_certs: "{{ pulp_validate_certs }}" + name: test_deb_distribution_version_1 + register: dist_version_1_result + + # FIXME: This currently fails due to + # https://github.com/stackhpc/ansible-collection-pulp/issues/34. + # - name: Query distribution distribution + # pulp.squeezer.deb_distribution: + # pulp_url: "{{ pulp_url }}" + # username: "{{ pulp_username }}" + # password: "{{ pulp_password }}" + # validate_certs: "{{ pulp_validate_certs }}" + # name: test_deb_distribution_distribution + # register: dist_distribution_result + + - name: Verify publication creation + assert: + that: + - pub_result.publication.repository == repo_result.repository.pulp_href + + - name: Verify distribution creation + assert: + that: + - dist_result.distribution.name == "test_deb_distribution" + - dist_result.distribution.base_path == "test_deb_distribution" + - dist_result.distribution.publication == pub_result.publication.pulp_href + + - name: Verify distribution creation + assert: + that: + - dist_version_1_result.distribution.name == "test_deb_distribution_version_1" + - dist_version_1_result.distribution.base_path == "test_deb_distribution_version_1" + - dist_version_1_result.distribution.publication == pub_result.publication.pulp_href + + # FIXME: This currently fails due to + # https://github.com/stackhpc/ansible-collection-pulp/issues/34. + # - name: Verify distribution creation + # assert: + # that: + # - dist_distribution_result.distribution.name == "test_deb_distribution_distribution" + # - dist_distribution_result.distribution.base_path == "test_deb_distribution_distribution" + # - dist_distribution_result.distribution.publication == pub_result.publication.pulp_href + + - include_role: + name: pulp_distribution + vars: + pulp_distribution_deb: + - name: test_deb_distribution + # FIXME: These should not be required. + repository: test_deb_repo + base_path: foo + state: absent + - name: test_deb_distribution_version_1 + # FIXME: These should not be required. + repository: test_deb_repo + base_path: foo + state: absent + - name: test_deb_distribution_distribution + # FIXME: These should not be required. + repository: test_deb_repo + base_path: foo + state: absent + + - include_role: + name: pulp_publication + vars: + pulp_publication_deb: + - repository: test_deb_repo + state: absent + + - include_role: + name: pulp_repository + vars: + pulp_repository_deb_repos: + - name: test_deb_repo + state: absent + + - name: Query distributions + pulp.squeezer.deb_distribution: + pulp_url: "{{ pulp_url }}" + username: "{{ pulp_username }}" + password: "{{ pulp_password }}" + validate_certs: "{{ pulp_validate_certs }}" + register: deb_distributions + + - name: Verify distribution deletion + assert: + that: deb_distributions.distributions | length == 0 + + - name: Query publications + pulp.squeezer.deb_publication: + pulp_url: "{{ pulp_url }}" + username: "{{ pulp_username }}" + password: "{{ pulp_password }}" + validate_certs: "{{ pulp_validate_certs }}" + register: deb_publications + + - name: Verify publication deletion + assert: + that: deb_publications.publications | length == 0 diff --git a/tests/test_rpm_distribution.yml b/tests/test_rpm_distribution.yml new file mode 100644 index 0000000..c4fe1a2 --- /dev/null +++ b/tests/test_rpm_distribution.yml @@ -0,0 +1,184 @@ +--- +- name: Test pulp_distribution + gather_facts: false + hosts: localhost + vars: + pulp_url: http://localhost:8080 + pulp_username: admin + pulp_password: password + pulp_validate_certs: true + tasks: + - include_role: + name: pulp_repository + vars: + pulp_repository_rpm_repos: + - name: test_rpm_repo + url: "https://fixtures.pulpproject.org/rpm-unsigned/" + policy: immediate + state: present + + - include_role: + name: pulp_publication + vars: + pulp_publication_rpm: + - repository: test_rpm_repo + state: present + + - include_role: + name: pulp_distribution + vars: + pulp_distribution_rpm: + - name: test_rpm_distribution + base_path: test_rpm_distribution + repository: test_rpm_repo + state: present + - name: test_rpm_distribution_version_1 + base_path: test_rpm_distribution_version_1 + repository: test_rpm_repo + version: 1 + state: present + + # FIXME: This currently fails due to + # https://github.com/stackhpc/ansible-collection-pulp/issues/34. + # - include_role: + # name: pulp_distribution + # vars: + # pulp_distribution_rpm: + # - name: test_rpm_distribution_distribution + # base_path: test_rpm_distribution_distribution + # distribution: test_rpm_distribution + # state: present + + - name: Query repository + pulp.squeezer.rpm_repository: + pulp_url: "{{ pulp_url }}" + username: "{{ pulp_username }}" + password: "{{ pulp_password }}" + validate_certs: "{{ pulp_validate_certs }}" + name: test_rpm_repo + register: repo_result + + - name: Query publication + pulp.squeezer.rpm_publication: + pulp_url: "{{ pulp_url }}" + username: "{{ pulp_username }}" + password: "{{ pulp_password }}" + validate_certs: "{{ pulp_validate_certs }}" + repository: test_rpm_repo + version: 1 + register: pub_result + + - name: Query distribution + pulp.squeezer.rpm_distribution: + pulp_url: "{{ pulp_url }}" + username: "{{ pulp_username }}" + password: "{{ pulp_password }}" + validate_certs: "{{ pulp_validate_certs }}" + name: test_rpm_distribution + register: dist_result + + - name: Query distribution version 1 + pulp.squeezer.rpm_distribution: + pulp_url: "{{ pulp_url }}" + username: "{{ pulp_username }}" + password: "{{ pulp_password }}" + validate_certs: "{{ pulp_validate_certs }}" + name: test_rpm_distribution_version_1 + register: dist_version_1_result + + # FIXME: This currently fails due to + # https://github.com/stackhpc/ansible-collection-pulp/issues/34. + # - name: Query distribution distribution + # pulp.squeezer.rpm_distribution: + # pulp_url: "{{ pulp_url }}" + # username: "{{ pulp_username }}" + # password: "{{ pulp_password }}" + # validate_certs: "{{ pulp_validate_certs }}" + # name: test_rpm_distribution_distribution + # register: dist_distribution_result + + - name: Verify publication creation + assert: + that: + - pub_result.publication.repository == repo_result.repository.pulp_href + + - name: Verify distribution creation + assert: + that: + - dist_result.distribution.name == "test_rpm_distribution" + - dist_result.distribution.base_path == "test_rpm_distribution" + - dist_result.distribution.publication == pub_result.publication.pulp_href + + - name: Verify distribution creation + assert: + that: + - dist_version_1_result.distribution.name == "test_rpm_distribution_version_1" + - dist_version_1_result.distribution.base_path == "test_rpm_distribution_version_1" + - dist_version_1_result.distribution.publication == pub_result.publication.pulp_href + + # FIXME: This currently fails due to + # https://github.com/stackhpc/ansible-collection-pulp/issues/34. + # - name: Verify distribution creation + # assert: + # that: + # - dist_distribution_result.distribution.name == "test_rpm_distribution_distribution" + # - dist_distribution_result.distribution.base_path == "test_rpm_distribution_distribution" + # - dist_distribution_result.distribution.publication == pub_result.publication.pulp_href + + - include_role: + name: pulp_distribution + vars: + pulp_distribution_rpm: + - name: test_rpm_distribution + # FIXME: These should not be required. + repository: test_rpm_repo + base_path: foo + state: absent + - name: test_rpm_distribution_version_1 + # FIXME: These should not be required. + repository: test_rpm_repo + base_path: foo + state: absent + - name: test_rpm_distribution_distribution + # FIXME: These should not be required. + repository: test_rpm_repo + base_path: foo + state: absent + + - include_role: + name: pulp_publication + vars: + pulp_publication_rpm: + - repository: test_rpm_repo + state: absent + + - include_role: + name: pulp_repository + vars: + pulp_repository_rpm_repos: + - name: test_rpm_repo + state: absent + + - name: Query distributions + pulp.squeezer.rpm_distribution: + pulp_url: "{{ pulp_url }}" + username: "{{ pulp_username }}" + password: "{{ pulp_password }}" + validate_certs: "{{ pulp_validate_certs }}" + register: rpm_distributions + + - name: Verify distribution deletion + assert: + that: rpm_distributions.distributions | length == 0 + + - name: Query publications + pulp.squeezer.rpm_publication: + pulp_url: "{{ pulp_url }}" + username: "{{ pulp_username }}" + password: "{{ pulp_password }}" + validate_certs: "{{ pulp_validate_certs }}" + register: rpm_publications + + - name: Verify publication deletion + assert: + that: rpm_publications.publications | length == 0 From f757e69e0f9ac4e4679127f73a6f5c19a054c1be Mon Sep 17 00:00:00 2001 From: Mark Goddard Date: Mon, 6 Dec 2021 09:58:55 +0000 Subject: [PATCH 3/4] CI: Add integration test job to pull request workflow --- .github/workflows/pull_request.yml | 21 ++++++++++++++++ tests/pulp-in-one.sh | 39 ++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100755 tests/pulp-in-one.sh diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 7b628c9..3e9f18d 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -32,3 +32,24 @@ jobs: - name: Linting code run: | ansible-lint -v --force-color + + integration: + runs-on: ubuntu-latest + steps: + # Checks-out the repository under $GITHUB_WORKSPACE, so it's accessible to the job + - uses: actions/checkout@v2 + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install ansible==5.* + ansible-galaxy collection install git+file://$(pwd) + + - name: Run Pulp in one + run: | + tests/pulp-in-one.sh + + # TODO: Use ansible-test to run these. + - name: Running integration tests + run: | + ansible-playbook -v tests/*.yml diff --git a/tests/pulp-in-one.sh b/tests/pulp-in-one.sh new file mode 100755 index 0000000..8258c16 --- /dev/null +++ b/tests/pulp-in-one.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +# Run a Pulp in one container, and reset the admin password to 'password'. +# Use only for testing! + +set -eu +set -o pipefail + +mkdir -p settings + +cat << EOF > settings/settings.py +CONTENT_ORIGIN='http://$(hostname):8080' +ANSIBLE_API_HOSTNAME='http://$(hostname):8080' +ANSIBLE_CONTENT_HOSTNAME='http://$(hostname):8080/pulp/content' +TOKEN_AUTH_DISABLED=True +EOF + +# Run Pulp in one container. +docker run \ + --detach \ + --name pulp \ + --volume "$(pwd)/settings":/etc/pulp \ + --publish 8080:80 \ + pulp/pulp:latest + +# Wait for it to come up. +attempts=0 +until curl --fail http://localhost:8080/pulp/api/v3/status/ > /dev/null 2>&1; do + sleep 2 + attempts=$((attempts + 1)) + if [[ $attempts -ge 60 ]]; then + echo "Timed out waiting for pulp" + docker logs pulp + exit 1 + fi +done + +# Reset the admin password. +docker exec pulp pulpcore-manager reset-admin-password --password password From 32ba370db4748f6ebcf52fdca07cee8f9b836f3b Mon Sep 17 00:00:00 2001 From: Mark Goddard Date: Mon, 6 Dec 2021 20:55:39 +0000 Subject: [PATCH 4/4] README: add basic info on running tests --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index 3a03458..2e3d63b 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,20 @@ collections: See [Ansible Using collections](https://docs.ansible.com/ansible/latest/user_guide/collections_using.html) for more details. +## Testing + +The integration tests require a running Pulp server. To run a Pulp in one container for testing: + +``` +tests/pulp-in-one.sh +``` + +Then, to run all of the integration tests: + +``` +ansible-playbook -v tests/*.yml +``` + ## More information - [Ansible Collection overview](https://github.com/ansible-collections/overview)