apt_*: add more info message while updating apt cache (#83230)

Fixes: #77941

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
pull/83312/head
Abhijeet Kasurde 6 months ago committed by GitHub
parent c1d41ee44e
commit 3af9d0f189
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,3 @@
---
bugfixes:
- apt_* - add more info messages raised while updating apt cache (https://github.com/ansible/ansible/issues/77941).

@ -1394,16 +1394,25 @@ def main():
if not module.check_mode:
cache.update()
break
except apt.cache.FetchFailedException as e:
err = to_native(e)
except apt.cache.FetchFailedException as fetch_failed_exc:
err = fetch_failed_exc
module.warn(
f"Failed to update cache after {retry + 1} retries due "
f"to {to_native(fetch_failed_exc)}, retrying"
)
# Use exponential backoff plus a little bit of randomness
delay = 2 ** retry + randomize
if delay > update_cache_retry_max_delay:
delay = update_cache_retry_max_delay + randomize
time.sleep(delay)
module.warn(f"Sleeping for {int(round(delay))} seconds, before attempting to refresh the cache again")
else:
module.fail_json(msg='Failed to update apt cache: %s' % (err if err else 'unknown reason'))
msg = (
f"Failed to update apt cache after {update_cache_retries} retries: "
f"{err if err else 'unknown reason'}"
)
module.fail_json(msg=msg)
cache.open(progress=None)
mtimestamp, post_cache_update_time = get_updated_cache_time()

@ -738,29 +738,38 @@ def main():
if changed and not module.check_mode:
try:
err = ''
sourceslist.save()
if update_cache:
err = ''
update_cache_retries = module.params.get('update_cache_retries')
update_cache_retry_max_delay = module.params.get('update_cache_retry_max_delay')
randomize = random.randint(0, 1000) / 1000.0
cache = apt.Cache()
for retry in range(update_cache_retries):
try:
cache = apt.Cache()
cache.update()
break
except apt.cache.FetchFailedException as e:
err = to_native(e)
except apt.cache.FetchFailedException as fetch_failed_exc:
err = fetch_failed_exc
module.warn(
f"Failed to update cache after {retry + 1} due "
f"to {to_native(fetch_failed_exc)} retry, retrying"
)
# Use exponential backoff with a max fail count, plus a little bit of randomness
delay = 2 ** retry + randomize
if delay > update_cache_retry_max_delay:
delay = update_cache_retry_max_delay + randomize
time.sleep(delay)
module.warn(f"Sleeping for {int(round(delay))} seconds, before attempting to update the cache again")
else:
revert_sources_list(sources_before, sources_after, sourceslist_before)
module.fail_json(msg='Failed to update apt cache: %s' % (err if err else 'unknown reason'))
msg = (
f"Failed to update apt cache after {update_cache_retries} retries: "
f"{err if err else 'unknown reason'}"
)
module.fail_json(msg=msg)
except (OSError, IOError) as ex:
revert_sources_list(sources_before, sources_after, sourceslist_before)

@ -328,7 +328,7 @@
- name: verify logical error message
assert:
that:
- "'Failed to fetch' in apt_result['msg']"
- "'Failed to update apt cache' in apt_result['msg']"
- "'403' in apt_result['msg']"
- name: Clean up

Loading…
Cancel
Save