From bf83bbea384e7b161d257783599913a10aa51c56 Mon Sep 17 00:00:00 2001 From: Achilleas Koutsou Date: Tue, 30 Aug 2022 16:08:04 +0200 Subject: [PATCH] test: move greenprint and redprint functions to shared_lib.sh Since we're sharing functions between test scripts, move greenprint(), the most rewritten function in the history of the project, to shared_lib.sh and source it everywhere. --- test/cases/api.sh | 5 +---- test/cases/api/common/aws.sh | 1 + test/cases/api/common/s3.sh | 2 ++ test/cases/api/generic.s3.sh | 1 + test/cases/aws.sh | 4 ---- test/cases/azure.sh | 5 ----- test/cases/container-embedding.sh | 4 ---- test/cases/container-upload.sh | 4 ---- test/cases/diff-manifests.sh | 6 ++---- test/cases/filesystem.sh | 5 ----- test/cases/gcp.sh | 4 ---- test/cases/installers.sh | 5 ----- test/cases/koji.sh | 5 +---- test/cases/multi-tenancy.sh | 6 +----- test/cases/oscap.sh | 5 ----- test/cases/ostree-ng.sh | 5 ----- test/cases/ostree-raw-image.sh | 4 ---- test/cases/ostree-rebase-bios.sh | 5 ----- test/cases/ostree-rebase-uefi.sh | 5 ----- test/cases/ostree-simplified-installer.sh | 5 ----- test/cases/ostree.sh | 5 ----- ...regression-composer-works-behind-satellite-fallback.sh | 4 ---- test/cases/regression-composer-works-behind-satellite.sh | 4 +--- test/cases/regression-insecure-repo.sh | 4 ---- test/cases/regression-old-worker-new-composer.sh | 4 ---- test/cases/shared_lib.sh | 8 ++++++++ test/cases/upgrade8to9.sh | 5 +---- test/cases/vmware.sh | 4 ---- 28 files changed, 19 insertions(+), 105 deletions(-) diff --git a/test/cases/api.sh b/test/cases/api.sh index c43a18524..da1ec008d 100755 --- a/test/cases/api.sh +++ b/test/cases/api.sh @@ -79,14 +79,11 @@ case ${IMAGE_TYPE} in exit 1 esac -# Colorful timestamped output. -function greenprint { - echo -e "\033[1;32m[$(date -Isecond)] ${1}\033[0m" -} ARTIFACTS="${ARTIFACTS:-/tmp/artifacts}" source /usr/libexec/osbuild-composer-test/set-env-variables.sh +source /usr/libexec/tests/osbuild-composer/shared_lib.sh # Container image used for cloud provider CLI tools export CONTAINER_IMAGE_CLOUD_TOOLS="quay.io/osbuild/cloud-tools:latest" diff --git a/test/cases/api/common/aws.sh b/test/cases/api/common/aws.sh index cc5c04f9c..881ce0057 100644 --- a/test/cases/api/common/aws.sh +++ b/test/cases/api/common/aws.sh @@ -1,4 +1,5 @@ #!/usr/bin/bash +source /usr/libexec/tests/osbuild-composer/shared_lib.sh function installClient() { if ! hash aws; then diff --git a/test/cases/api/common/s3.sh b/test/cases/api/common/s3.sh index a3f812a24..638fde7e8 100644 --- a/test/cases/api/common/s3.sh +++ b/test/cases/api/common/s3.sh @@ -1,5 +1,7 @@ #!/usr/bin/bash +source /usr/libexec/tests/osbuild-composer/shared_lib.sh + function createReqFileEdge() { cat > "$REQUEST_FILE" << EOF { diff --git a/test/cases/api/generic.s3.sh b/test/cases/api/generic.s3.sh index 0301e0b04..01507b3e6 100644 --- a/test/cases/api/generic.s3.sh +++ b/test/cases/api/generic.s3.sh @@ -2,6 +2,7 @@ source /usr/libexec/tests/osbuild-composer/api/common/common.sh source /usr/libexec/tests/osbuild-composer/api/common/s3.sh +source /usr/libexec/tests/osbuild-composer/shared_lib.sh function checkEnv() { printenv AWS_REGION > /dev/null diff --git a/test/cases/aws.sh b/test/cases/aws.sh index 19ea232f9..d28a7eb4d 100755 --- a/test/cases/aws.sh +++ b/test/cases/aws.sh @@ -12,10 +12,6 @@ set -euo pipefail source /usr/libexec/osbuild-composer-test/set-env-variables.sh source /usr/libexec/tests/osbuild-composer/shared_lib.sh -# Colorful output. -function greenprint { - echo -e "\033[1;32m[$(date -Isecond)] ${1}\033[0m" -} # Container image used for cloud provider CLI tools CONTAINER_IMAGE_CLOUD_TOOLS="quay.io/osbuild/cloud-tools:latest" diff --git a/test/cases/azure.sh b/test/cases/azure.sh index c5b99a43c..61b1b25b0 100755 --- a/test/cases/azure.sh +++ b/test/cases/azure.sh @@ -17,11 +17,6 @@ BRANCH_NAME="${CI_COMMIT_BRANCH:-local}" BUILD_ID="${CI_BUILD_ID:-$(uuidgen)}" HYPER_V_GEN="${HYPER_V_GEN:-V1}" -# Colorful output. -function greenprint { - echo -e "\033[1;32m[$(date -Isecond)] ${1}\033[0m" -} - # Container image used for cloud provider CLI tools CONTAINER_IMAGE_CLOUD_TOOLS="quay.io/osbuild/cloud-tools:latest" diff --git a/test/cases/container-embedding.sh b/test/cases/container-embedding.sh index daa2fa6b0..166eb9d0b 100755 --- a/test/cases/container-embedding.sh +++ b/test/cases/container-embedding.sh @@ -1,10 +1,6 @@ #!/usr/bin/bash set -euxo pipefail -# Colorful timestamped output. -function greenprint { - echo -e "\033[1;32m[$(date -Isecond)] ${1}\033[0m" -} source /usr/libexec/osbuild-composer-test/set-env-variables.sh source /usr/libexec/tests/osbuild-composer/shared_lib.sh diff --git a/test/cases/container-upload.sh b/test/cases/container-upload.sh index e14fb7dd4..ee75a0815 100755 --- a/test/cases/container-upload.sh +++ b/test/cases/container-upload.sh @@ -1,10 +1,6 @@ #!/usr/bin/bash set -euxo pipefail -# Colorful timestamped output. -function greenprint { - echo -e "\033[1;32m[$(date -Isecond)] ${1}\033[0m" -} source /usr/libexec/osbuild-composer-test/set-env-variables.sh source /usr/libexec/tests/osbuild-composer/shared_lib.sh diff --git a/test/cases/diff-manifests.sh b/test/cases/diff-manifests.sh index d40e79b56..f052017e2 100755 --- a/test/cases/diff-manifests.sh +++ b/test/cases/diff-manifests.sh @@ -2,13 +2,11 @@ set -euo pipefail -# Colorful output. +# Colorful timestamped output. function greenprint { echo -e "\033[1;32m[$(date -Isecond)] ${1}\033[0m" } -function redprint { - echo -e "\033[1;31m[$(date -Isecond)] ${1}\033[0m" -} + function revert_to_head { git checkout "$head" } diff --git a/test/cases/filesystem.sh b/test/cases/filesystem.sh index 46dea0c9a..d68701661 100644 --- a/test/cases/filesystem.sh +++ b/test/cases/filesystem.sh @@ -12,11 +12,6 @@ source /etc/os-release source /usr/libexec/tests/osbuild-composer/shared_lib.sh -# Colorful output. -function greenprint { - echo -e "\033[1;32m[$(date -Isecond)] ${1}\033[0m" -} - TEST_UUID=$(uuidgen) IMAGE_KEY="osbuild-composer-test-${TEST_UUID}" diff --git a/test/cases/gcp.sh b/test/cases/gcp.sh index bef24fa72..ecf03d55f 100755 --- a/test/cases/gcp.sh +++ b/test/cases/gcp.sh @@ -12,10 +12,6 @@ source /usr/libexec/tests/osbuild-composer/shared_lib.sh set -euo pipefail -# Colorful output. -function greenprint { - echo -e "\033[1;32m[$(date -Isecond)] ${1}\033[0m" -} # Container image used for cloud provider CLI tools CONTAINER_IMAGE_CLOUD_TOOLS="quay.io/osbuild/cloud-tools:latest" diff --git a/test/cases/installers.sh b/test/cases/installers.sh index 4bf4796d7..e95396239 100755 --- a/test/cases/installers.sh +++ b/test/cases/installers.sh @@ -15,11 +15,6 @@ set -euo pipefail source /usr/libexec/osbuild-composer-test/set-env-variables.sh source /usr/libexec/tests/osbuild-composer/shared_lib.sh -# Colorful output. -function greenprint { - echo -e "\033[1;32m[$(date -Isecond)] ${1}\033[0m" -} - # modify existing kickstart by prepending and appending commands function modksiso { sudo dnf install -y lorax # for mkksiso diff --git a/test/cases/koji.sh b/test/cases/koji.sh index f0322b68e..7fd4400f4 100755 --- a/test/cases/koji.sh +++ b/test/cases/koji.sh @@ -5,11 +5,8 @@ OSBUILD_COMPOSER_TEST_DATA=/usr/share/tests/osbuild-composer/ # Get OS data. source /usr/libexec/osbuild-composer-test/set-env-variables.sh +source /usr/libexec/tests/osbuild-composer/shared_lib.sh -# Colorful output. -function greenprint { - echo -e "\033[1;32m[$(date -Isecond)] ${1}\033[0m" -} if [ "${NIGHTLY:=false}" == "true" ]; then greenprint "INFO: Test not supported during nightly CI pipelines. Exiting ..." diff --git a/test/cases/multi-tenancy.sh b/test/cases/multi-tenancy.sh index 7982b0558..62ae413fd 100755 --- a/test/cases/multi-tenancy.sh +++ b/test/cases/multi-tenancy.sh @@ -15,16 +15,12 @@ OSBUILD_COMPOSER_TEST_DATA=/usr/share/tests/osbuild-composer/ # Get OS data. source /usr/libexec/osbuild-composer-test/set-env-variables.sh -# Colorful output. -function greenprint { - echo -e "\033[1;32m[$(date -Isecond)] ${1}\033[0m" -} - # Provision the software under test. /usr/libexec/osbuild-composer-test/provision.sh jwt # Source common functions source /usr/libexec/tests/osbuild-composer/api/common/common.sh +source /usr/libexec/tests/osbuild-composer/shared_lib.sh greenprint "Registering clean ups" KILL_PIDS=() diff --git a/test/cases/oscap.sh b/test/cases/oscap.sh index 49c7adcdc..db9208763 100755 --- a/test/cases/oscap.sh +++ b/test/cases/oscap.sh @@ -11,11 +11,6 @@ source /etc/os-release source /usr/libexec/tests/osbuild-composer/shared_lib.sh -# Colorful output. -function greenprint { - echo -e "\033[1;32m[$(date -Isecond)] ${1}\033[0m" -} - # Start libvirtd and test it. greenprint "🚀 Starting libvirt daemon" sudo systemctl start libvirtd diff --git a/test/cases/ostree-ng.sh b/test/cases/ostree-ng.sh index 9d6f71ca5..e8d6ff14a 100755 --- a/test/cases/ostree-ng.sh +++ b/test/cases/ostree-ng.sh @@ -8,11 +8,6 @@ set -euo pipefail source /usr/libexec/osbuild-composer-test/set-env-variables.sh source /usr/libexec/tests/osbuild-composer/shared_lib.sh -# Colorful output. -function greenprint { - echo -e "\033[1;32m[$(date -Isecond)] ${1}\033[0m" -} - # Install openshift client greenprint "🔧 Installing oenshift client(oc)" diff --git a/test/cases/ostree-raw-image.sh b/test/cases/ostree-raw-image.sh index 6962aaf73..4c3b974f4 100755 --- a/test/cases/ostree-raw-image.sh +++ b/test/cases/ostree-raw-image.sh @@ -10,10 +10,6 @@ source /usr/libexec/tests/osbuild-composer/shared_lib.sh source /etc/os-release ARCH=$(uname -m) -# Colorful output. -function greenprint { - echo -e "\033[1;32m[$(date -Isecond)] ${1}\033[0m" -} # Start libvirtd and test it. greenprint "🚀 Starting libvirt daemon" diff --git a/test/cases/ostree-rebase-bios.sh b/test/cases/ostree-rebase-bios.sh index 8782ae9e9..cd901cb21 100755 --- a/test/cases/ostree-rebase-bios.sh +++ b/test/cases/ostree-rebase-bios.sh @@ -14,11 +14,6 @@ fi # Provision the software under test. /usr/libexec/osbuild-composer-test/provision.sh none -# Colorful output. -function greenprint { - echo -e "\033[1;32m[$(date -Isecond)] ${1}\033[0m" -} - # Start libvirtd and test it. greenprint "🚀 Starting libvirt daemon" sudo systemctl start libvirtd diff --git a/test/cases/ostree-rebase-uefi.sh b/test/cases/ostree-rebase-uefi.sh index fcc04af57..0119f14c6 100755 --- a/test/cases/ostree-rebase-uefi.sh +++ b/test/cases/ostree-rebase-uefi.sh @@ -13,11 +13,6 @@ fi # Provision the software under test. /usr/libexec/osbuild-composer-test/provision.sh none -# Colorful output. -function greenprint { - echo -e "\033[1;32m[$(date -Isecond)] ${1}\033[0m" -} - # Start libvirtd and test it. greenprint "🚀 Starting libvirt daemon" sudo systemctl start libvirtd diff --git a/test/cases/ostree-simplified-installer.sh b/test/cases/ostree-simplified-installer.sh index 3725a6da8..0defaec3c 100755 --- a/test/cases/ostree-simplified-installer.sh +++ b/test/cases/ostree-simplified-installer.sh @@ -8,11 +8,6 @@ set -euo pipefail source /etc/os-release ARCH=$(uname -m) -# Colorful output. -function greenprint { - echo -e "\033[1;32m[$(date -Isecond)] ${1}\033[0m" -} - source /usr/libexec/tests/osbuild-composer/shared_lib.sh # Start firewalld diff --git a/test/cases/ostree.sh b/test/cases/ostree.sh index 0c31f3dc1..9847850a0 100755 --- a/test/cases/ostree.sh +++ b/test/cases/ostree.sh @@ -111,11 +111,6 @@ case "${ID}-${VERSION_ID}" in esac -# Colorful output. -function greenprint { - echo -e "\033[1;32m[$(date -Isecond)] ${1}\033[0m" -} - # Start libvirtd and test it. greenprint "🚀 Starting libvirt daemon" sudo systemctl start libvirtd diff --git a/test/cases/regression-composer-works-behind-satellite-fallback.sh b/test/cases/regression-composer-works-behind-satellite-fallback.sh index 286006ad3..b7b931818 100644 --- a/test/cases/regression-composer-works-behind-satellite-fallback.sh +++ b/test/cases/regression-composer-works-behind-satellite-fallback.sh @@ -7,10 +7,6 @@ set -exuo pipefail -function greenprint { - echo -e "\033[1;32m[$(date -Isecond)] ${1}\033[0m" -} - function generate_certificates { # Generate CA root key sudo openssl genrsa -out ca.key diff --git a/test/cases/regression-composer-works-behind-satellite.sh b/test/cases/regression-composer-works-behind-satellite.sh index 08cd3bb4d..c77b0f5cc 100644 --- a/test/cases/regression-composer-works-behind-satellite.sh +++ b/test/cases/regression-composer-works-behind-satellite.sh @@ -8,9 +8,7 @@ set -exuo pipefail -function greenprint { - echo -e "\033[1;32m[$(date -Isecond)] ${1}\033[0m" -} +source /usr/libexec/tests/osbuild-composer/shared_lib.sh function generate_certificates { # Generate CA root key diff --git a/test/cases/regression-insecure-repo.sh b/test/cases/regression-insecure-repo.sh index fb5729885..7676bfa32 100644 --- a/test/cases/regression-insecure-repo.sh +++ b/test/cases/regression-insecure-repo.sh @@ -6,10 +6,6 @@ set -xeuo pipefail -function greenprint { - echo -e "\033[1;32m[$(date -Isecond)] ${1}\033[0m" -} - source /usr/libexec/osbuild-composer-test/set-env-variables.sh source /usr/libexec/tests/osbuild-composer/shared_lib.sh diff --git a/test/cases/regression-old-worker-new-composer.sh b/test/cases/regression-old-worker-new-composer.sh index f0bb39d56..72c50ce5a 100644 --- a/test/cases/regression-old-worker-new-composer.sh +++ b/test/cases/regression-old-worker-new-composer.sh @@ -7,10 +7,6 @@ set -exuo pipefail -# Colorful timestamped output. -function greenprint { - echo -e "\033[1;32m[$(date -Isecond)] ${1}\033[0m" -} ARTIFACTS="${ARTIFACTS:-/tmp/artifacts}" diff --git a/test/cases/shared_lib.sh b/test/cases/shared_lib.sh index 2bba5a68a..99c76a9dd 100755 --- a/test/cases/shared_lib.sh +++ b/test/cases/shared_lib.sh @@ -33,3 +33,11 @@ function get_build_info() { jq -r "${key}" "${fname}" } +# Colorful timestamped output. +function greenprint { + echo -e "\033[1;32m[$(date -Isecond)] ${1}\033[0m" +} + +function redprint { + echo -e "\033[1;31m[$(date -Isecond)] ${1}\033[0m" +} diff --git a/test/cases/upgrade8to9.sh b/test/cases/upgrade8to9.sh index f8179c9ac..b54ba512c 100755 --- a/test/cases/upgrade8to9.sh +++ b/test/cases/upgrade8to9.sh @@ -3,13 +3,10 @@ set -uxo pipefail # Get OS data. source /usr/libexec/osbuild-composer-test/set-env-variables.sh +source /usr/libexec/tests/osbuild-composer/shared_lib.sh ARTIFACTS="${ARTIFACTS:-/tmp/artifacts}" -# Colorful output. -function greenprint { - echo -e "\033[1;32m[$(date -Isecond)] ${1}\033[0m" -} # Wait for VM to start function wait_for_vm { diff --git a/test/cases/vmware.sh b/test/cases/vmware.sh index 34c75568d..2f109751c 100755 --- a/test/cases/vmware.sh +++ b/test/cases/vmware.sh @@ -12,10 +12,6 @@ set -euo pipefail source /usr/libexec/osbuild-composer-test/set-env-variables.sh source /usr/libexec/tests/osbuild-composer/shared_lib.sh -# Colorful output. -function greenprint { - echo -e "\033[1;32m[$(date -Isecond)] ${1}\033[0m" -} # Provision the software under test. /usr/libexec/osbuild-composer-test/provision.sh none