Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

Retries for model downloads in samples tests (#34776)

Alina Kladieva0be52af1e2af
diff --git a/tests/samples_tests/smoke_tests/common/common_utils.py b/tests/samples_tests/smoke_tests/common/common_utils.py
index 34c1661f1c6..d1f1878e861 100644
--- a/tests/samples_tests/smoke_tests/common/common_utils.py
+++ b/tests/samples_tests/smoke_tests/common/common_utils.py
@@ -1,3 +1,6 @@
+# Copyright (C) 2018-2026 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+
"""
Copyright (C) 2018-2026 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
@@ -10,8 +13,47 @@
See the License for the specific language governing permissions and
limitations under the License.
"""
+import functools
import subprocess
import sys
+import time
+
+
+def retry(max_retries=3, exceptions=(Exception,), delay=None, exponential_backoff=False, backoff_multiplier=2, max_delay=None):
+ """
+ Retry decorator with optional exponential backoff.
+
+ Args:
+ max_retries: Maximum number of retry attempts
+ exceptions: Tuple of exception types to catch and retry on
+ delay: Base delay in seconds between retries
+ exponential_backoff: If True, use exponential backoff instead of fixed delay
+ backoff_multiplier: Multiplier for exponential backoff (default: 2)
+ max_delay: Maximum delay cap for exponential backoff
+ """
+ def retry_decorator(func):
+ @functools.wraps(func)
+ def wrapper(*args, **kwargs):
+ for attempt in range(max_retries):
+ try:
+ return func(*args, **kwargs)
+ except exceptions as e:
+ print(f"Attempt {attempt + 1} of {max_retries} failed: {e}")
+ if attempt < max_retries - 1 and delay is not None:
+ if exponential_backoff:
+ backoff_delay = delay * (backoff_multiplier ** attempt)
+ if max_delay is not None:
+ backoff_delay = min(backoff_delay, max_delay)
+ print(f"Waiting {backoff_delay:.2f} seconds before retry")
+ time.sleep(backoff_delay)
+ else:
+ print(f"Waiting {delay} seconds before retry")
+ time.sleep(delay)
+ else:
+ raise e
+ return wrapper
+ return retry_decorator
+
def shell(cmd, env=None, cwd=None, out_format="plain"):
"""
diff --git a/tests/samples_tests/smoke_tests/common/samples_common_test_class.py b/tests/samples_tests/smoke_tests/common/samples_common_test_class.py
index 744c26e664c..02ae336e049 100644
--- a/tests/samples_tests/smoke_tests/common/samples_common_test_class.py
+++ b/tests/samples_tests/smoke_tests/common/samples_common_test_class.py
@@ -1,3 +1,6 @@
+# Copyright (C) 2018-2026 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+
"""
Copyright (C) 2018-2026 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,7 +27,7 @@ import numpy as np
import zipfile
import logging as log
-from common.common_utils import shell
+from common.common_utils import shell, retry
from shutil import which
import openvino as ov
@@ -47,6 +50,11 @@ def get_cmd_output(*cmd):
return output
+@retry(max_retries=3, exceptions=(requests.RequestException,), delay=5, exponential_backoff=True)
+def _requests_get(url):
+ return requests.get(url)
+
+
def download(test_data_dir, file_path):
if file_path.exists():
return file_path
@@ -58,15 +66,15 @@ def download(test_data_dir, file_path):
with lock_path.open('bx'):
if not file_path.exists():
if test_data_dir / 'bvlcalexnet-12.onnx' == file_path:
- response = requests.get("https://media.githubusercontent.com/media/onnx/models/4c46cd00fbdb7cd30b6c1c17ab54f2e1f4f7b177/validated/vision/classification/alexnet/model/bvlcalexnet-12.onnx?download=true")
+ response = _requests_get("https://media.githubusercontent.com/media/onnx/models/4c46cd00fbdb7cd30b6c1c17ab54f2e1f4f7b177/validated/vision/classification/alexnet/model/bvlcalexnet-12.onnx?download=true")
with file_path.open('wb') as nfnet:
nfnet.write(response.content)
elif test_data_dir / 'efficientnet-lite4-11-qdq.onnx' == file_path:
- response = requests.get("https://media.githubusercontent.com/media/onnx/models/4c46cd00fbdb7cd30b6c1c17ab54f2e1f4f7b177/validated/vision/classification/efficientnet-lite4/model/efficientnet-lite4-11-qdq.onnx?download=true")
+ response = _requests_get("https://media.githubusercontent.com/media/onnx/models/4c46cd00fbdb7cd30b6c1c17ab54f2e1f4f7b177/validated/vision/classification/efficientnet-lite4/model/efficientnet-lite4-11-qdq.onnx?download=true")
with file_path.open('wb') as nfnet:
nfnet.write(response.content)
else:
- response = requests.get("https://storage.openvinotoolkit.org/repositories/openvino/ci_dependencies/test/2021.4/samples_smoke_tests_data_2021.4.zip")
+ response = _requests_get("https://storage.openvinotoolkit.org/repositories/openvino/ci_dependencies/test/2021.4/samples_smoke_tests_data_2021.4.zip")
with zipfile.ZipFile(io.BytesIO(response.content)) as zfile:
zfile.extractall(test_data_dir)
cv2.imwrite(str(test_data_dir / 'dog-224x224.bmp'), cv2.resize(cv2.imread(str(test_data_dir / 'samples_smoke_tests_data_2021.4/validation_set/227x227/dog.bmp')), (224, 224)))