From f01de15d25e81b0a2709e6a94ed1ec72d95b8f6f Mon Sep 17 00:00:00 2001 From: Sam Doran Date: Tue, 19 May 2020 11:31:49 -0400 Subject: [PATCH] ansible-galaxy - remove warning during collection install (#69541) * ansible-galaxy - remove warning during collection install If existing collections do not contain a MANIFEST.json, which is common for collections under development that were not installed from Ansible Galaxy, fall back to inspecting galaxy.yml rather than displaying a warning. A warning will still be displayed in neither a MANIFEST.json nor galaxy.yml are present. * Update unit tests --- ...sible-galaxy-install-manifest-warning.yaml | 4 +++ lib/ansible/galaxy/collection.py | 2 +- test/units/galaxy/test_collection_install.py | 34 +++++++++++++++---- 3 files changed, 33 insertions(+), 7 deletions(-) create mode 100644 changelogs/fragments/ansible-galaxy-install-manifest-warning.yaml diff --git a/changelogs/fragments/ansible-galaxy-install-manifest-warning.yaml b/changelogs/fragments/ansible-galaxy-install-manifest-warning.yaml new file mode 100644 index 00000000000..aee3c4a5592 --- /dev/null +++ b/changelogs/fragments/ansible-galaxy-install-manifest-warning.yaml @@ -0,0 +1,4 @@ +bugfixes: + - > + ansible-galaxy - hide warning during collection installation if other installed collections + do not contain a ``MANIFEST.json`` (https://github.com/ansible/ansible/issues/67490) diff --git a/lib/ansible/galaxy/collection.py b/lib/ansible/galaxy/collection.py index 7ca4da6ec27..ab86ee59c23 100644 --- a/lib/ansible/galaxy/collection.py +++ b/lib/ansible/galaxy/collection.py @@ -605,7 +605,7 @@ def install_collections(collections, output_path, apis, validate_certs, ignore_e :param force: Re-install a collection if it has already been installed. :param force_deps: Re-install a collection as well as its dependencies if they have already been installed. """ - existing_collections = find_existing_collections(output_path) + existing_collections = find_existing_collections(output_path, fallback_metadata=True) with _tempdir() as b_temp_path: display.display("Process install dependency map") diff --git a/test/units/galaxy/test_collection_install.py b/test/units/galaxy/test_collection_install.py index 8c821d7423a..a1526ad0ea5 100644 --- a/test/units/galaxy/test_collection_install.py +++ b/test/units/galaxy/test_collection_install.py @@ -746,12 +746,34 @@ def test_install_collections_existing_without_force(collection_artifact, monkeyp # Filter out the progress cursor display calls. display_msgs = [m[1][0] for m in mock_display.mock_calls if 'newline' not in m[2] and len(m[1]) == 1] - assert len(display_msgs) == 4 - # Msg1 is the warning about not MANIFEST.json, cannot really check message as it has line breaks which varies based - # on the path size - assert display_msgs[1] == "Process install dependency map" - assert display_msgs[2] == "Starting collection install process" - assert display_msgs[3] == "Skipping 'ansible_namespace.collection' as it is already installed" + assert len(display_msgs) == 3 + + assert display_msgs[0] == "Process install dependency map" + assert display_msgs[1] == "Starting collection install process" + assert display_msgs[2] == "Skipping 'ansible_namespace.collection' as it is already installed" + + for msg in display_msgs: + assert 'WARNING' not in msg + + +def test_install_missing_metadata_warning(collection_artifact, monkeypatch): + collection_path, collection_tar = collection_artifact + temp_path = os.path.split(collection_tar)[0] + + mock_display = MagicMock() + monkeypatch.setattr(Display, 'display', mock_display) + + for file in [b'MANIFEST.json', b'galaxy.yml']: + b_path = os.path.join(collection_path, file) + if os.path.isfile(b_path): + os.unlink(b_path) + + collection.install_collections([(to_text(collection_tar), '*', None,)], to_text(temp_path), + [u'https://galaxy.ansible.com'], True, False, False, False, False) + + display_msgs = [m[1][0] for m in mock_display.mock_calls if 'newline' not in m[2] and len(m[1]) == 1] + + assert 'WARNING' in display_msgs[0] # Makes sure we don't get stuck in some recursive loop