From 9e9aec5b53559176bef72732e6b9066032556648 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Hozza?= Date: Wed, 14 Sep 2022 22:09:00 +0200 Subject: [PATCH] test/api: move `govc` installation to `common/vsphere.sh` Move the installation of the VSphere client out of the `api/common/aws.sh` `installClient()` function into a dedicated `installClientVSphere()` function in `api/common/vsphere.sh`. Rename the `installClient()` in `api/common/aws.sh` to `installAWSClient()`. Introduce `installClient()` in both, `api/aws.sh` and `api/aws.s3.sh`, which calls `installAWSClient()`. Call `installClientVSphere()` conditionally when testing VMDK image type in `api/aws.s3.sh` and `api/generic.s3.sh`. --- test/cases/api/aws.s3.sh | 9 +++++++++ test/cases/api/aws.sh | 3 +++ test/cases/api/common/aws.sh | 21 +-------------------- test/cases/api/common/vsphere.sh | 26 ++++++++++++++++++++++++++ test/cases/api/generic.s3.sh | 5 +++++ 5 files changed, 44 insertions(+), 20 deletions(-) create mode 100644 test/cases/api/common/vsphere.sh diff --git a/test/cases/api/aws.s3.sh b/test/cases/api/aws.s3.sh index 922820c2d..49e1e49e9 100644 --- a/test/cases/api/aws.s3.sh +++ b/test/cases/api/aws.s3.sh @@ -2,6 +2,7 @@ source /usr/libexec/tests/osbuild-composer/api/common/aws.sh source /usr/libexec/tests/osbuild-composer/api/common/common.sh +source /usr/libexec/tests/osbuild-composer/api/common/vsphere.sh source /usr/libexec/tests/osbuild-composer/api/common/s3.sh # Check that needed variables are set to access AWS. @@ -33,6 +34,14 @@ function cleanup() { fi } +function installClient() { + installAWSClient + + if [ "${IMAGE_TYPE}" == "${IMAGE_TYPE_VSPHERE}" ]; then + installClientVSphere + fi +} + function createReqFile() { case ${IMAGE_TYPE} in "$IMAGE_TYPE_EDGE_COMMIT"|"$IMAGE_TYPE_EDGE_CONTAINER"|"$IMAGE_TYPE_EDGE_INSTALLER"|"$IMAGE_TYPE_IMAGE_INSTALLER") diff --git a/test/cases/api/aws.sh b/test/cases/api/aws.sh index dc2e75563..469e20397 100644 --- a/test/cases/api/aws.sh +++ b/test/cases/api/aws.sh @@ -27,6 +27,9 @@ function cleanup() { fi } +function installClient() { + installAWSClient +} function createReqFile() { AWS_SNAPSHOT_NAME=${TEST_ID} diff --git a/test/cases/api/common/aws.sh b/test/cases/api/common/aws.sh index 881ce0057..93b0c5d18 100644 --- a/test/cases/api/common/aws.sh +++ b/test/cases/api/common/aws.sh @@ -1,7 +1,7 @@ #!/usr/bin/bash source /usr/libexec/tests/osbuild-composer/shared_lib.sh -function installClient() { +function installAWSClient() { if ! hash aws; then echo "Using 'awscli' from a container" sudo "${CONTAINER_RUNTIME}" pull "${CONTAINER_IMAGE_CLOUD_TOOLS}" @@ -16,25 +16,6 @@ function installClient() { AWS_CMD="aws --region $AWS_REGION --output json --color on" fi $AWS_CMD --version - - if ! hash govc; then - ARCH="$(uname -m)" - if [ "$ARCH" = "aarch64" ]; then - ARCH="arm64" - fi - greenprint "Installing govc" - pushd "${WORKDIR}" || exit 1 - curl -Ls --retry 5 --output govc.tar.gz \ - "https://github.com/vmware/govmomi/releases/download/v0.29.0/govc_Linux_$ARCH.tar.gz" - tar -xvf govc.tar.gz - GOVC_CMD="${WORKDIR}/govc" - chmod +x "${GOVC_CMD}" - popd || exit 1 - else - echo "Using pre-installed 'govc' from the system" - GOVC_CMD="govc" - fi - $GOVC_CMD version } # Log into AWS diff --git a/test/cases/api/common/vsphere.sh b/test/cases/api/common/vsphere.sh new file mode 100644 index 000000000..4248ca68a --- /dev/null +++ b/test/cases/api/common/vsphere.sh @@ -0,0 +1,26 @@ +#!/usr/bin/bash + +source /usr/libexec/tests/osbuild-composer/shared_lib.sh + +function installClientVSphere() { + if ! hash govc; then + ARCH="$(uname -m)" + if [ "$ARCH" = "aarch64" ]; then + ARCH="arm64" + fi + greenprint "Installing govc" + pushd "${WORKDIR}" || exit 1 + curl -Ls --retry 5 --output govc.tar.gz \ + "https://github.com/vmware/govmomi/releases/download/v0.29.0/govc_Linux_$ARCH.tar.gz" + tar -xvf govc.tar.gz + GOVC_CMD="${WORKDIR}/govc" + chmod +x "${GOVC_CMD}" + popd || exit 1 + else + echo "Using pre-installed 'govc' from the system" + GOVC_CMD="govc" + fi + + $GOVC_CMD version +} + diff --git a/test/cases/api/generic.s3.sh b/test/cases/api/generic.s3.sh index 01507b3e6..c61d4dfce 100644 --- a/test/cases/api/generic.s3.sh +++ b/test/cases/api/generic.s3.sh @@ -1,6 +1,7 @@ #!/usr/bin/bash source /usr/libexec/tests/osbuild-composer/api/common/common.sh +source /usr/libexec/tests/osbuild-composer/api/common/vsphere.sh source /usr/libexec/tests/osbuild-composer/api/common/s3.sh source /usr/libexec/tests/osbuild-composer/shared_lib.sh @@ -56,6 +57,10 @@ function installClient() { AWS_CMD+=" --region $MINIO_REGION --output json --color on --endpoint-url $MINIO_ENDPOINT" $AWS_CMD --version + if [ "${IMAGE_TYPE}" == "${IMAGE_TYPE_VSPHERE}" ]; then + installClientVSphere + fi + # Configure the local server (retry until the service is up) MINIO_CONFIGURE_RETRY=0 MINIO_CONFIGURE_MAX_RETRY=5