Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better error for "ansible-galaxy collection verify" if there's no MANIFEST.json #67498

Merged
merged 5 commits into from
May 14, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/ansible/galaxy/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,10 @@ def verify_collections(collections, search_paths, apis, validate_certs, ignore_e
break
if local_collection is None:
raise AnsibleError(message='Collection %s is not installed in any of the collection paths.' % collection_name)
if local_collection.latest_version == '*':
s-hertel marked this conversation as resolved.
Show resolved Hide resolved
msg = 'Collection %s does not appear to have the MANIFEST.json. ' % collection_name
msg += 'A MANIFEST.json is expected if the collection has been built and installed via ansible-galaxy.'
raise AnsibleError(message=msg)
s-hertel marked this conversation as resolved.
Show resolved Hide resolved

# Download collection on a galaxy server for comparison
try:
Expand Down
27 changes: 24 additions & 3 deletions test/units/galaxy/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,25 @@ def test_verify_identical(monkeypatch, mock_collection, manifest_info, files_man
assert mock_debug.call_args_list[-1][0][0] == success_msg


@patch.object(os.path, 'isdir', return_value=True)
def test_verify_collections_no_version(mock_isdir, mock_collection, monkeypatch):
namespace = 'ansible_namespace'
name = 'collection'
version = '*' # Occurs if MANIFEST.json does not exist

local_collection = mock_collection(namespace=namespace, name=name, version=version)
monkeypatch.setattr(collection.CollectionRequirement, 'from_path', MagicMock(return_value=local_collection))

collections = [('%s.%s' % (namespace, name), version, None)]

with pytest.raises(AnsibleError) as err:
collection.verify_collections(collections, './', local_collection.api, False, False)

err_msg = 'Collection %s.%s does not appear to have the MANIFEST.json. ' % (namespace, name)
err_msg += 'A MANIFEST.json is expected if the collection has been built and installed via ansible-galaxy.'
assert err.value.message == err_msg


@patch.object(collection.CollectionRequirement, 'verify')
def test_verify_collections_not_installed(mock_verify, mock_collection, monkeypatch):
namespace = 'ansible_namespace'
Expand Down Expand Up @@ -1186,11 +1205,13 @@ def test_verify_collections_not_installed_ignore_errors(mock_verify, mock_collec

@patch.object(os.path, 'isdir', return_value=True)
@patch.object(collection.CollectionRequirement, 'verify')
def test_verify_collections_no_remote(mock_verify, mock_isdir, mock_collection):
def test_verify_collections_no_remote(mock_verify, mock_isdir, mock_collection, monkeypatch):
namespace = 'ansible_namespace'
name = 'collection'
version = '1.0.0'

monkeypatch.setattr(collection.CollectionRequirement, 'from_path', MagicMock(return_value=mock_collection()))

collections = [('%s.%s' % (namespace, name), version, None)]
search_path = './'
validate_certs = False
Expand All @@ -1205,12 +1226,12 @@ def test_verify_collections_no_remote(mock_verify, mock_isdir, mock_collection):

@patch.object(os.path, 'isdir', return_value=True)
@patch.object(collection.CollectionRequirement, 'verify')
def test_verify_collections_no_remote_ignore_errors(mock_verify, mock_isdir, mock_collection):
def test_verify_collections_no_remote_ignore_errors(mock_verify, mock_isdir, mock_collection, monkeypatch):
namespace = 'ansible_namespace'
name = 'collection'
version = '1.0.0'

local_collection = mock_collection(local_installed=False)
monkeypatch.setattr(collection.CollectionRequirement, 'from_path', MagicMock(return_value=mock_collection()))

collections = [('%s.%s' % (namespace, name), version, None)]
search_path = './'
Expand Down