diff --git a/.github/files/ci.py b/.github/files/ci.py new file mode 100644 index 0000000..817434b --- /dev/null +++ b/.github/files/ci.py @@ -0,0 +1,11 @@ +import action_lib + +env = action_lib.OCIEnvIntegrationTest( + envs=[ + { + "env_file": "standalone.compose.env", + "run_tests": False, + "db_restore": None, + } + ] +) diff --git a/.github/files/galaxy.yml.j2 b/.github/files/galaxy.yml.j2 new file mode 100644 index 0000000..fb7911f --- /dev/null +++ b/.github/files/galaxy.yml.j2 @@ -0,0 +1,30 @@ +--- +authors: + - Sean Sullivan @sean-m-sullivan + - Tom Page @Tompage1994 + - David Danielsson @djdanielsson +dependencies: {} +description: Ansible content that interacts with the Ansible Automation Hub API +documentation: https://github.com/ansible-collections/ansible_hub/blob/main/README.md +license: + - GPL-3.0-only +namespace: {{ collection_namespace }} +name: {{ collection_name }} +version: {{ collection_version }} +readme: README.md +repository: {{ collection_repo }} +issues: {{ collection_repo }}/issues +tags: + - cloud + - infrastructure + - galaxy + - ansible + - galaxy + - automation +build_ignore: + - tools + - setup.cfg + - galaxy.yml.j2 + - template_galaxy.yml + - '*.tar.gz' +... diff --git a/.github/workflows/ansible-test.yml b/.github/workflows/ansible-test.yml index d831a0e..73ce9e5 100644 --- a/.github/workflows/ansible-test.yml +++ b/.github/workflows/ansible-test.yml @@ -166,110 +166,6 @@ jobs: # https://github.com/ansible-community/ansible-test-gh-action#pull-request-change-detection pull-request-change-detection: false -### -# Integration tests (RECOMMENDED) -# -# https://docs.ansible.com/ansible/latest/dev_guide/testing_integration.html - - -# If the application you are testing is available as a docker container and you want to test -# multiple versions see the following for an example: -# https://github.com/ansible-collections/community.zabbix/tree/master/.github/workflows - - integration: - # Ansible-test on various stable branches does not yet work well with cgroups v2. - # Since ubuntu-latest now uses Ubuntu 22.04, we need to fall back to the ubuntu-20.04 - # image for these stable branches. The list of branches where this is necessary will - # shrink over time, check out https://github.com/ansible-collections/news-for-maintainers/issues/28 - # for the latest list. - runs-on: >- - ${{ contains(fromJson( - '["stable-2.9", "stable-2.10", "stable-2.11"]' - ), matrix.ansible) && 'ubuntu-20.04' || 'ubuntu-latest' }} - name: I (Ⓐ${{ matrix.ansible }}+py${{ matrix.python }}) - strategy: - fail-fast: false - matrix: - ansible: - - devel - # - milestone - python: - - '3.8' - - '3.9' - - '3.10' - - '3.11' - - '3.12' - include: - # Add new versions announced in - # https://github.com/ansible-collections/news-for-maintainers in a timely manner, - # consider dropping testing against EOL versions and versions you don't support. - # ansible-core 2.15 - - ansible: stable-2.15 - python: '3.5' - - ansible: stable-2.15 - python: '3.6' - - ansible: stable-2.15 - python: '3.7' - - ansible: stable-2.15 - python: '3.8' - - ansible: stable-2.15 - python: '3.9' - - ansible: stable-2.15 - python: '3.10' - - ansible: stable-2.15 - python: '3.11' - # ansible-core 2.16 - - ansible: stable-2.16 - python: '3.6' - - ansible: stable-2.16 - python: '3.7' - - ansible: stable-2.16 - python: '3.8' - - ansible: stable-2.16 - python: '3.9' - - ansible: stable-2.16 - python: '3.10' - - ansible: stable-2.16 - python: '3.11' - - ansible: stable-2.16 - python: '3.12' - # ansible-core 2.17 - - ansible: stable-2.17 - python: '3.7' - - ansible: stable-2.17 - python: '3.8' - - ansible: stable-2.17 - python: '3.9' - - ansible: stable-2.17 - python: '3.10' - - ansible: stable-2.17 - python: '3.11' - - ansible: stable-2.17 - python: '3.12' - - - steps: - - name: >- - Perform integration testing against - Ansible version ${{ matrix.ansible }} - under Python ${{ matrix.python }} - # See the documentation for the following GitHub action on - # https://github.com/ansible-community/ansible-test-gh-action/blob/main/README.md - uses: ansible-community/ansible-test-gh-action@release/v1 - with: - ansible-core-version: ${{ matrix.ansible }} - # OPTIONAL command to run before invoking `ansible-test integration` - # pre-test-cmd: - target-python-version: ${{ matrix.python }} - testing-type: integration - # OPTIONAL If your integration tests require code - # from other collections, install them like this - test-deps: ansible.netcommon - # OPTIONAL If set to true, will test only against changed files, - # which should improve CI performance. See limitations on - # https://github.com/ansible-community/ansible-test-gh-action#pull-request-change-detection - pull-request-change-detection: false - check: # This job does nothing and is only used for the branch protection # or multi-stage CI jobs, like making sure that all tests pass before @@ -279,7 +175,6 @@ jobs: needs: - sanity - units - - integration runs-on: ubuntu-latest diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml new file mode 100644 index 0000000..5e85fe2 --- /dev/null +++ b/.github/workflows/integration.yml @@ -0,0 +1,128 @@ +--- +name: Test integration tests with galaxy_ng + +on: + # Run CI against all pushes (direct commits, also merged PRs), Pull Requests + push: + branches: + - main + - stable-* + pull_request: + # Run CI once per day (at 06:00 UTC) + # This ensures that even if there haven't been commits that we are still testing against latest version of ansible-test for each ansible-base version + schedule: + - cron: '0 6 * * *' + +jobs: + + integration: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + galaxy_ng_version: + # - stable-4.8 + # - stable-4.9 + - master + steps: + - uses: actions/checkout@v2 + with: + ref: ${{ github.event.pull_request.head.sha || github.sha }} + + - name: Build and install the collection + id: build + uses: redhat-cop/ansible_collections_tooling/actions/build_ansible_collection@main + with: + collection_namespace: ansible + collection_name: hub + collection_version: 1.0.0 + collection_repo: https://github.com/ansible-collections/ansible_hub + + - name: "Checkout galaxy_ng" + uses: actions/checkout@v2 + with: + repository: ansible/galaxy_ng + path: galaxy_ng + ref: ${{ matrix.galaxy_ng_version }} + + - name: (Linux) Install docker compose + run: | + curl -L -o /tmp/docker-compose https://github.com/docker/compose/releases/download/v2.29.1/docker-compose-linux-x86_64 + install /tmp/docker-compose /usr/local/bin/ + + # Note: COMPOSE_INTERACTIVE_NO_CLI=1 is required for oci-env to work correctly when there's no interactive terminal + - name: Set environment variables + working-directory: galaxy_ng + run: | + echo "OCI_ENV_PATH=${GITHUB_WORKSPACE}/oci_env" >> $GITHUB_ENV + echo "COMPOSE_INTERACTIVE_NO_CLI=1" >> $GITHUB_ENV + echo "OCI_VERBOSE=1" >> $GITHUB_ENV + echo "GH_DUMP_LOGS=1" >> $GITHUB_ENV + echo "GH_TEARDOWN=0" >> $GITHUB_ENV + echo "AH_HOST=http://localhost:55001/" >> $GITHUB_ENV + echo "AH_USERNAME=admin" >> $GITHUB_ENV + echo "AH_PASSWORD=admin" >> $GITHUB_ENV + + - name: Update apt + run: sudo apt -y update + + - name: Install LDAP requirements + run: sudo apt-get install -y libsasl2-dev python3 libldap2-dev libssl-dev build-essential + + - name: setup oci-env + working-directory: galaxy_ng + run: | + git clone https://github.com/pulp/oci_env.git $OCI_ENV_PATH + pip install -e $OCI_ENV_PATH/client/ + mkdir $OCI_ENV_PATH/db_backup/ + + - name: Move ci cfg to oci + run: mv .github/files/ci.py ./galaxy_ng/dev/oci_env_integration/actions/ci.py + + - name: Stand up galaxy_ng + working-directory: galaxy_ng + run: python3 dev/oci_env_integration/actions/ci.py + + - name: Create integration config + working-directory: /home/runner/collections/ansible_collections/ansible/hub/tests/integration/ + run: | + echo "ah_host: 'http://localhost:55001/'" > integration_config.yml + echo "ah_username: admin" >> integration_config.yml + echo "ah_password: admin" >> integration_config.yml + echo "ah_verify_ssl: false" >> integration_config.yml + + - name: Run integration test - ah_namespace + run: ansible-test integration ah_namespace + working-directory: /home/runner/collections/ansible_collections/ansible/hub + + - name: Run integration test - ah_build + run: ansible-test integration ah_build + working-directory: /home/runner/collections/ansible_collections/ansible/hub + + - name: Run integration test - ah_approval + run: ansible-test integration ah_approval + working-directory: /home/runner/collections/ansible_collections/ansible/hub + + - name: Run integration test - ah_collection + run: ansible-test integration ah_collection + working-directory: /home/runner/collections/ansible_collections/ansible/hub + + - name: Run integration test - ah_collection_upload + run: ansible-test integration ah_collection_upload + working-directory: /home/runner/collections/ansible_collections/ansible/hub + + - name: Run integration test - collection_remote + run: ansible-test integration collection_remote + working-directory: /home/runner/collections/ansible_collections/ansible/hub + + - name: Run integration test - collection_repository + run: ansible-test integration collection_repository + working-directory: /home/runner/collections/ansible_collections/ansible/hub + + - name: Run integration test - collection_repository_sync + run: ansible-test integration collection_repository_sync + working-directory: /home/runner/collections/ansible_collections/ansible/hub + + - name: Run integration test - ah_ee_registry + run: ansible-test integration ah_ee_registry + working-directory: /home/runner/collections/ansible_collections/ansible/hub diff --git a/tests/integration/targets/ah_approval/tasks/main.yml b/tests/integration/targets/ah_approval/tasks/main.yml new file mode 100644 index 0000000..90c6d1d --- /dev/null +++ b/tests/integration/targets/ah_approval/tasks/main.yml @@ -0,0 +1,114 @@ +--- +- name: ah_approval integration tests + module_defaults: + group/ansible.hub.hub: + ah_host: "{{ ah_host }}" + ah_username: "{{ ah_username }}" + ah_password: "{{ ah_password }}" + validate_certs: "{{ ah_verify_ssl }}" + block: + - name: Generate a test_id for the test + set_fact: + test_id: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') | lower }}" + when: test_id is not defined + + - name: Define variables + set_fact: + namespace: "sample" + company: "my_company_{{ test_id }}" + collection_name: "sample" + build_path: "/home/runner/collections/ansible_collections/ansible/hub/tests/integration/targets/ah_build/files" + + - name: Create namespace + ansible.hub.ah_namespace: + name: "{{ namespace }}" + company: "{{ company }}" + email: "{{ test_id }}@example.com" + avatar_url: https://pnt.redhat.com/pnt/d-11633955/LogoRedHatHatColorRGB.png + description: This is the Redhat Namespace + links: + - name: "homepage" + url: "https://www.redhat.com" + register: r + + - name: Check if the namespace is created + assert: + that: + - r.changed + + - name: Build Ansible Collection from the directory + ansible.hub.ah_build: + path: "{{ build_path }}/sample/sample" + output_path: "{{ build_path }}/" + register: r + + - name: Check if the file exists + ansible.builtin.stat: + path: "{{ build_path }}/sample-sample-1.0.0.tar.gz" + register: build_stat + + - name: Check if the build is successful + assert: + that: + - r.changed + - build_stat.stat.exists + + - name: Upload a collection to the given collection + ansible.hub.ah_collection: + namespace: "{{ namespace }}" + name: "{{ collection_name }}" + path: "{{ build_path }}/sample-sample-1.0.0.tar.gz" + auto_approve: false + register: r + + - name: Check if the collection is uploaded successfully + assert: + that: + - r.changed + + - name: Approve the collection + ansible.hub.ah_approval: + namespace: "{{ namespace }}" + name: "{{ collection_name }}" + version: 1.0.0 + register: r + + - name: Check if the collection is approved + assert: + that: + - r.changed + + - name: Delete a collection to the given collection + ansible.hub.ah_collection: + namespace: "{{ namespace }}" + name: "{{ collection_name }}" + version: 1.0.0 + state: absent + register: r + + - name: Check if the collection is deleted successfully + assert: + that: + - r.changed + - r.deleted + + always: + - name: Delete a collection to the given collection + ansible.hub.ah_collection: + namespace: "{{ namespace }}" + name: "{{ collection_name }}" + version: 1.0.0 + state: absent + ignore_errors: true + + - name: Delete namespace + ansible.hub.ah_namespace: + name: "{{ namespace }}" + state: absent + ignore_errors: true + + - name: Remove built collection + ansible.builtin.file: + path: "{{ build_path }}/sample-sample-1.0.0.tar.gz" + state: absent + ignore_errors: true diff --git a/tests/integration/targets/ah_build/files/sample/sample/README.md b/tests/integration/targets/ah_build/files/sample/sample/README.md new file mode 100644 index 0000000..0511911 --- /dev/null +++ b/tests/integration/targets/ah_build/files/sample/sample/README.md @@ -0,0 +1,3 @@ +# Ansible Collection - sample.sample + +Documentation for the collection. diff --git a/tests/integration/targets/ah_build/files/sample/sample/galaxy.yml b/tests/integration/targets/ah_build/files/sample/sample/galaxy.yml new file mode 100644 index 0000000..88af806 --- /dev/null +++ b/tests/integration/targets/ah_build/files/sample/sample/galaxy.yml @@ -0,0 +1,17 @@ +namespace: sample +name: sample +version: 1.0.0 +readme: README.md +authors: + - your name +description: your collection description +license: + - GPL-2.0-or-later +license_file: '' +tags: [] +dependencies: {} +repository: http://example.com/repository +documentation: http://docs.example.com +homepage: http://example.com +issues: http://example.com/issue/tracker +build_ignore: [] diff --git a/tests/integration/targets/ah_build/files/sample/sample/meta/runtime.yml b/tests/integration/targets/ah_build/files/sample/sample/meta/runtime.yml new file mode 100644 index 0000000..1c7d1bb --- /dev/null +++ b/tests/integration/targets/ah_build/files/sample/sample/meta/runtime.yml @@ -0,0 +1,2 @@ +--- +requires_ansible: '>=2.15' diff --git a/tests/integration/targets/ah_build/files/sample/sample/plugins/README.md b/tests/integration/targets/ah_build/files/sample/sample/plugins/README.md new file mode 100644 index 0000000..67a66d4 --- /dev/null +++ b/tests/integration/targets/ah_build/files/sample/sample/plugins/README.md @@ -0,0 +1,31 @@ +# Collections Plugins Directory + +This directory can be used to ship various plugins inside an Ansible collection. Each plugin is placed in a folder that +is named after the type of plugin it is in. It can also include the `module_utils` and `modules` directory that +would contain module utils and modules respectively. + +Here is an example directory of the majority of plugins currently supported by Ansible: + +``` +└── plugins + ├── action + ├── become + ├── cache + ├── callback + ├── cliconf + ├── connection + ├── filter + ├── httpapi + ├── inventory + ├── lookup + ├── module_utils + ├── modules + ├── netconf + ├── shell + ├── strategy + ├── terminal + ├── test + └── vars +``` + +A full list of plugin types can be found at [Working With Plugins](https://docs.ansible.com/ansible-core/2.16/plugins/plugins.html). diff --git a/tests/integration/targets/ah_build/tasks/main.yml b/tests/integration/targets/ah_build/tasks/main.yml new file mode 100644 index 0000000..174ce2d --- /dev/null +++ b/tests/integration/targets/ah_build/tasks/main.yml @@ -0,0 +1,62 @@ +--- +- name: ah_build integration tests + block: + - name: Generate a test_id for the test + set_fact: + test_id: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') | lower }}" + when: test_id is not defined + + - name: Define variables + set_fact: + namespace: "sample" + company: "my_company_{{ test_id }}" + collection_name: "sample" + build_path: "{{ playbook_dir }}/targets/ah_build/files" + + - name: Build Ansible Collection from the directory + ansible.hub.ah_build: + path: "{{ build_path }}/sample/sample" + output_path: "{{ build_path }}/" + register: r + + - name: Check if the file exists + ansible.builtin.stat: + path: "{{ build_path }}/sample-sample-1.0.0.tar.gz" + register: build_stat + + - name: Check if the build is successful + assert: + that: + - r.changed + - build_stat.stat.exists + + - name: Build Ansible Collection from the directory again + ansible.hub.ah_build: + path: "{{ build_path }}/sample/sample" + output_path: "{{ build_path }}/" + register: r + ignore_errors: true + + - name: Check if re-building the collection without force fails + assert: + that: + - r.failed + - "'ERROR' in r.msg" + + - name: Build Ansible Collection from the directory again + ansible.hub.ah_build: + path: "{{ build_path }}/sample/sample" + output_path: "{{ build_path }}/" + force: true + register: r + + - name: Check if re-building the collection with force works + assert: + that: + - r.changed + always: + - name: Remove built collection + ansible.builtin.file: + path: "{{ build_path }}/sample-sample-1.0.0.tar.gz" + state: absent + ignore_errors: true diff --git a/tests/integration/targets/ah_collection/tasks/main.yml b/tests/integration/targets/ah_collection/tasks/main.yml new file mode 100644 index 0000000..8efb013 --- /dev/null +++ b/tests/integration/targets/ah_collection/tasks/main.yml @@ -0,0 +1,101 @@ +--- +- name: ah_collection integration tests + module_defaults: + group/ansible.hub.hub: + ah_host: "{{ ah_host }}" + ah_username: "{{ ah_username }}" + ah_password: "{{ ah_password }}" + validate_certs: "{{ ah_verify_ssl }}" + block: + - name: Generate a test_id for the test + set_fact: + test_id: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') | lower }}" + when: test_id is not defined + + - name: Define variables + set_fact: + namespace: "sample" + company: "my_company_{{ test_id }}" + collection_name: "sample" + build_path: "/home/runner/collections/ansible_collections/ansible/hub/tests/integration/targets/ah_build/files" + + - name: Create namespace + ansible.hub.ah_namespace: + name: "{{ namespace }}" + company: "{{ company }}" + email: "{{ test_id }}@example.com" + avatar_url: https://pnt.redhat.com/pnt/d-11633955/LogoRedHatHatColorRGB.png + description: This is the Redhat Namespace + links: + - name: "homepage" + url: "https://www.redhat.com" + register: r + + - name: Check if the namespace is created + assert: + that: + - r.changed + + - name: Build Ansible Collection from the directory + ansible.hub.ah_build: + path: "{{ build_path }}/sample/sample" + output_path: "{{ build_path }}/" + register: r + + - name: Check if the file exists + ansible.builtin.stat: + path: "{{ build_path }}/sample-sample-1.0.0.tar.gz" + register: build_stat + + - name: Check if the build is successful + assert: + that: + - r.changed + - build_stat.stat.exists + + - name: Upload a collection to the given collection + ansible.hub.ah_collection: + namespace: "{{ namespace }}" + name: "{{ collection_name }}" + path: "{{ build_path }}/sample-sample-1.0.0.tar.gz" + register: r + + - name: Check if the collection is uploaded successfully + assert: + that: + - r.changed + + - name: Delete a collection to the given collection + ansible.hub.ah_collection: + namespace: "{{ namespace }}" + name: "{{ collection_name }}" + version: 1.0.0 + state: absent + register: r + + - name: Check if the collection is deleted successfully + assert: + that: + - r.changed + - r.deleted + + always: + - name: Delete a collection to the given collection + ansible.hub.ah_collection: + namespace: "{{ namespace }}" + name: "{{ collection_name }}" + version: 1.0.0 + state: absent + ignore_errors: true + + - name: Delete namespace + ansible.hub.ah_namespace: + name: "{{ namespace }}" + state: absent + ignore_errors: true + + - name: Remove built collection + ansible.builtin.file: + path: "{{ build_path }}/sample-sample-1.0.0.tar.gz" + state: absent + ignore_errors: true diff --git a/tests/integration/targets/ah_collection_upload/tasks/main.yml b/tests/integration/targets/ah_collection_upload/tasks/main.yml new file mode 100644 index 0000000..c99bc23 --- /dev/null +++ b/tests/integration/targets/ah_collection_upload/tasks/main.yml @@ -0,0 +1,72 @@ +--- +- name: ah_collection_upload integration tests + module_defaults: + group/ansible.hub.hub: + ah_host: "{{ ah_host }}" + ah_username: "{{ ah_username }}" + ah_password: "{{ ah_password }}" + validate_certs: "{{ ah_verify_ssl }}" + block: + - name: Generate a test_id for the test + set_fact: + test_id: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') | lower }}" + when: test_id is not defined + + - name: Define variables + set_fact: + namespace: "sample" + company: "my_company_{{ test_id }}" + collection_name: "sample" + build_path: "/home/runner/collections/ansible_collections/ansible/hub/tests/integration/targets/ah_build/files" + + - name: Create namespace + ansible.hub.ah_namespace: + name: "{{ namespace }}" + company: "{{ company }}" + email: "{{ test_id }}@example.com" + avatar_url: https://pnt.redhat.com/pnt/d-11633955/LogoRedHatHatColorRGB.png + description: This is the Redhat Namespace + links: + - name: "homepage" + url: "https://www.redhat.com" + register: r + + - name: Check if the namespace is created + assert: + that: + - r.changed + + - name: Build Ansible Collection from the directory + ansible.hub.ah_build: + path: "{{ build_path }}/sample/sample" + output_path: "{{ build_path }}/" + force: true + register: r + + - name: Check if the file exists + ansible.builtin.stat: + path: "{{ build_path }}/sample-sample-1.0.0.tar.gz" + register: build_stat + + - name: Check if the build is successful + assert: + that: + - r.changed + - build_stat.stat.exists + + - name: Upload a collection to the given collection + ansible.hub.ah_collection_upload: + path: "{{ build_path }}/sample-sample-1.0.0.tar.gz" + register: r + + - name: Check if the collection is uploaded successfully + assert: + that: + - r.changed + + always: + - name: Remove built collection + ansible.builtin.file: + path: "{{ build_path }}/sample-sample-1.0.0.tar.gz" + state: absent + ignore_errors: true diff --git a/tests/integration/targets/ah_ee_registry/tasks/main.yml b/tests/integration/targets/ah_ee_registry/tasks/main.yml new file mode 100644 index 0000000..d41b3ad --- /dev/null +++ b/tests/integration/targets/ah_ee_registry/tasks/main.yml @@ -0,0 +1,85 @@ +--- +- name: ah_ee_registry integration tests + module_defaults: + group/ansible.hub.hub: + ah_host: "{{ ah_host }}" + ah_username: "{{ ah_username }}" + ah_password: "{{ ah_password }}" + validate_certs: "{{ ah_verify_ssl }}" + block: + - name: Generate a test_id for the test + set_fact: + test_id: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') | lower }}" + when: test_id is not defined + + - name: Define variables for registry name + set_fact: + registry_name: "ee_{{ test_id }}" + + - name: Create EE remote registry in check_mode + ansible.hub.ah_ee_registry: + name: "{{ registry_name }}" + url: https://quay.io/my/registry + state: present + register: r + check_mode: yes + + - name: Check if the remote registry EE is created in check_mode + assert: + that: + - r.changed + + - name: Create EE remote registry + ansible.hub.ah_ee_registry: + name: "{{ registry_name }}" + url: https://quay.io/my/registry + state: present + register: r + + - name: Check if the remote registry EE is created + assert: + that: + - r.changed + + - name: Create EE remote registry again + ansible.hub.ah_ee_registry: + name: "{{ registry_name }}" + url: https://quay.io/my/registry + state: present + register: r + + - name: Check if the remote registry EE is not created again + assert: + that: + - not r.changed + + - name: Delete EE remote registry + ansible.hub.ah_ee_registry: + name: "{{ registry_name }}" + url: https://quay.io/my/registry + state: absent + register: r + + - name: Check if the remote registry EE is deleted + assert: + that: + - r.changed + + - name: Delete EE remote registry again + ansible.hub.ah_ee_registry: + name: "{{ registry_name }}" + url: https://quay.io/my/registry + state: absent + register: r + + - name: Check if the remote registry EE is not deleted + assert: + that: + - not r.changed + + always: + - name: Delete EE remote registry + ansible.hub.ah_ee_registry: + name: "{{ registry_name }}" + state: absent + ignore_errors: true diff --git a/tests/integration/targets/ah_namespace/tasks/main.yml b/tests/integration/targets/ah_namespace/tasks/main.yml new file mode 100644 index 0000000..92d7534 --- /dev/null +++ b/tests/integration/targets/ah_namespace/tasks/main.yml @@ -0,0 +1,53 @@ +--- +- name: ah_namespace integration tests + module_defaults: + group/ansible.hub.hub: + ah_host: "{{ ah_host }}" + ah_username: "{{ ah_username }}" + ah_password: "{{ ah_password }}" + validate_certs: "{{ ah_verify_ssl }}" + block: + - name: Generate a test_id for the test + set_fact: + test_id: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') | lower }}" + when: test_id is not defined + + - name: Define variables for credential and project + set_fact: + namespace: "my_namespace_{{ test_id }}" + company: "my_company_{{ test_id }}" + + - name: Create namespace + ansible.hub.ah_namespace: + name: "{{ namespace }}" + company: "{{ company }}" + email: "{{ test_id }}@example.com" + avatar_url: https://pnt.redhat.com/pnt/d-11633955/LogoRedHatHatColorRGB.png + description: This is the Redhat Namespace + links: + - name: "homepage" + url: "https://www.redhat.com" + register: r + + - name: Check if the namespace is created + assert: + that: + - r.changed + + - name: Delete namespace + ansible.hub.ah_namespace: + name: "{{ namespace }}" + state: absent + register: r + + - name: Check if the namespace is deleted + assert: + that: + - r.changed + + always: + - name: Delete namespace + ansible.hub.ah_namespace: + name: "{{ namespace }}" + state: absent + ignore_errors: true diff --git a/tests/integration/targets/collection_remote/tasks/main.yml b/tests/integration/targets/collection_remote/tasks/main.yml new file mode 100644 index 0000000..5485bfd --- /dev/null +++ b/tests/integration/targets/collection_remote/tasks/main.yml @@ -0,0 +1,57 @@ +--- +- name: collection_remote integration tests + module_defaults: + group/ansible.hub.hub: + ah_host: "{{ ah_host }}" + ah_username: "{{ ah_username }}" + ah_password: "{{ ah_password }}" + validate_certs: "{{ ah_verify_ssl }}" + block: + - name: Generate a test_id for the test + set_fact: + test_id: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') | lower }}" + when: test_id is not defined + + - name: Define variables + set_fact: + collection_repo_name: "sample_{{ test_id }}" + distribution: "sample_{{ test_id }}" + + - name: Create a collection repository + ansible.hub.collection_repository: + name: "{{ collection_repo_name }}" + description: "description of the repository" + pulp_labels: + pipeline: "approved" + distribution: + name: "{{ distribution }}" + state: present + remote: community + wait: true + register: r + + - name: Check if the collection repository is created + assert: + that: + - r.changed + + - name: Configure collection + collection_remote: + name: "{{ collection_repo_name }}" + url: https://galaxy.ansible.com/api/ + requirements: + - galaxy.galaxy + - infra.controller_configuration + register: r + + - name: Check if the collection_remote works + assert: + that: + - r.changed + + always: + - name: Cleanup - Delete collection repository + ansible.hub.collection_repository: + name: "{{ collection_repo_name }}" + state: absent + ignore_errors: true diff --git a/tests/integration/targets/collection_repository/tasks/main.yml b/tests/integration/targets/collection_repository/tasks/main.yml new file mode 100644 index 0000000..6bcc9f4 --- /dev/null +++ b/tests/integration/targets/collection_repository/tasks/main.yml @@ -0,0 +1,114 @@ +--- +- name: collection_repository integration tests + module_defaults: + group/ansible.hub.hub: + ah_host: "{{ ah_host }}" + ah_username: "{{ ah_username }}" + ah_password: "{{ ah_password }}" + validate_certs: "{{ ah_verify_ssl }}" + block: + - name: Generate a test_id for the test + set_fact: + test_id: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') | lower }}" + when: test_id is not defined + + - name: Define variables + set_fact: + collection_repo_name: "sample_{{ test_id }}" + distribution: "sample_{{ test_id }}" + + - name: Create a collection repository in check mode + ansible.hub.collection_repository: + name: "{{ collection_repo_name }}" + description: "description of the repository" + pulp_labels: + pipeline: "approved" + distribution: + name: "{{ distribution }}" + state: present + remote: community + wait: true + register: r + check_mode: yes + + - name: Check if the collection repository is created in check mode + assert: + that: + - r.changed + + - name: Create a collection repository + ansible.hub.collection_repository: + name: "{{ collection_repo_name }}" + description: "description of the repository" + pulp_labels: + pipeline: "approved" + distribution: + name: "{{ distribution }}" + state: present + remote: community + wait: true + register: r + + - name: Check if the collection repository is created + assert: + that: + - r.changed + + - name: Create a collection repository again + ansible.hub.collection_repository: + name: "{{ collection_repo_name }}" + description: "description of the repository" + pulp_labels: + pipeline: "approved" + distribution: + name: "{{ distribution }}" + state: present + remote: community + wait: true + register: r + + - name: Check if the collection repository is not created again + assert: + that: + - not r.changed + + - name: Delete collection repository in check mode + ansible.hub.collection_repository: + name: "{{ collection_repo_name }}" + state: absent + check_mode: yes + register: r + + - name: Check if the collection is deleted in check mode + assert: + that: + - r.changed + + - name: Delete collection repository + ansible.hub.collection_repository: + name: "{{ collection_repo_name }}" + state: absent + register: r + + - name: Check if the collection is deleted + assert: + that: + - r.changed + + - name: Delete collection repository again + ansible.hub.collection_repository: + name: "{{ collection_repo_name }}" + state: absent + register: r + + - name: Check if the collection is not deleted again + assert: + that: + - not r.changed + + always: + - name: Cleanup - Delete collection repository + ansible.hub.collection_repository: + name: "{{ collection_repo_name }}" + state: absent + ignore_errors: true diff --git a/tests/integration/targets/collection_repository_sync/tasks/main.yml b/tests/integration/targets/collection_repository_sync/tasks/main.yml new file mode 100644 index 0000000..ddd67da --- /dev/null +++ b/tests/integration/targets/collection_repository_sync/tasks/main.yml @@ -0,0 +1,31 @@ +--- +- name: collection_repository_sync integration tests + module_defaults: + group/ansible.hub.hub: + ah_host: "{{ ah_host }}" + ah_username: "{{ ah_username }}" + ah_password: "{{ ah_password }}" + validate_certs: "{{ ah_verify_ssl }}" + block: + - name: Sync rh-certified in check mode + ansible.hub.collection_repository_sync: + name: rh-certified + wait: false + check_mode: yes + register: r + + - name: Check if sync is successful + assert: + that: + - r.changed + + - name: Sync rh-certified + ansible.hub.collection_repository_sync: + name: rh-certified + wait: false + register: r + + - name: Check if sync is successful + assert: + that: + - r.changed