Skip to content

Commit 87d9b49

Browse files
authored
Fix listing of colleciton plugins with symlinks (ansible#69305)
* Fix listing of colleciton plugins with symlinks
1 parent c13b040 commit 87d9b49

File tree

6 files changed

+45
-4
lines changed

6 files changed

+45
-4
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ credentials.yml
6464
results.xml
6565
coverage.xml
6666
/test/units/cover-html
67+
/test/integration/inventory
6768
/test/integration/targets/*/backup/
6869
/test/cache/*
6970
# Development
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bugfixes:
2+
- fix issue in which symlinked collection cannot be listed, though the docs/plugins can be loaded if referenced directly.

lib/ansible/utils/collection_loader.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -550,9 +550,9 @@ def get_collection_name_from_path(path):
550550
:param n_path: native-string path to evaluate for collection containment
551551
:return: collection name or None
552552
"""
553-
n_collection_paths = [to_native(os.path.realpath(to_bytes(p))) for p in AnsibleCollectionLoader().n_collection_paths]
553+
n_collection_paths = [to_native(os.path.abspath(to_bytes(p))) for p in AnsibleCollectionLoader().n_collection_paths]
554554

555-
b_path = os.path.realpath(to_bytes(path))
555+
b_path = os.path.abspath(to_bytes(path))
556556
n_path = to_native(b_path)
557557

558558
for coll_path in n_collection_paths:
@@ -575,7 +575,7 @@ def get_collection_name_from_path(path):
575575
return None
576576

577577
# ensure we're using the canonical real path, with the bogus __synthetic__ stripped off
578-
b_loaded_collection_path = os.path.dirname(os.path.realpath(to_bytes(loaded_collection_path)))
578+
b_loaded_collection_path = os.path.dirname(os.path.abspath(to_bytes(loaded_collection_path)))
579579

580580
# if the collection path prefix matches the path prefix we were passed, it's the same collection that's loaded
581581
if os.path.commonprefix([b_path, b_loaded_collection_path]) == b_loaded_collection_path:

test/integration/targets/collections/runme.sh

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,19 @@ export ANSIBLE_HOST_PATTERN_MISMATCH=error
99

1010

1111
# FUTURE: just use INVENTORY_PATH as-is once ansible-test sets the right dir
12-
ipath=../../$(basename "${INVENTORY_PATH}")
12+
ipath=../../$(basename "${INVENTORY_PATH:-../../inventory}")
1313
export INVENTORY_PATH="$ipath"
1414

1515
# test callback
1616
ANSIBLE_CALLBACK_WHITELIST=testns.testcoll.usercallback ansible localhost -m ping | grep "usercallback says ok"
1717

1818
# test documentation
1919
ansible-doc testns.testcoll.testmodule -vvv | grep -- "- normal_doc_frag"
20+
# same with symlink
21+
ln -s "${PWD}/testcoll2" ./collection_root_sys/ansible_collections/testns/testcoll2
22+
ansible-doc testns.testcoll2.testmodule2 -vvv | grep "Test module"
23+
# now test we can list with symlink
24+
ansible-doc -l -vvv| grep "testns.testcoll2.testmodule2"
2025

2126
# test adhoc default collection resolution (use unqualified collection module with playbook dir under its collection)
2227
echo "testing adhoc default collection support with explicit playbook dir"

test/integration/targets/collections/testcoll2/MANIFEST.json

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/python
2+
from __future__ import (absolute_import, division, print_function)
3+
__metaclass__ = type
4+
5+
ANSIBLE_METADATA = {'metadata_version': '1.1',
6+
'status': ['stableinterface'],
7+
'supported_by': 'core'}
8+
9+
DOCUMENTATION = '''
10+
---
11+
module: testmodule2
12+
short_description: Test module
13+
description:
14+
- Test module
15+
author:
16+
- Ansible Core Team
17+
'''
18+
19+
EXAMPLES = '''
20+
'''
21+
22+
RETURN = '''
23+
'''
24+
25+
import json
26+
27+
28+
def main():
29+
print(json.dumps(dict(changed=False, source='sys')))
30+
31+
32+
if __name__ == '__main__':
33+
main()

0 commit comments

Comments
 (0)