From 6b0f055b4ed407f8a190f768d0e654235ac015dd Mon Sep 17 00:00:00 2001 From: Yadnesh Kulkarni Date: Thu, 23 Nov 2023 11:59:49 +0530 Subject: [PATCH] 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 --- functions | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/functions b/functions index 7ada0feba7..01e1d259ad 100644 --- a/functions +++ b/functions @@ -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