Skip to content

Commit 2dfb69c

Browse files
authored
Add retry on artifactory calls and update wrapper (#2844)
##### Short description: Partial backport of #2819 ##### More details: ##### What this PR does / why we need it: ##### Which issue(s) this PR fixes: ##### Special notes for reviewer: ##### jira-ticket: <!-- full-ticket-url needs to be provided. This would add a link to the pull request to the jira and close it when the pull request is merged If the task is not tracked by a Jira ticket, just write "NONE". -->
1 parent a1a08cf commit 2dfb69c

File tree

5 files changed

+24
-6
lines changed

5 files changed

+24
-6
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,5 @@ repos:
8080
"types-setuptools",
8181
"types-pexpect",
8282
"types-netaddr",
83+
"types-cachetools"
8384
]

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ dependencies = [
7979
"python-simple-logger>=2.0.13",
8080
"pytest-html>=4.1.1",
8181
"openshift-python-wrapper~=4.20.0",
82+
"cachetools>=6.2.1",
8283
]
8384

8485
[project.optional-dependencies]

tests/utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@
1919
from ocp_resources.virtual_machine import VirtualMachine
2020
from ocp_resources.virtual_machine_instance_migration import VirtualMachineInstanceMigration
2121
from pyhelper_utils.shell import run_ssh_commands
22-
from timeout_sampler import TimeoutExpiredError, TimeoutSampler
22+
from timeout_sampler import TimeoutExpiredError, TimeoutSampler, retry
2323

2424
from utilities.constants import (
2525
DISK_SERIAL,
2626
HCO_DEFAULT_CPU_MODEL_KEY,
2727
RHSM_SECRET_NAME,
28+
TIMEOUT_1MIN,
2829
TIMEOUT_1SEC,
2930
TIMEOUT_5SEC,
3031
TIMEOUT_10MIN,
@@ -467,13 +468,16 @@ def get_parameters_from_template(template, parameter_subset):
467468
}
468469

469470

471+
@retry(wait_timeout=TIMEOUT_1MIN, sleep=TIMEOUT_1SEC)
470472
def download_and_extract_tar(tarfile_url, dest_path):
471473
"""Download and Extract the tar file."""
472474
artifactory_header = get_artifactory_header()
473-
request = requests.get(tarfile_url, verify=False, headers=artifactory_header)
475+
request = requests.get(tarfile_url, verify=False, headers=artifactory_header, timeout=10)
474476
thetarfile = tarfile.open(fileobj=BytesIO(request.content), mode="r|xz")
475477
thetarfile.extractall(path=dest_path)
476478

479+
return True
480+
477481

478482
@contextmanager
479483
def update_hco_with_persistent_storage_config(hco_cr, storage_class):

utilities/storage.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import shlex
55
from contextlib import contextmanager
66

7+
import cachetools.func
78
import kubernetes
89
import requests
910
from kubernetes.dynamic import DynamicClient
@@ -23,7 +24,7 @@
2324
from ocp_resources.volume_snapshot_class import VolumeSnapshotClass
2425
from pyhelper_utils.shell import run_ssh_commands
2526
from pytest_testconfig import config as py_config
26-
from timeout_sampler import TimeoutExpiredError, TimeoutSampler
27+
from timeout_sampler import TimeoutExpiredError, TimeoutSampler, retry
2728

2829
import utilities.infra
2930
import utilities.virt as virt_util
@@ -296,6 +297,7 @@ def data_volume(
296297
yield dv
297298

298299

300+
@retry(wait_timeout=TIMEOUT_1MIN, sleep=TIMEOUT_1SEC)
299301
def get_downloaded_artifact(remote_name, local_name):
300302
"""
301303
Download image or artifact to local tmpdir path
@@ -317,6 +319,8 @@ def get_downloaded_artifact(remote_name, local_name):
317319
file_downloaded.write(chunk)
318320
try:
319321
assert os.path.isfile(local_name)
322+
return True
323+
320324
except FileNotFoundError as err:
321325
LOGGER.error(err)
322326
raise
@@ -1167,7 +1171,11 @@ def vm_snapshot(vm, name):
11671171
yield snapshot
11681172

11691173

1174+
@cachetools.func.ttl_cache(ttl=TIMEOUT_60MIN)
1175+
@retry(wait_timeout=TIMEOUT_1MIN, sleep=TIMEOUT_10SEC)
11701176
def validate_file_exists_in_url(url):
1171-
response = requests.head(url, headers=utilities.infra.get_artifactory_header(), verify=False)
1177+
response = requests.head(url, headers=utilities.infra.get_artifactory_header(), verify=False, timeout=10)
11721178
if response.status_code != 200:
11731179
raise UrlNotFoundError(url_request=response)
1180+
1181+
return True

uv.lock

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)