Make ansible-galaxy collection verify error out on no MANIFEST.json

PR #73403

Co-Authored-By: Sviatoslav Sydorenko <webknjaz@redhat.com>
This commit is contained in:
Sloane Hertel 2021-02-01 03:55:21 -05:00 committed by GitHub
parent 6f4b4c345b
commit 728dafb6eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 2 deletions

View file

@ -108,7 +108,7 @@ from ansible.galaxy.dependency_resolution import (
build_collection_dependency_resolver,
)
from ansible.galaxy.dependency_resolution.dataclasses import (
Candidate, Requirement,
Candidate, Requirement, _is_installed_collection_dir,
)
from ansible.galaxy.dependency_resolution.errors import (
CollectionDependencyResolutionImpossible,
@ -606,6 +606,7 @@ def verify_collections(
# NOTE: Verify local collection exists before
# NOTE: downloading its source artifact from
# NOTE: a galaxy server.
default_err = 'Collection %s is not installed in any of the collection paths.' % collection.fqcn
for search_path in search_paths:
b_search_path = to_bytes(
os.path.join(
@ -616,13 +617,20 @@ def verify_collections(
)
if not os.path.isdir(b_search_path):
continue
if not _is_installed_collection_dir(b_search_path):
default_err = (
"Collection %s does not have a MANIFEST.json. "
"A MANIFEST.json is expected if the collection has been built "
"and installed via ansible-galaxy" % collection.fqcn
)
continue
local_collection = Candidate.from_dir_path(
b_search_path, artifacts_manager,
)
break
else:
raise AnsibleError(message='Collection %s is not installed in any of the collection paths.' % collection.fqcn)
raise AnsibleError(message=default_err)
remote_collection = Candidate(
collection.fqcn,

View file

@ -191,3 +191,33 @@
- assert:
that:
- "'Collection ansible_test.verify contains modified content in the following files:\nansible_test.verify\n MANIFEST.json' in verify.stdout"
- name: remove the artifact metadata to test verifying a collection without it
file:
path: "{{ item }}"
state: absent
loop:
- "{{ manifest_path }}"
- "{{ file_manifest_path }}"
- name: add some development metadata
copy:
content: |
namespace: 'ansible_test'
name: 'verify'
version: '2.0.0'
readme: 'README.md'
authors: ['Ansible']
dest: '{{ galaxy_dir }}/ansible_collections/ansible_test/verify/galaxy.yml'
- name: test we only verify collections containing a MANIFEST.json with the version on the server
command: ansible-galaxy collection verify ansible_test.verify:2.0.0
register: verify
environment:
ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}'
ignore_errors: yes
- assert:
that:
- verify.failed
- "'Collection ansible_test.verify does not have a MANIFEST.json' in verify.stderr"