diff options
author | Jordan Borean <jborean93@gmail.com> | 2020-07-31 03:08:25 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-30 10:08:25 -0700 |
commit | a8217f1bd440f400e3b97d0a669a55a0676363d7 (patch) | |
tree | ae517fedae6e068cfa585be8679a09cc01ba4de4 | |
parent | 8389f4df0bff176829fde36c4ad6870e0fb8e5d5 (diff) | |
download | ansible-a8217f1bd440f400e3b97d0a669a55a0676363d7.tar.gz |
ansible-galaxy - fix fallback for AH searches (#70957) - 2.10 (#70980)
* ansible-galaxy - fix fallback for AH searches (#70957)
(cherry picked from commit b1cb2553af9e3811ce6f66e54c0f050977332eba)
* Fix tests after backport
-rw-r--r-- | changelogs/fragments/galaxy-collection-fallback.yml | 2 | ||||
-rw-r--r-- | lib/ansible/galaxy/collection.py | 16 | ||||
-rw-r--r-- | test/integration/targets/ansible-galaxy-collection/tasks/main.yml | 17 |
3 files changed, 30 insertions, 5 deletions
diff --git a/changelogs/fragments/galaxy-collection-fallback.yml b/changelogs/fragments/galaxy-collection-fallback.yml new file mode 100644 index 0000000000..dad92bd822 --- /dev/null +++ b/changelogs/fragments/galaxy-collection-fallback.yml @@ -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 diff --git a/lib/ansible/galaxy/collection.py b/lib/ansible/galaxy/collection.py index bdc287e592..21d76c1244 100644 --- a/lib/ansible/galaxy/collection.py +++ b/lib/ansible/galaxy/collection.py @@ -525,11 +525,17 @@ class CollectionRequirement: else: versions = api.get_collection_versions(namespace, name) except GalaxyError as err: - if err.http_code == 404: - display.vvv("Collection '%s' is not available from server %s %s" - % (collection, api.name, api.api_server)) - continue - raise + if err.http_code != 404: + raise + + versions = [] + + # 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)) break diff --git a/test/integration/targets/ansible-galaxy-collection/tasks/main.yml b/test/integration/targets/ansible-galaxy-collection/tasks/main.yml index bbbe372cc0..c4cc9edbb8 100644 --- a/test/integration/targets/ansible-galaxy-collection/tasks/main.yml +++ b/test/integration/targets/ansible-galaxy-collection/tasks/main.yml @@ -154,5 +154,22 @@ - name: automation_hub 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' + - name: run ansible-galaxy collection download tests include_tasks: download.yml |