From 8dcf859473cccf225ca3c4fcaa0b1d1603cfef16 Mon Sep 17 00:00:00 2001 From: Jakub Rusz Date: Tue, 4 May 2021 18:15:09 +0200 Subject: [PATCH] tests: move some integration tests to gitlab CI This also includes several modifications to tests scripts to enable them running in gitlab CI. --- .gitlab-ci.yml | 29 ++++++++++++++++ schutzbot/Jenkinsfile | 60 ++++++++++++++++++---------------- schutzbot/run_cloud_cleaner.sh | 2 ++ test/cases/api.sh | 2 +- test/cases/azure.sh | 17 +++++++--- test/cases/koji.sh | 9 ++++- tools/libvirt_test.sh | 1 + 7 files changed, 84 insertions(+), 36 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 221956b6d..3d3652b92 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -8,6 +8,7 @@ stages: after_script: - schutzbot/update_github_status.sh update - schutzbot/save_journal.sh + - schutzbot/run_cloud_cleaner.sh tags: - terraform artifacts: @@ -81,6 +82,34 @@ OSTree: - openstack/fedora-33-x86_64 - openstack/rhel-8-x86_64 +Integration: + stage: test + extends: .terraform + variables: + EXTRA_REPO_PATH_SEGMENT: "gitlab/" + script: + - schutzbot/deploy.sh + - /usr/libexec/tests/osbuild-composer/koji.sh + - /usr/libexec/tests/osbuild-composer/libvirt.sh + - /usr/libexec/tests/osbuild-composer/aws.sh + - /usr/libexec/tests/osbuild-composer/azure.sh + - /usr/libexec/tests/osbuild-composer/api.sh azure + - /usr/libexec/tests/osbuild-composer/api.sh aws + parallel: + matrix: + - RUNNER: + - aws/fedora-32-x86_64 + - aws/fedora-33-x86_64 + - aws/centos-stream-8-x86_64 + - RUNNER: + - aws/rhel-8-x86_64 + - aws/rhel-8.4-x86_64 + INTERNAL_NETWORK: ["true"] + - RUNNER: + - aws/rhel-8-x86_64 + INTERNAL_NETWORK: ["true"] + DISTRO_CODE: ["rhel_90"] + finish: stage: finish tags: diff --git a/schutzbot/Jenkinsfile b/schutzbot/Jenkinsfile index 082f74324..5bb934304 100644 --- a/schutzbot/Jenkinsfile +++ b/schutzbot/Jenkinsfile @@ -815,34 +815,41 @@ void run_tests(test_type) { if (test_type == 'integration') { // Run Koji tests. - sh ( - label: "Koji tests", - script: "/usr/libexec/tests/osbuild-composer/koji.sh" - ) + if (env.BUILD_CAUSE == 'cron') { + sh ( + label: "Koji tests", + script: "/usr/libexec/tests/osbuild-composer/koji.sh" + ) - // Run the libvirt test. - sh ( - label: "Integration test: libvirt", - script: "/usr/libexec/tests/osbuild-composer/libvirt.sh" - ) + // Run the libvirt test. + sh ( + label: "Integration test: libvirt", + script: "/usr/libexec/tests/osbuild-composer/libvirt.sh" + ) - // Run the AWS test. - sh ( - label: "Integration test: AWS", - script: "/usr/libexec/tests/osbuild-composer/aws.sh" - ) + // Run the AWS test. + sh ( + label: "Integration test: AWS", + script: "/usr/libexec/tests/osbuild-composer/aws.sh" + ) - // Run the Azure test. - sh ( - label: "Integration test: AZURE", - script: "/usr/libexec/tests/osbuild-composer/azure.sh" - ) + // Run the Azure test. + sh ( + label: "Integration test: AZURE", + script: "/usr/libexec/tests/osbuild-composer/azure.sh" + ) - // Run the API test with AWS. - sh ( - label: "Integration test: API (AWS)", - script: "/usr/libexec/tests/osbuild-composer/api.sh aws" - ) + // Run the API test with AWS. + sh ( + label: "Integration test: API (AWS)", + script: "/usr/libexec/tests/osbuild-composer/api.sh aws" + ) + + sh ( + label: "Integration test: API (Azure)", + script: "/usr/libexec/tests/osbuild-composer/api.sh azure" + ) + } if (env.GOOGLE_APPLICATION_CREDENTIALS) { // Run the API test with GCP. @@ -852,11 +859,6 @@ void run_tests(test_type) { ) } - sh ( - label: "Integration test: API (Azure)", - script: "/usr/libexec/tests/osbuild-composer/api.sh azure" - ) - if (env.VCENTER_CREDS) { // Run the VMWare test. sh ( diff --git a/schutzbot/run_cloud_cleaner.sh b/schutzbot/run_cloud_cleaner.sh index ee551b1d4..36d9cbe55 100755 --- a/schutzbot/run_cloud_cleaner.sh +++ b/schutzbot/run_cloud_cleaner.sh @@ -3,6 +3,8 @@ set -euo pipefail source /etc/os-release DISTRO_CODE="${DISTRO_CODE:-${ID}_${VERSION_ID//./}}" +BRANCH_NAME="${BRANCH_NAME:-${CI_COMMIT_BRANCH}}" +BUILD_ID="${BUILD_ID:-${CI_PIPELINE_ID}}" CLEANER_CMD="env $(cat "${AZURE_CREDS:-/dev/null}") BRANCH_NAME=$BRANCH_NAME BUILD_ID=$BUILD_ID DISTRO_CODE=$DISTRO_CODE /usr/libexec/osbuild-composer-test/cloud-cleaner" diff --git a/test/cases/api.sh b/test/cases/api.sh index 12d7afaea..4c10010a9 100755 --- a/test/cases/api.sh +++ b/test/cases/api.sh @@ -130,7 +130,7 @@ function cleanupAzure() { # do not run clean-up if the image name is not yet defined if [[ -n "$AZURE_CMD" && -n "$AZURE_IMAGE_NAME" ]]; then set +e - $AZURE_CMD image delete --resource-group sharing-research --name "$AZURE_IMAGE_NAME" + $AZURE_CMD image delete --resource-group "$AZURE_RESOURCE_GROUP" --name "$AZURE_IMAGE_NAME" # find a storage account by its tag AZURE_STORAGE_ACCOUNT=$($AZURE_CMD resource list --tag imageBuilderStorageAccount=location="$AZURE_LOCATION" | jq -r .[0].name) diff --git a/test/cases/azure.sh b/test/cases/azure.sh index f8912ba26..735a0e10e 100755 --- a/test/cases/azure.sh +++ b/test/cases/azure.sh @@ -3,6 +3,8 @@ set -euo pipefail source /etc/os-release DISTRO_CODE="${DISTRO_CODE:-${ID}_${VERSION_ID//./}}" +BRANCH_NAME="${BRANCH_NAME:-${CI_COMMIT_BRANCH}}" +BUILD_ID="${BUILD_ID:-${CI_PIPELINE_ID}}" # Colorful output. function greenprint { @@ -102,11 +104,16 @@ get_compose_metadata () { cat "${COMPOSE_ID}".json | jq -M '.' | tee "$METADATA_FILE" > /dev/null } -# Export Azure credentials -exec 4<"$AZURE_CREDS" -readarray -t -u 4 vars -for line in "${vars[@]}"; do export "${line?}"; done -exec 4<&- +# Export Azure credentials if running on Jenkins +set +u +if [ -n "$AZURE_CREDS" ] +then + exec 4<"$AZURE_CREDS" + readarray -t -u 4 vars + for line in "${vars[@]}"; do export "${line?}"; done + exec 4<&- +fi +set -u # Write an Azure TOML file tee "$AZURE_CONFIG" > /dev/null << EOF diff --git a/test/cases/koji.sh b/test/cases/koji.sh index 5772e3f1b..2a705c12a 100755 --- a/test/cases/koji.sh +++ b/test/cases/koji.sh @@ -6,7 +6,14 @@ OSBUILD_COMPOSER_TEST_DATA=/usr/share/tests/osbuild-composer/ # Get OS data. source /etc/os-release ARCH=$(uname -m) -DISTRO_CODE="${DISTRO_CODE:-${ID}_${VERSION_ID//./}}" +# This should be revisited and solved in a more sustainable way +if [[ "$ID" == 'rhel' ]] && [[ "$VERSION_ID" == 8.3 ]] +then + DISTRO_CODE="${DISTRO_CODE:-rhel_8}" +else + DISTRO_CODE="${DISTRO_CODE:-${ID}_${VERSION_ID//./}}" +fi + # Colorful output. function greenprint { diff --git a/tools/libvirt_test.sh b/tools/libvirt_test.sh index 06bc7c062..805510732 100755 --- a/tools/libvirt_test.sh +++ b/tools/libvirt_test.sh @@ -303,6 +303,7 @@ for LOOP_COUNTER in $(seq 0 ${MAX_LOOPS}); do echo "Smoke test passed! 🥳" break fi + echo "Machine is not ready yet, retrying connection." sleep 10 done