From 5a76595fe9f5ff86054aee39646520fee519d2ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Budai?= Date: Mon, 17 Mar 2025 09:33:24 +0100 Subject: [PATCH] test: retry uploads in the openshift virt test The networking to the cluster seems slightly flakey, so I noticed a few failures when playing with it. A little retry is able to fix it. The function was taken from deploy.sh. I considered de-duping it, but deploy.sh runs in a context where /usr/libexec/tests/osbuild-composer/shared_lib.sh is not yet established, so it's unfortunately no so simple. :( --- test/cases/openshift_virtualization.sh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/test/cases/openshift_virtualization.sh b/test/cases/openshift_virtualization.sh index 506fde998..9051d0ba2 100755 --- a/test/cases/openshift_virtualization.sh +++ b/test/cases/openshift_virtualization.sh @@ -30,6 +30,23 @@ function cleanup() { } trap cleanup EXIT +function retry { + local count=0 + local retries=5 + until "$@"; do + exit=$? + count=$((count + 1)) + if [[ $count -lt $retries ]]; then + echo "Retrying command..." + sleep 1 + else + echo "Command failed after ${retries} retries. Giving up." + return $exit + fi + done + return 0 +} + ARCH=$(uname -m) # OpenShift doesn't like upper-case, dots and underscores TEST_ID=$(echo "$DISTRO_CODE-$ARCH-$BRANCH_NAME-$BUILD_ID" | tr "[:upper:]" "[:lower:]" | tr "_." "-") @@ -178,7 +195,7 @@ STORAGE_CLASS="rh-restricted-nfs" # import the image into a data volume; total quota on the namespace seems to be 500 GiB PVC_NAME="image-builder-data-volume-$TEST_ID" -"$VIRTCTL" image-upload --insecure dv "$PVC_NAME" --size=10Gi --storage-class="${STORAGE_CLASS}" --image-path="${IMAGE_FILENAME}" +retry "$VIRTCTL" image-upload --insecure dv "$PVC_NAME" --size=10Gi --storage-class="${STORAGE_CLASS}" --image-path="${IMAGE_FILENAME}" # Note: --size=10Gi corresponds to the size of the filesystem inside the image, not the actual size of the qcow2 file PVC_VOLUME_ID=$($OC_CLI get pvc "$PVC_NAME" -o json | jq -r ".spec.volumeName")