mirror of https://github.com/ansible/ansible.git
ansible-galaxy - validate version for directories and collections in git repos (#76579)
* Ensure the version is valid for directories and collections in git repos before installing Fix the error message for invalid semantic versions * Make requested changes * Add a test case for unhandled ValueError exception * Add changelog * Update lib/ansible/galaxy/collection/galaxy_api_proxy.py Co-authored-by: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua> * Reword error message Include link to learn how to compose a semver version * Move version validation into the caller, find_matches * Add tests for more invalid version types * Remove unused import Fix raising unexpected error * Update lib/ansible/galaxy/collection/__init__.py Co-authored-by: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua> * Update lib/ansible/galaxy/dependency_resolution/providers.py Co-authored-by: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua> * Update lib/ansible/galaxy/dependency_resolution/providers.py Co-authored-by: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua> Co-authored-by: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua>pull/76671/head
parent
6e57c8c084
commit
15ace5a854
@ -0,0 +1,2 @@
|
||||
bugfixes:
|
||||
- ansible-galaxy - installing/downloading collections with invalid versions in git repositories and directories now gives a formatted error message (https://github.com/ansible/ansible/issues/76425, https://github.com/ansible/ansible/issues/75404).
|
@ -0,0 +1,47 @@
|
||||
- name: Initialize a git repo
|
||||
command: 'git init {{ test_error_repo_path }}'
|
||||
|
||||
- stat:
|
||||
path: "{{ test_error_repo_path }}"
|
||||
|
||||
- name: Add a collection to the repository
|
||||
command: 'ansible-galaxy collection init {{ item }}'
|
||||
args:
|
||||
chdir: '{{ scm_path }}'
|
||||
loop:
|
||||
- error_test.float_version_collection
|
||||
- error_test.not_semantic_version_collection
|
||||
- error_test.list_version_collection
|
||||
- error_test.dict_version_collection
|
||||
|
||||
- name: Add an invalid float version to a collection
|
||||
lineinfile:
|
||||
path: '{{ test_error_repo_path }}/float_version_collection/galaxy.yml'
|
||||
regexp: '^version'
|
||||
line: "version: 1.0" # Version is a float, not a string as expected
|
||||
|
||||
- name: Add an invalid non-semantic string version a collection
|
||||
lineinfile:
|
||||
path: '{{ test_error_repo_path }}/not_semantic_version_collection/galaxy.yml'
|
||||
regexp: '^version'
|
||||
line: "version: '1.0'" # Version is a string, but not a semantic version as expected
|
||||
|
||||
- name: Add an invalid list version to a collection
|
||||
lineinfile:
|
||||
path: '{{ test_error_repo_path }}/list_version_collection/galaxy.yml'
|
||||
regexp: '^version'
|
||||
line: "version: ['1.0.0']" # Version is a list, not a string as expected
|
||||
|
||||
- name: Add an invalid version to a collection
|
||||
lineinfile:
|
||||
path: '{{ test_error_repo_path }}/dict_version_collection/galaxy.yml'
|
||||
regexp: '^version'
|
||||
line: "version: {'broken': 'version'}" # Version is a dict, not a string as expected
|
||||
|
||||
- name: Commit the changes
|
||||
command: '{{ item }}'
|
||||
args:
|
||||
chdir: '{{ test_error_repo_path }}'
|
||||
loop:
|
||||
- git add ./
|
||||
- git commit -m 'add collections'
|
@ -0,0 +1,58 @@
|
||||
- block:
|
||||
- name: test installing a collection with an invalid float version value
|
||||
command: 'ansible-galaxy collection install git+file://{{ test_error_repo_path }}/.git#float_version_collection -vvvvvv'
|
||||
ignore_errors: yes
|
||||
register: invalid_version_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- invalid_version_result is failed
|
||||
- msg in invalid_version_result.stderr
|
||||
vars:
|
||||
req: error_test.float_version_collection:1.0
|
||||
ver: "1.0 (<class 'float'>)"
|
||||
msg: "Invalid version found for the collection '{{ req }}': {{ ver }}. A SemVer-compliant version or '*' is required."
|
||||
|
||||
- name: test installing a collection with an invalid non-SemVer string version value
|
||||
command: 'ansible-galaxy collection install git+file://{{ test_error_repo_path }}/.git#not_semantic_version_collection -vvvvvv'
|
||||
ignore_errors: yes
|
||||
register: invalid_version_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- invalid_version_result is failed
|
||||
- msg in invalid_version_result.stderr
|
||||
vars:
|
||||
req: error_test.not_semantic_version_collection:1.0
|
||||
ver: "1.0 (<class 'str'>)"
|
||||
msg: "Invalid version found for the collection '{{ req }}': {{ ver }}. A SemVer-compliant version or '*' is required."
|
||||
|
||||
- name: test installing a collection with an invalid list version value
|
||||
command: 'ansible-galaxy collection install git+file://{{ test_error_repo_path }}/.git#list_version_collection -vvvvvv'
|
||||
ignore_errors: yes
|
||||
register: invalid_version_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- invalid_version_result is failed
|
||||
- msg in invalid_version_result.stderr
|
||||
vars:
|
||||
req: "error_test.list_version_collection:['1.0.0']"
|
||||
msg: "Invalid version found for the collection '{{ req }}'. A SemVer-compliant version or '*' is required."
|
||||
|
||||
- name: test installing a collection with an invalid dict version value
|
||||
command: 'ansible-galaxy collection install git+file://{{ test_error_repo_path }}/.git#dict_version_collection -vvvvvv'
|
||||
ignore_errors: yes
|
||||
register: invalid_version_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- invalid_version_result is failed
|
||||
- msg in invalid_version_result.stderr
|
||||
vars:
|
||||
req: "error_test.dict_version_collection:{'broken': 'version'}"
|
||||
msg: "Invalid version found for the collection '{{ req }}'. A SemVer-compliant version or '*' is required."
|
||||
|
||||
always:
|
||||
- include_tasks: ./empty_installed_collections.yml
|
||||
when: cleanup
|
Loading…
Reference in New Issue