ansible-galaxy - fix fallback for AH searches (#70957) (#70983)

(cherry picked from commit b1cb2553af)
pull/70851/head
Jordan Borean 4 years ago committed by GitHub
parent c37acc7740
commit 74d5391f73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- ansible-galaxy collection install - fix fallback mechanism if the AH server did not have the collection requested - https://github.com/ansible/ansible/issues/70940

@ -349,11 +349,17 @@ class CollectionRequirement:
# StrictVersion (x.y.z) and only support pre-releases if an explicit version was set (done above). # StrictVersion (x.y.z) and only support pre-releases if an explicit version was set (done above).
versions = [v for v in resp if StrictVersion.version_re.match(v)] versions = [v for v in resp if StrictVersion.version_re.match(v)]
except GalaxyError as err: except GalaxyError as err:
if err.http_code == 404: if err.http_code != 404:
display.vvv("Collection '%s' is not available from server %s %s" raise
% (collection, api.name, api.api_server))
continue versions = []
raise
# Automation Hub doesn't return a 404 but an empty version list so we check that to align both AH and
# Galaxy when the collection is not available on that server.
if not versions:
display.vvv("Collection '%s' is not available from server %s %s" % (collection, api.name,
api.api_server))
continue
display.vvv("Collection '%s' obtained from server %s %s" % (collection, api.name, api.api_server)) display.vvv("Collection '%s' obtained from server %s %s" % (collection, api.name, api.api_server))
break break

@ -153,3 +153,20 @@
server: '{{ fallaxy_galaxy_server }}' server: '{{ fallaxy_galaxy_server }}'
- name: automation_hub - name: automation_hub
server: '{{ fallaxy_ah_server }}' server: '{{ fallaxy_ah_server }}'
# fake.fake does not exist but we check the output to ensure it checked all 3
# servers defined in the config. We hardcode to -vvv as that's what level the
# message is shown
- name: test install fallback on server list
command: ansible-galaxy collection install fake.fake -vvv
ignore_errors: yes
environment:
ANSIBLE_CONFIG: '{{ galaxy_dir }}/ansible.cfg'
register: missing_fallback
- name: assert test install fallback on server list
assert:
that:
- missing_fallback.rc == 1
- '"Collection ''fake.fake'' is not available from server galaxy" in missing_fallback.stdout'
- '"Collection ''fake.fake'' is not available from server automation_hub" in missing_fallback.stdout'

Loading…
Cancel
Save