From 0fef633b362cefe31d841034ce68746869ba89b4 Mon Sep 17 00:00:00 2001 From: smiron Date: Mon, 20 May 2024 18:47:44 +0300 Subject: [PATCH] add first integration CI test to run on eco vcenter --- .github/workflows/eco-vcenter-ci.yaml | 46 +++++++++++++++++++ CODEOWNERS | 14 ++++-- Makefile | 10 ++++ .../42__eco-vcenter-ci-integration.yml | 4 ++ scripts/generate_integration_config.sh | 14 ++++++ scripts/integration_config.yml.tpl | 5 ++ tests/integration/requirements.txt | 3 +- .../targets/info_test/defaults/main.yml | 13 ++++++ tests/integration/targets/info_test/run.yml | 31 +++++++++---- tests/integration/targets/info_test/runme.sh | 13 +++++- tests/integration/targets/info_test/vars.yml | 7 ++- tests/integration/targets/init.sh | 6 ++- .../targets/prepare_rest/tasks/main.yml | 2 + .../targets/prepare_soap/tasks/main.yml | 2 +- 14 files changed, 154 insertions(+), 16 deletions(-) create mode 100644 .github/workflows/eco-vcenter-ci.yaml create mode 100644 changelogs/fragments/42__eco-vcenter-ci-integration.yml create mode 100755 scripts/generate_integration_config.sh create mode 100644 scripts/integration_config.yml.tpl create mode 100644 tests/integration/targets/info_test/defaults/main.yml diff --git a/.github/workflows/eco-vcenter-ci.yaml b/.github/workflows/eco-vcenter-ci.yaml new file mode 100644 index 00000000..47814319 --- /dev/null +++ b/.github/workflows/eco-vcenter-ci.yaml @@ -0,0 +1,46 @@ +--- +name: Ansible Eco vCenter Integration Test +on: + pull_request_target: + types: [opened, synchronize] + push: + branches: + - main + - 'release-\d.\d' +permissions: + contents: read +jobs: + ansible_integration_test: + runs-on: ["self-hosted", linux, X64] + steps: + - name: Update pip, git + if: runner.os == 'Linux' && startsWith(runner.name, 'ubuntu') + run: | + set -euxo pipefail + sudo apt-get update + sudo apt-get install podman + + - name: Checkout repo + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + path: ansible_collections/cloud/vmware_ops + + - name: Generate integration config + working-directory: ansible_collections/cloud/vmware_ops/scripts + run: | + chmod +x generate_integration_config.sh + ./generate_integration_config.sh + env: + VCENTER_HOSTNAME: ${{ secrets.VCENTER_HOSTNAME }} + VCENTER_USERNAME: ${{ secrets.VCENTER_USERNAME }} + VCENTER_PASSWORD: ${{ secrets.VCENTER_PASSWORD }} + + - name: Run integration tests + run: | + python3 -m venv .venv + source .venv/bin/activate + make eco-vcenter-ci + working-directory: ansible_collections/cloud/vmware_ops + env: + ANSIBLE_COLLECTIONS_PATH: "${{ github.workspace }}" diff --git a/CODEOWNERS b/CODEOWNERS index 5af144e0..e87c2524 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -1,3 +1,11 @@ -* @bardielle -* @machacekondra -* @mikemorency +# Default code owners for all files and directories +* @bardielle @machacekondra @mikemorency + +# Integration tests permissions +/tests/integration/ @shellymiron @elsapassaro + +# Specific workflow file permissions +.github/workflows/eco-vcenter-ci.yaml @shellymiron @elsapassaro + +# Scripts directory permissions +/scripts/ @shellymiron @elsapassaro diff --git a/Makefile b/Makefile index c6718f4c..59036e50 100644 --- a/Makefile +++ b/Makefile @@ -9,10 +9,20 @@ install-python-packages: install-ansible-collections: ansible-galaxy collection install --upgrade -r tests/integration/requirements.yml +# workaround pyvmomy issue till latest version +# is available to use in requirements.txt +.PHONY: install-pyvmomy-latest +install-pyvmomy-latest: + pip3 install pyVmomi --force + .PHONY: integration integration: install-python-packages install-ansible-collections ansible-test integration --no-temp-workdir +.PHONY: eco-vcenter-ci +eco-vcenter-ci: install-python-packages install-ansible-collections install-pyvmomy-latest + ansible-test integration --no-temp-workdir info_test + .PHONY: ee-clean ee-clean: rm -rf context/ diff --git a/changelogs/fragments/42__eco-vcenter-ci-integration.yml b/changelogs/fragments/42__eco-vcenter-ci-integration.yml new file mode 100644 index 00000000..f253c7e3 --- /dev/null +++ b/changelogs/fragments/42__eco-vcenter-ci-integration.yml @@ -0,0 +1,4 @@ +--- +minor_changes: + - info_test - adding a CI for validated content repo to run on a real vcenter env, + and include this test within the pr \ No newline at end of file diff --git a/scripts/generate_integration_config.sh b/scripts/generate_integration_config.sh new file mode 100755 index 00000000..5605416e --- /dev/null +++ b/scripts/generate_integration_config.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +# shellcheck disable=SC2155,SC2086 + +# Resolve the script's directory reliably +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)" +cd "$SCRIPT_DIR" || exit 1 + +# Truncate the output file +truncate -s 0 integration_config.yml + +# Read the template and substitute environment variables +while read -r line; do + eval 'echo "'"$line"'"' >> integration_config.yml +done < "integration_config.yml.tpl" diff --git a/scripts/integration_config.yml.tpl b/scripts/integration_config.yml.tpl new file mode 100644 index 00000000..502230cb --- /dev/null +++ b/scripts/integration_config.yml.tpl @@ -0,0 +1,5 @@ +--- +vcenter_hostname: ${VCENTER_HOSTNAME} +vcenter_username: ${VCENTER_USERNAME} +vcenter_password: ${VCENTER_PASSWORD} +ansible_tags: eco-vcenter-ci diff --git a/tests/integration/requirements.txt b/tests/integration/requirements.txt index 89d91ac0..2b9c6bc9 100644 --- a/tests/integration/requirements.txt +++ b/tests/integration/requirements.txt @@ -1,3 +1,4 @@ +aiohttp pyVim podman requests @@ -6,4 +7,4 @@ ansible-core # see the cluster_settings role README.md for an explanation on the <7.0.3 restriction pyVmomi>=6.7,<7.0.3 - +git+https://github.com/vmware/vsphere-automation-sdk-python.git diff --git a/tests/integration/targets/info_test/defaults/main.yml b/tests/integration/targets/info_test/defaults/main.yml new file mode 100644 index 00000000..97ad64a7 --- /dev/null +++ b/tests/integration/targets/info_test/defaults/main.yml @@ -0,0 +1,13 @@ +info_hostname: "{{ vcenter_hostname }}" +info_username: "{{ vcenter_username }}" +info_password: "{{ vcenter_password }}" +info_validate_certs: false +info_appliance_file: "/tmp/info_appliance_file" +info_license_file: "/tmp/info_license_file" +info_storage_file: "/tmp/info_storage_file" +info_guest_file: "/tmp/guest_info_file" +info_license: true +info_storage: true +info_cluster: true +info_guest: true +info_appliance: true diff --git a/tests/integration/targets/info_test/run.yml b/tests/integration/targets/info_test/run.yml index ae03d4b3..8f667f6b 100644 --- a/tests/integration/targets/info_test/run.yml +++ b/tests/integration/targets/info_test/run.yml @@ -1,19 +1,34 @@ -- hosts: localhost - gather_facts: no +- name: Run Info Test Tasks + hosts: localhost + gather_facts: false collections: - community.general - vars_files: - - vars.yml tasks: - - name: Vcsim - ansible.builtin.import_role: - name: prepare_soap - - name: Vcsim + - name: Import eco-vcenter credentials + ansible.builtin.include_vars: + file: ../../../../scripts/integration_config.yml + tags: eco-vcenter-ci + + - name: Import simulator vars + ansible.builtin.include_vars: + file: vars.yml + tags: integration-ci + + - name: Prepare Rest ansible.builtin.import_role: name: prepare_rest + tags: integration-ci + + - name: Prepare Soap (vcsim) + ansible.builtin.import_role: + name: prepare_soap + tags: integration-ci - name: Import info role ansible.builtin.import_role: name: info_test + tags: + - eco-vcenter-ci + - integration-ci diff --git a/tests/integration/targets/info_test/runme.sh b/tests/integration/targets/info_test/runme.sh index a4c36631..df332d3d 100755 --- a/tests/integration/targets/info_test/runme.sh +++ b/tests/integration/targets/info_test/runme.sh @@ -1,3 +1,14 @@ #!/usr/bin/env bash source ../init.sh -exec ansible-playbook run.yml + +# Extract the ansible_tags from integration_config.yml +ANSIBLE_TAGS=$(awk '/ansible_tags/ {print $2}' ../../../../scripts/integration_config.yml) + +# Check if the ANSIBLE_TAGS variable is set +if [[ -n "$ANSIBLE_TAGS" ]]; then + echo "ANSIBLE_TAGS is set to: $ANSIBLE_TAGS" + exec ansible-playbook run.yml --tags "$ANSIBLE_TAGS" +else + echo "ANSIBLE_TAGS is not set for Eco vCenter. Running on simulator." + exec ansible-playbook run.yml --tags integration-ci +fi diff --git a/tests/integration/targets/info_test/vars.yml b/tests/integration/targets/info_test/vars.yml index ba988a8e..3047827c 100644 --- a/tests/integration/targets/info_test/vars.yml +++ b/tests/integration/targets/info_test/vars.yml @@ -7,4 +7,9 @@ info_validate_certs: false mock_file: "info_test" -info_cluster: true +# workaround till simulator fixed +info_cluster: false +info_license: true +info_appliance: false +info_guest: false +info_storage: false diff --git a/tests/integration/targets/init.sh b/tests/integration/targets/init.sh index cd18c79e..2cefa174 100644 --- a/tests/integration/targets/init.sh +++ b/tests/integration/targets/init.sh @@ -1,5 +1,9 @@ #!/usr/bin/env bash # shellcheck disable=SC2155,SC2086 -BASE_DIR=$(dirname "${BASH_SOURCE[0]}") +# Export the collections path +export ANSIBLE_COLLECTIONS_PATH="$ANSIBLE_COLLECTIONS_PATH/ansible_collections" + +echo "ANSIBLE_COLLECTIONS_PATH: $ANSIBLE_COLLECTIONS_PATH" +BASE_DIR=$(dirname "$(realpath "${BASH_SOURCE[0]}")") export ANSIBLE_ROLES_PATH=${BASE_DIR} diff --git a/tests/integration/targets/prepare_rest/tasks/main.yml b/tests/integration/targets/prepare_rest/tasks/main.yml index 3ed1cc91..a24a23e8 100644 --- a/tests/integration/targets/prepare_rest/tasks/main.yml +++ b/tests/integration/targets/prepare_rest/tasks/main.yml @@ -4,6 +4,8 @@ name: - requests - aiohttp + - pyvmomi + - git+https://github.com/vmware/vsphere-automation-sdk-python.git@v7.0.3.2 - name: Run rest containers.podman.podman_container: diff --git a/tests/integration/targets/prepare_soap/tasks/main.yml b/tests/integration/targets/prepare_soap/tasks/main.yml index 35d51d6c..aad073a0 100644 --- a/tests/integration/targets/prepare_soap/tasks/main.yml +++ b/tests/integration/targets/prepare_soap/tasks/main.yml @@ -4,11 +4,11 @@ name: - requests - pyVmomi + - git+https://github.com/vmware/vsphere-automation-sdk-python.git - name: Run soap vcSim containers.podman.podman_container: name: vmwaresoap - image: docker.io/vmware/vcsim:latest state: started recreate: yes