diff options
author | Jordan Borean <jborean93@gmail.com> | 2021-01-21 06:19:29 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-20 21:19:29 +0100 |
commit | bc60d8ccda7a5a5bf0776c83f76c52663378b59c (patch) | |
tree | f27251c80258fea081947fa06cfb1fb8f967d29b /lib/ansible/galaxy/api.py | |
parent | 51e00c5e86ff026bcefff7d3de04824be0fe2cc3 (diff) | |
download | ansible-bc60d8ccda7a5a5bf0776c83f76c52663378b59c.tar.gz |
Galaxy - make versions list consistent across versions (#72932)
* Galaxy - make versions list consistent across versions
* Fix up unit tests
Diffstat (limited to 'lib/ansible/galaxy/api.py')
-rw-r--r-- | lib/ansible/galaxy/api.py | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/lib/ansible/galaxy/api.py b/lib/ansible/galaxy/api.py index 6167206902..2ed4930b25 100644 --- a/lib/ansible/galaxy/api.py +++ b/lib/ansible/galaxy/api.py @@ -751,9 +751,15 @@ class GalaxyAPI: server_cache = self._cache.setdefault(get_cache_id(versions_url), {}) modified_cache = server_cache.setdefault('modified', {}) - modified_date = self.get_collection_metadata(namespace, name).modified_str - cached_modified_date = modified_cache.get('%s.%s' % (namespace, name), None) + try: + modified_date = self.get_collection_metadata(namespace, name).modified_str + except GalaxyError as err: + if err.http_code != 404: + raise + # No collection found, return an empty list to keep things consistent with the various APIs + return [] + cached_modified_date = modified_cache.get('%s.%s' % (namespace, name), None) if cached_modified_date != modified_date: modified_cache['%s.%s' % (namespace, name)] = modified_date if versions_url_info.path in server_cache: @@ -763,7 +769,14 @@ class GalaxyAPI: error_context_msg = 'Error when getting available collection versions for %s.%s from %s (%s)' \ % (namespace, name, self.name, self.api_server) - data = self._call_galaxy(versions_url, error_context_msg=error_context_msg, cache=True) + + try: + data = self._call_galaxy(versions_url, error_context_msg=error_context_msg, cache=True) + except GalaxyError as err: + if err.http_code != 404: + raise + # v3 doesn't raise a 404 so we need to mimick the empty response from APIs that do. + return [] if 'data' in data: # v3 automation-hub is the only known API that uses `data` |