Galaxy trailing slash (#82732)

* fix: ensure path argument doesn't have a backslash

* feat: add changelog

* Update lib/ansible/cli/__init__.py

Co-authored-by: Matt Clay <matt@mystile.com>

* Simplify logic and add tests

---------

Co-authored-by: dorkamotorka <teo.podobnik1234@gmail.com>
Co-authored-by: Teodor Janez Podobnik <48418580+dorkamotorka@users.noreply.github.com>
Co-authored-by: Matt Clay <matt@mystile.com>
pull/82735/head
Jordan Borean 3 months ago committed by GitHub
parent a1edb61ce7
commit 1b209d742e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,2 @@
bugfixes:
- ansible-galaxy - ensure path to ansible collection when installing or downloading doesn't have a backslash (https://github.com/ansible/ansible/pull/79705).

@ -425,6 +425,10 @@ class CLI(ABC):
skip_tags.add(tag.strip())
options.skip_tags = list(skip_tags)
# Make sure path argument doesn't have a backslash
if hasattr(options, 'action') and options.action in ['install', 'download'] and hasattr(options, 'args'):
options.args = [path.rstrip("/") for path in options.args]
# process inventory options except for CLIs that require their own processing
if hasattr(options, 'inventory') and not self.SKIP_INVENTORY_DEFAULTS:

@ -170,6 +170,33 @@
- '"Downloading collection ''ansible_test.my_collection:1.0.0'' to" in download_collection.stdout'
- download_collection_actual.stat.exists
- block:
- name: create skeleton collection for trailing slash test
command: ansible-galaxy collection init trailing_dir.name --init-path "{{ galaxy_dir }}"
- name: install collection with directory source and trailing slash - {{ test_id }}
command: ansible-galaxy collection download '{{ galaxy_dir }}/trailing_dir/name/' {{ galaxy_verbosity }}
args:
chdir: '{{ galaxy_dir }}/download'
register: download_dir_slash
- name: get result of install collections with with trailing slash - {{ test_id }}
stat:
path: '{{ galaxy_dir }}/download/collections/trailing_dir-name-1.0.0.tar.gz'
register: download_dir_slash_actual
- name: assert install collections with with trailing slash - {{ test_id }}
assert:
that:
- '"Downloading collection ''trailing_dir.name:1.0.0'' to" in download_dir_slash.stdout'
- download_dir_slash_actual.stat.exists
always:
- name: remove trailing dir skeleton
file:
path: '{{ galaxy_dir }}/trailing_dir'
state: absent
- name: remove test download dir
file:
path: '{{ galaxy_dir }}/download'

@ -1141,6 +1141,33 @@
- (install_concrete_pre_actual.results[0].content | b64decode | from_json).collection_info.version == '1.1.0-beta.1'
- (install_concrete_pre_actual.results[1].content | b64decode | from_json).collection_info.version == '1.0.0'
- block:
- name: create skeleton collection for trailing slash test
command: ansible-galaxy collection init trailing_dir.name --init-path "{{ galaxy_dir }}/scratch"
- name: install collection with directory source and trailing slash - {{ test_id }}
command: ansible-galaxy collection install '{{ galaxy_dir }}/scratch/trailing_dir/name/' {{ galaxy_verbosity }}
environment:
ANSIBLE_COLLECTIONS_PATHS: '{{ galaxy_dir }}/ansible_collections'
register: install_dir_slash
- name: get result of install collections with with trailing slash - {{ test_id }}
slurp:
path: '{{ galaxy_dir }}/ansible_collections/trailing_dir/name/MANIFEST.json'
register: install_dir_slash_actual
- name: assert install collections with with trailing slash - {{ test_id }}
assert:
that:
- '"Installing ''trailing_dir.name:1.0.0'' to" in install_dir_slash.stdout'
- (install_dir_slash_actual.content | b64decode | from_json).collection_info.version == '1.0.0'
always:
- name: remove trailing dir skeleton
file:
path: '{{ galaxy_dir }}/scratch/trailing_dir'
state: absent
- name: remove collection dir after round of testing - {{ test_id }}
file:
path: '{{ galaxy_dir }}/ansible_collections'

Loading…
Cancel
Save