tests: modify image_tests for Gitlab CI

This commit is contained in:
Jakub Rusz 2021-06-24 21:11:00 +02:00 committed by Alexander Todorov
parent 579a5df698
commit b1e40b5ce7

View file

@ -6,6 +6,12 @@ source /etc/os-release
ARCH=$(uname -m)
DISTRO_CODE="${DISTRO_CODE:-${ID}_${VERSION_ID//./}}"
if [[ -n "$CI_BUILD_ID" ]]; then
BUILD_ID="${BUILD_ID:-${CI_BUILD_ID}}"
else
BUILD_ID="${BUILD_ID:-$(uuidgen)}"
fi
WORKING_DIRECTORY=/usr/libexec/osbuild-composer
IMAGE_TEST_CASE_RUNNER=/usr/libexec/osbuild-composer-test/osbuild-image-tests
IMAGE_TEST_CASES_PATH=/usr/share/tests/osbuild-composer/manifests
@ -49,35 +55,12 @@ run_test_case () {
echo "🏃🏻 Running test: ${TEST_NAME}"
test_divider
# Set up the testing command with Azure secrets in the environment.
#
# This works by having a text file stored in Jenkins credentials.
# In Jenkinsfile, the following line assigns the path to this secret file
# to an environment variable called AZURE_CREDS:
# AZURE_CREDS = credentials('azure')
#
# The file is in the following format:
# KEY1=VALUE1
# KEY2=VALUE2
#
# Using `env $(cat $AZURE_CREDS)` we can take all the key-value pairs and
# save them as environment variables.
# Read test/README.md to see all required environment variables for Azure
# uploads
#
# AZURE_CREDS might not be defined in all cases (e.g. Azure doesn't
# support aarch64), therefore the following line sets AZURE_CREDS to
# /dev/null if the variable is undefined.
AWS_CREDS=${AWS_IMAGE_TEST_CREDS-/dev/null}
AZURE_CREDS=${AZURE_CREDS-/dev/null}
OPENSTACK_CREDS=${OPENSTACK_CREDS-/dev/null}
VCENTER_CREDS=${VCENTER_CREDS-/dev/null}
TEST_CMD="env $(cat "$AWS_CREDS" "$AZURE_CREDS" "$OPENSTACK_CREDS" "$VCENTER_CREDS") BRANCH_NAME=${BRANCH_NAME-main} BUILD_ID=$BUILD_ID DISTRO_CODE=$DISTRO_CODE $TEST_RUNNER -test.v ${IMAGE_TEST_CASES_PATH}/${TEST_CASE_FILENAME}"
TEST_CMD="env BRANCH_NAME=${BRANCH_NAME-main} BUILD_ID=$BUILD_ID DISTRO_CODE=$DISTRO_CODE $TEST_RUNNER -test.v ${IMAGE_TEST_CASES_PATH}/${TEST_CASE_FILENAME}"
# Run the test and add the test name to the list of passed or failed
# tests depending on the result.
# shellcheck disable=SC2086 # We need to pass multiple arguments here.
if sudo $TEST_CMD 2>&1 | tee "${WORKSPACE}"/"${TEST_NAME}".log; then
if sudo -E $TEST_CMD 2>&1 | tee "${WORKSPACE}"/"${TEST_NAME}".log; then
PASSED_TESTS+=("$TEST_NAME")
else
FAILED_TESTS+=("$TEST_NAME")