Skip to content

Commit 40044a8

Browse files
Add retry with timeout for virtctl download to handle transient SSL errors
Signed-off-by: Ahmad Hafe <ahafe@redhat.com> Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 93d8ab2 commit 40044a8

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

utilities/infra.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,24 @@ def get_all_console_links(console_cli_downloads_spec_links):
681681
return all_urls
682682

683683

684+
@retry(
685+
wait_timeout=TIMEOUT_2MIN,
686+
sleep=TIMEOUT_10SEC,
687+
exceptions_dict={
688+
requests.exceptions.SSLError: [],
689+
requests.exceptions.ConnectionError: [],
690+
requests.exceptions.Timeout: [],
691+
},
692+
)
693+
def _download_file(url: str, local_file_name: str) -> str:
694+
urllib3.disable_warnings() # TODO: remove this when we fix the SSL warning
695+
response = requests.get(url, verify=False, timeout=TIMEOUT_30SEC)
696+
response.raise_for_status()
697+
with open(local_file_name, "wb") as file_downloaded:
698+
file_downloaded.write(response.content)
699+
return local_file_name
700+
701+
684702
def download_and_extract_file_from_cluster(tmpdir, url):
685703
"""
686704
Download and extract archive file from the cluster
@@ -694,12 +712,8 @@ def download_and_extract_file_from_cluster(tmpdir, url):
694712
"""
695713
zip_file_extension = ".zip"
696714
LOGGER.info(f"Downloading archive using: url={url}")
697-
urllib3.disable_warnings() # TODO: remove this when we fix the SSL warning
698715
local_file_name = os.path.join(tmpdir, url.split("/")[-1])
699-
with requests.get(url, verify=False, stream=True) as created_request:
700-
created_request.raise_for_status()
701-
with open(local_file_name, "wb") as file_downloaded:
702-
file_downloaded.writelines(created_request.iter_content(chunk_size=8192))
716+
_download_file(url=url, local_file_name=local_file_name)
703717
LOGGER.info("Extract the downloaded archive.")
704718
if url.endswith(zip_file_extension):
705719
archive_file_object = zipfile.ZipFile(file=local_file_name)

0 commit comments

Comments
 (0)