From ff82dec37f53ffeee9af7e6e688cf6182b165ff6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Hozza?= Date: Wed, 14 Sep 2022 22:20:23 +0200 Subject: [PATCH] test/api/common: add `cleanupVSphere()` and use it where appropriate Clean up VSphere in all S3 test case implementations, which were previously not cleaning up after themselves. --- test/cases/api/aws.s3.sh | 4 ++++ test/cases/api/common/vsphere.sh | 31 +++++++++++++++++++++++++++++++ test/cases/api/generic.s3.sh | 3 +++ 3 files changed, 38 insertions(+) diff --git a/test/cases/api/aws.s3.sh b/test/cases/api/aws.s3.sh index 746a11907..ead9b6c1a 100644 --- a/test/cases/api/aws.s3.sh +++ b/test/cases/api/aws.s3.sh @@ -31,6 +31,10 @@ function cleanup() { if [ -n "$AWS_CMD" ]; then $AWS_CMD s3 rm "${S3_URI}" fi + + if [ "${IMAGE_TYPE}" == "${IMAGE_TYPE_VSPHERE}" ]; then + cleanupVSphere + fi } function installClient() { diff --git a/test/cases/api/common/vsphere.sh b/test/cases/api/common/vsphere.sh index 0772baad4..bc7fdffc4 100644 --- a/test/cases/api/common/vsphere.sh +++ b/test/cases/api/common/vsphere.sh @@ -215,3 +215,34 @@ function verifyInVSphere() { greenprint "✅ Successfully verified VSphere image with cloud-init" } + +function cleanupVSphere() { + # since this function can be called at any time, ensure that we don't expand unbound variables + GOVC_CMD="${GOVC_CMD:-}" + VSPHERE_VM_NAME="${VSPHERE_VM_NAME:-}" + VSPHERE_CIDATA_ISO_PATH="${VSPHERE_CIDATA_ISO_PATH:-}" + + greenprint "🧹 Cleaning up the VSphere VM" + $GOVC_CMD vm.destroy \ + -u "${GOVMOMI_USERNAME}:${GOVMOMI_PASSWORD}@${GOVMOMI_URL}" \ + -k=true \ + -dc="${GOVC_DATACENTER}" \ + "${VSPHERE_VM_NAME}" + + greenprint "🧹 Cleaning up the VSphere Datastore" + $GOVC_CMD datastore.rm \ + -u "${GOVMOMI_USERNAME}:${GOVMOMI_PASSWORD}@${GOVMOMI_URL}" \ + -k=true \ + -dc="${GOVC_DATACENTER}" \ + -ds="${GOVMOMI_DATASTORE}" \ + -f \ + "${VSPHERE_CIDATA_ISO_PATH}" + + $GOVC_CMD datastore.rm \ + -u "${GOVMOMI_USERNAME}:${GOVMOMI_PASSWORD}@${GOVMOMI_URL}" \ + -k=true \ + -dc="${GOVC_DATACENTER}" \ + -ds="${GOVMOMI_DATASTORE}" \ + -f \ + "${VSPHERE_VM_NAME}" +} diff --git a/test/cases/api/generic.s3.sh b/test/cases/api/generic.s3.sh index 193461be6..e3cdf074d 100644 --- a/test/cases/api/generic.s3.sh +++ b/test/cases/api/generic.s3.sh @@ -20,6 +20,9 @@ function cleanup() { if [ -n "${MINIO_CONTAINER_NAME}" ]; then sudo "${CONTAINER_RUNTIME}" kill "${MINIO_CONTAINER_NAME}" fi + if [ "${IMAGE_TYPE}" == "${IMAGE_TYPE_VSPHERE}" ]; then + cleanupVSphere + fi } function installClient() {