summaryrefslogtreecommitdiff
path: root/lib/ansible/galaxy/collection/concrete_artifact_manager.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ansible/galaxy/collection/concrete_artifact_manager.py')
-rw-r--r--lib/ansible/galaxy/collection/concrete_artifact_manager.py51
1 files changed, 34 insertions, 17 deletions
diff --git a/lib/ansible/galaxy/collection/concrete_artifact_manager.py b/lib/ansible/galaxy/collection/concrete_artifact_manager.py
index 7c920b85dd..67d8e43f6a 100644
--- a/lib/ansible/galaxy/collection/concrete_artifact_manager.py
+++ b/lib/ansible/galaxy/collection/concrete_artifact_manager.py
@@ -27,9 +27,12 @@ if t.TYPE_CHECKING:
from ansible.errors import AnsibleError
from ansible.galaxy import get_collections_galaxy_meta_info
+from ansible.galaxy.api import should_retry_error
from ansible.galaxy.dependency_resolution.dataclasses import _GALAXY_YAML
from ansible.galaxy.user_agent import user_agent
from ansible.module_utils._text import to_bytes, to_native, to_text
+from ansible.module_utils.api import retry_with_delays_and_condition
+from ansible.module_utils.api import generate_jittered_backoff
from ansible.module_utils.common.process import get_bin_path
from ansible.module_utils.common._collections_compat import MutableMapping
from ansible.module_utils.common.yaml import yaml_load
@@ -160,17 +163,24 @@ class ConcreteArtifactsManager:
token=token,
) # type: bytes
except URLError as err:
- raise_from(
- AnsibleError(
- 'Failed to download collection tar '
- "from '{coll_src!s}': {download_err!s}".
- format(
- coll_src=to_native(collection.src),
- download_err=to_native(err),
- ),
+ raise AnsibleError(
+ 'Failed to download collection tar '
+ "from '{coll_src!s}': {download_err!s}".
+ format(
+ coll_src=to_native(collection.src),
+ download_err=to_native(err),
),
- err,
- )
+ ) from err
+ except Exception as err:
+ raise AnsibleError(
+ 'Failed to download collection tar '
+ "from '{coll_src!s}' due to the following unforeseen error: "
+ '{download_err!s}'.
+ format(
+ coll_src=to_native(collection.src),
+ download_err=to_native(err),
+ ),
+ ) from err
else:
display.vvv(
"Collection '{coll!s}' obtained from "
@@ -460,6 +470,10 @@ def _extract_collection_from_git(repo_url, coll_ver, b_path):
# FIXME: use random subdirs while preserving the file names
+@retry_with_delays_and_condition(
+ backoff_iterator=generate_jittered_backoff(retries=6, delay_base=2, delay_threshold=40),
+ should_retry_error=should_retry_error
+)
def _download_file(url, b_path, expected_hash, validate_certs, token=None, timeout=60):
# type: (str, bytes, t.Optional[str], bool, GalaxyToken, int) -> bytes
# ^ NOTE: used in download and verify_collections ^
@@ -478,13 +492,16 @@ def _download_file(url, b_path, expected_hash, validate_certs, token=None, timeo
display.display("Downloading %s to %s" % (url, to_text(b_tarball_dir)))
# NOTE: Galaxy redirects downloads to S3 which rejects the request
# NOTE: if an Authorization header is attached so don't redirect it
- resp = open_url(
- to_native(url, errors='surrogate_or_strict'),
- validate_certs=validate_certs,
- headers=None if token is None else token.headers(),
- unredirected_headers=['Authorization'], http_agent=user_agent(),
- timeout=timeout
- )
+ try:
+ resp = open_url(
+ to_native(url, errors='surrogate_or_strict'),
+ validate_certs=validate_certs,
+ headers=None if token is None else token.headers(),
+ unredirected_headers=['Authorization'], http_agent=user_agent(),
+ timeout=timeout
+ )
+ except Exception as err:
+ raise AnsibleError(to_native(err), orig_exc=err)
with open(b_file_path, 'wb') as download_file: # type: t.BinaryIO
actual_hash = _consume_file(resp, write_to=download_file)