From 52391df1b0998350dfe476e8522af75825475bd6 Mon Sep 17 00:00:00 2001 From: Ahmad Hafe Date: Tue, 30 Jun 2026 17:14:57 +0300 Subject: [PATCH] Add retry with timeout for virtctl download to handle transient SSL errors Signed-off-by: Ahmad Hafe Co-authored-by: Cursor Signed-off-by: Ahmad Hafe Co-authored-by: Cursor --- utilities/infra.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/utilities/infra.py b/utilities/infra.py index 788b345eab..b7d23bc374 100644 --- a/utilities/infra.py +++ b/utilities/infra.py @@ -675,6 +675,24 @@ def get_all_console_links(console_cli_downloads_spec_links): return all_urls +@retry( + wait_timeout=TIMEOUT_2MIN, + sleep=TIMEOUT_10SEC, + exceptions_dict={ + requests.exceptions.SSLError: [], + requests.exceptions.ConnectionError: [], + requests.exceptions.Timeout: [], + }, +) +def _download_file(url: str, local_file_name: str) -> str: + urllib3.disable_warnings() # TODO: remove this when we fix the SSL warning + response = requests.get(url=url, verify=False, timeout=TIMEOUT_30SEC) + response.raise_for_status() + with open(local_file_name, "wb") as file_downloaded: + file_downloaded.write(response.content) + return local_file_name + + def download_and_extract_file_from_cluster(tmpdir, url): """ Download and extract archive file from the cluster @@ -688,12 +706,8 @@ def download_and_extract_file_from_cluster(tmpdir, url): """ zip_file_extension = ".zip" LOGGER.info(f"Downloading archive using: url={url}") - urllib3.disable_warnings() # TODO: remove this when we fix the SSL warning local_file_name = os.path.join(tmpdir, url.split("/")[-1]) - with requests.get(url, verify=False, stream=True) as created_request: - created_request.raise_for_status() - with open(local_file_name, "wb") as file_downloaded: - file_downloaded.writelines(created_request.iter_content(chunk_size=8192)) + _download_file(url=url, local_file_name=local_file_name) LOGGER.info("Extract the downloaded archive.") if url.endswith(zip_file_extension): archive_file_object = zipfile.ZipFile(file=local_file_name)