From 4c5d1ae45a683842946c344f61ed1200b6b36ec0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Budai?= Date: Fri, 9 Jul 2021 12:01:29 +0200 Subject: [PATCH] test: move env variables into set-env-variables helper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ondřej Budai --- osbuild-composer.spec | 1 + schutzbot/deploy.sh | 3 +-- schutzbot/mockbuild.sh | 3 +-- schutzbot/run_cloud_cleaner.sh | 3 +-- test/cases/api.sh | 3 +-- test/cases/aws.sh | 3 +-- test/cases/azure.sh | 3 +-- test/cases/image_tests.sh | 4 +--- test/cases/installers.sh | 2 +- test/cases/koji.sh | 3 +-- test/cases/libvirt.sh | 3 +-- test/cases/ostree-ng.sh | 3 +-- test/cases/ostree.sh | 3 +-- test/cases/regression.sh | 2 +- test/cases/vmware.sh | 2 +- tools/libvirt_test.sh | 3 +-- tools/provision.sh | 3 +-- tools/set-env-variables.sh | 7 +++++++ 18 files changed, 24 insertions(+), 30 deletions(-) create mode 100644 tools/set-env-variables.sh diff --git a/osbuild-composer.spec b/osbuild-composer.spec index 756104aad..6d4f270b8 100644 --- a/osbuild-composer.spec +++ b/osbuild-composer.spec @@ -234,6 +234,7 @@ install -m 0755 -vp tools/image-info %{buildroot}%{_l install -m 0755 -vp tools/run-koji-container.sh %{buildroot}%{_libexecdir}/osbuild-composer-test/ install -m 0755 -vp tools/koji-compose.py %{buildroot}%{_libexecdir}/osbuild-composer-test/ install -m 0755 -vp tools/libvirt_test.sh %{buildroot}%{_libexecdir}/osbuild-composer-test/ +install -m 0755 -vp tools/set-env-variables.sh %{buildroot}%{_libexecdir}/osbuild-composer-test/ install -m 0755 -vd %{buildroot}%{_libexecdir}/tests/osbuild-composer install -m 0755 -vp test/cases/* %{buildroot}%{_libexecdir}/tests/osbuild-composer/ diff --git a/schutzbot/deploy.sh b/schutzbot/deploy.sh index c3ba59689..7bda50d76 100755 --- a/schutzbot/deploy.sh +++ b/schutzbot/deploy.sh @@ -51,8 +51,7 @@ EOF } # Get OS details. -source /etc/os-release -ARCH=$(uname -m) +source tools/set-env-variables.sh if [[ $ID == "rhel" && ${VERSION_ID%.*} == "9" ]]; then # There's a bug in RHEL 9 that causes /tmp to be mounted on tmpfs. diff --git a/schutzbot/mockbuild.sh b/schutzbot/mockbuild.sh index 87c9a7262..d063e3a1b 100755 --- a/schutzbot/mockbuild.sh +++ b/schutzbot/mockbuild.sh @@ -7,8 +7,7 @@ function greenprint { } # Get OS and architecture details. -source /etc/os-release -ARCH=$(uname -m) +source tools/set-env-variables.sh # Register RHEL if we are provided with a registration script. if [[ $ID == "rhel" && $VERSION_ID == "8.3" && -n "${RHN_REGISTRATION_SCRIPT:-}" ]] && ! sudo subscription-manager status; then diff --git a/schutzbot/run_cloud_cleaner.sh b/schutzbot/run_cloud_cleaner.sh index 7fe5326c6..f57a8b293 100755 --- a/schutzbot/run_cloud_cleaner.sh +++ b/schutzbot/run_cloud_cleaner.sh @@ -1,8 +1,7 @@ #!/bin/bash set -euo pipefail -source /etc/os-release -DISTRO_CODE="${DISTRO_CODE:-${ID}_${VERSION_ID//./}}" +source tools/set-env-variables.sh BRANCH_NAME="${BRANCH_NAME:-${CI_COMMIT_BRANCH}}" BUILD_ID="${BUILD_ID:-${CI_BUILD_ID}}" diff --git a/test/cases/api.sh b/test/cases/api.sh index 56036e1d1..5bf3f070d 100755 --- a/test/cases/api.sh +++ b/test/cases/api.sh @@ -17,8 +17,7 @@ set -euxo pipefail ARTIFACTS=ci-artifacts mkdir -p "${ARTIFACTS}" -source /etc/os-release -DISTRO_CODE="${DISTRO_CODE:-${ID}_${VERSION_ID//./}}" +source /usr/libexec/osbuild-composer-test/set-env-variables.sh # Container image used for cloud provider CLI tools CONTAINER_IMAGE_CLOUD_TOOLS="quay.io/osbuild/cloud-tools:latest" diff --git a/test/cases/aws.sh b/test/cases/aws.sh index 57fef1a91..b96e65014 100755 --- a/test/cases/aws.sh +++ b/test/cases/aws.sh @@ -1,8 +1,7 @@ #!/bin/bash set -euo pipefail -source /etc/os-release -DISTRO_CODE="${DISTRO_CODE:-${ID}_${VERSION_ID//./}}" +source /usr/libexec/osbuild-composer-test/set-env-variables.sh # Colorful output. function greenprint { diff --git a/test/cases/azure.sh b/test/cases/azure.sh index a6408dd9f..b009f6e95 100755 --- a/test/cases/azure.sh +++ b/test/cases/azure.sh @@ -2,8 +2,7 @@ shopt -s expand_aliases set -euo pipefail -source /etc/os-release -DISTRO_CODE="${DISTRO_CODE:-${ID}_${VERSION_ID//./}}" +source /usr/libexec/osbuild-composer-test/set-env-variables.sh BRANCH_NAME="${CI_COMMIT_BRANCH:-local}" BUILD_ID="${CI_BUILD_ID:-$(uuidgen)}" HYPER_V_GEN="${HYPER_V_GEN:-V1}" diff --git a/test/cases/image_tests.sh b/test/cases/image_tests.sh index a2ee49dff..01f2e5d43 100755 --- a/test/cases/image_tests.sh +++ b/test/cases/image_tests.sh @@ -2,9 +2,7 @@ set -euo pipefail # Get OS and architecture details. -source /etc/os-release -ARCH=$(uname -m) -DISTRO_CODE="${DISTRO_CODE:-${ID}_${VERSION_ID//./}}" +source /usr/libexec/osbuild-composer-test/set-env-variables.sh if [[ -n "$CI_BUILD_ID" ]]; then BUILD_ID="${BUILD_ID:-${CI_BUILD_ID}}" diff --git a/test/cases/installers.sh b/test/cases/installers.sh index c19c91007..744693eff 100755 --- a/test/cases/installers.sh +++ b/test/cases/installers.sh @@ -5,7 +5,7 @@ set -euo pipefail /usr/libexec/osbuild-composer-test/provision.sh # Get OS data. -source /etc/os-release +source /usr/libexec/osbuild-composer-test/set-env-variables.sh # Colorful output. function greenprint { diff --git a/test/cases/koji.sh b/test/cases/koji.sh index dc69eb1ad..7083b82e9 100755 --- a/test/cases/koji.sh +++ b/test/cases/koji.sh @@ -4,8 +4,7 @@ set -euo pipefail OSBUILD_COMPOSER_TEST_DATA=/usr/share/tests/osbuild-composer/ # Get OS data. -source /etc/os-release -ARCH=$(uname -m) +source /usr/libexec/osbuild-composer-test/set-env-variables.sh # Colorful output. function greenprint { diff --git a/test/cases/libvirt.sh b/test/cases/libvirt.sh index 84b151493..1b378c0cc 100644 --- a/test/cases/libvirt.sh +++ b/test/cases/libvirt.sh @@ -2,8 +2,7 @@ set -euo pipefail # Get OS data. -source /etc/os-release -DISTRO_CODE="${DISTRO_CODE:-${ID}_${VERSION_ID//./}}" +source /usr/libexec/osbuild-composer-test/set-env-variables.sh # Provision the software under test. /usr/libexec/osbuild-composer-test/provision.sh diff --git a/test/cases/ostree-ng.sh b/test/cases/ostree-ng.sh index 48da470a0..c10940cee 100755 --- a/test/cases/ostree-ng.sh +++ b/test/cases/ostree-ng.sh @@ -5,8 +5,7 @@ set -euo pipefail /usr/libexec/osbuild-composer-test/provision.sh # Get OS data. -source /etc/os-release -ARCH=$(uname -m) +source /usr/libexec/osbuild-composer-test/set-env-variables.sh # Colorful output. function greenprint { diff --git a/test/cases/ostree.sh b/test/cases/ostree.sh index 14527c028..30040c604 100755 --- a/test/cases/ostree.sh +++ b/test/cases/ostree.sh @@ -4,8 +4,7 @@ set -euo pipefail source /usr/libexec/osbuild-composer-test/define-compose-url.sh # Get OS data. -source /etc/os-release -ARCH=$(uname -m) +source /usr/libexec/osbuild-composer-test/set-env-variables.sh # Provision the software under test. /usr/libexec/osbuild-composer-test/provision.sh diff --git a/test/cases/regression.sh b/test/cases/regression.sh index 01705b6c6..b1b1864a2 100644 --- a/test/cases/regression.sh +++ b/test/cases/regression.sh @@ -1,7 +1,7 @@ #!/bin/bash set -euo pipefail -source /etc/os-release +source /usr/libexec/osbuild-composer-test/set-env-variables.sh TESTS_PATH=/usr/libexec/tests/osbuild-composer/ mkdir --parents /tmp/logs diff --git a/test/cases/vmware.sh b/test/cases/vmware.sh index 4ae7279af..0c058810e 100755 --- a/test/cases/vmware.sh +++ b/test/cases/vmware.sh @@ -1,7 +1,7 @@ #!/bin/bash set -euo pipefail -source /etc/os-release +source /usr/libexec/osbuild-composer-test/set-env-variables.sh # Colorful output. function greenprint { diff --git a/tools/libvirt_test.sh b/tools/libvirt_test.sh index 7ca4c4a69..8663d7106 100755 --- a/tools/libvirt_test.sh +++ b/tools/libvirt_test.sh @@ -4,8 +4,7 @@ set -euo pipefail OSBUILD_COMPOSER_TEST_DATA=/usr/share/tests/osbuild-composer/ # Get OS data. -source /etc/os-release -ARCH=$(uname -m) +source /usr/libexec/osbuild-composer-test/set-env-variables.sh # Take the image type passed to the script or use qcow2 by default if nothing # was passed. diff --git a/tools/provision.sh b/tools/provision.sh index 25badacc8..67c71a136 100755 --- a/tools/provision.sh +++ b/tools/provision.sh @@ -1,8 +1,7 @@ #!/bin/bash set -euxo pipefail -source /etc/os-release -ARCH=$(uname -m) +source /usr/libexec/osbuild-composer-test/set-env-variables.sh # koji and ansible are not in RHEL repositories. Depending on them in the spec # file breaks RHEL gating (see OSCI-1541). Therefore, we need to enable epel diff --git a/tools/set-env-variables.sh b/tools/set-env-variables.sh new file mode 100644 index 000000000..91e616297 --- /dev/null +++ b/tools/set-env-variables.sh @@ -0,0 +1,7 @@ +#!/bin/bash +# don't error on unused ARCH and DISTRO_CODE variables +# shellcheck disable=SC2034 + +source /etc/os-release +ARCH=$(uname -m) +DISTRO_CODE="${DISTRO_CODE:-${ID}_${VERSION_ID//./}}"