Skip to content
Snippets Groups Projects
Commit 8c385317 authored by Ben Morrice's avatar Ben Morrice
Browse files

Add retry logic to get_changelog function

parent 6374ab79
No related branches found
No related tags found
1 merge request!9Various improvements
Pipeline #6329850 failed
...@@ -82,17 +82,35 @@ def do_execute(cmd, tdir="/tmp", return_output=False, return_error=False): ...@@ -82,17 +82,35 @@ def do_execute(cmd, tdir="/tmp", return_output=False, return_error=False):
def get_changelog(token, checksum): def get_changelog(token, checksum):
"""get the changelog for a rpm, which requires downloading it""" """get the changelog for a rpm, which requires downloading it"""
url = f"https://api.access.redhat.com/management/v1/packages/{checksum}/download" # We don't usually retry stuff from api calls as the script runs
result = call_api(token, url, stream=True) # frequently, however - in this case a failure results in a blank
# changelog which is not very useful
attempts = 0
max_attempts = 3
rpm_downloaded = False
temp_file = generate_temp_file("checksum") temp_file = generate_temp_file("checksum")
# TODO: try and do this with dnf 'add_remote_rpms', although we would need to auth url = f"https://api.access.redhat.com/management/v1/packages/{checksum}/download"
with open(temp_file, "wb") as f: while attempts < max_attempts:
try: attempts += 1
for chunk in result.iter_content(chunk_size=1024): result = call_api(token, url, stream=True)
if chunk: if result.status_code == 200:
f.write(chunk) # TODO: try and do this with dnf 'add_remote_rpms', although we would need to auth
except: with open(temp_file, "wb") as f:
f.close() try:
for chunk in result.iter_content(chunk_size=1024):
if chunk:
f.write(chunk)
rpm_downloaded = True
except:
print(f"Saving changelog appeared to have failed. Retrying {attempts}/{max_attempts}", flush=True)
f.close()
if rpm_downloaded:
break
else:
print(f"API call failed, Retrying {attempts}/{max_attempts}", flush=True)
if not rpm_downloaded:
print(f"Changelog failed to download, exiting", flush=True)
sys.exit(1)
# TODO: maybe have some better logic instead of the head command # TODO: maybe have some better logic instead of the head command
changelog = do_execute(f"rpm -qp {temp_file} --changelog | head -20", return_output=True) changelog = do_execute(f"rpm -qp {temp_file} --changelog | head -20", return_output=True)
# Even though we are running through a container, let's clean up after ourselves # Even though we are running through a container, let's clean up after ourselves
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment