Make multiple attempts to download image

Downloading an image can fail due to network issues, so let's
retry 5 times before giving up. We have seen issues in CI due
to network issues as described below and in the Related-Bug:-

Often times fetching Fedora image in FIPS jobs fails due to
"GnuTLS: One of the involved algorithms has insufficient security level."

This occurs when request to pull image is redirected to a mirror that's
incompatible with FIPS enabled system.

Making multiple attempts to download images could provide better chance of
pulling images from different mirrors and avoid failure of the job.
This will also save a few rechecks.

Related-Bug: #2045725
Change-Id: I7163aea4d121cb27620e4f2a083a543abfc286bf
(cherry picked from commit 6b0f055b4e)
This commit is contained in:
Yadnesh Kulkarni 2023-11-23 11:59:49 +05:30 committed by yatin
parent 146bf0d10c
commit c32b528f8d
1 changed files with 16 additions and 5 deletions

View File

@ -133,17 +133,28 @@ function upload_image {
local image image_fname image_name
local max_attempts=5
# Create a directory for the downloaded image tarballs.
mkdir -p $FILES/images
image_fname=`basename "$image_url"`
if [[ $image_url != file* ]]; then
# Downloads the image (uec ami+akistyle), then extracts it.
if [[ ! -f $FILES/$image_fname || "$(stat -c "%s" $FILES/$image_fname)" = "0" ]]; then
wget --progress=dot:giga -c $image_url -O $FILES/$image_fname
if [[ $? -ne 0 ]]; then
echo "Not found: $image_url"
return
fi
for attempt in `seq $max_attempts`; do
local rc=0
wget --progress=dot:giga -c $image_url -O $FILES/$image_fname || rc=$?
if [[ $rc -ne 0 ]]; then
if [[ "$attempt" -eq "$max_attempts" ]]; then
echo "Not found: $image_url"
return
fi
echo "Download failed, retrying in $attempt second, attempt: $attempt"
sleep $attempt
else
break
fi
done
fi
image="$FILES/${image_fname}"
else