Fix listing of colleciton plugins with symlinks (#69305)

* Fix listing of colleciton plugins with symlinks
pull/69437/head
Brian Coca 5 years ago committed by GitHub
parent c13b040e67
commit 87d9b49de2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

1
.gitignore vendored

@ -64,6 +64,7 @@ credentials.yml
results.xml results.xml
coverage.xml coverage.xml
/test/units/cover-html /test/units/cover-html
/test/integration/inventory
/test/integration/targets/*/backup/ /test/integration/targets/*/backup/
/test/cache/* /test/cache/*
# Development # Development

@ -0,0 +1,2 @@
bugfixes:
- fix issue in which symlinked collection cannot be listed, though the docs/plugins can be loaded if referenced directly.

@ -550,9 +550,9 @@ def get_collection_name_from_path(path):
:param n_path: native-string path to evaluate for collection containment :param n_path: native-string path to evaluate for collection containment
:return: collection name or None :return: collection name or None
""" """
n_collection_paths = [to_native(os.path.realpath(to_bytes(p))) for p in AnsibleCollectionLoader().n_collection_paths] n_collection_paths = [to_native(os.path.abspath(to_bytes(p))) for p in AnsibleCollectionLoader().n_collection_paths]
b_path = os.path.realpath(to_bytes(path)) b_path = os.path.abspath(to_bytes(path))
n_path = to_native(b_path) n_path = to_native(b_path)
for coll_path in n_collection_paths: for coll_path in n_collection_paths:
@ -575,7 +575,7 @@ def get_collection_name_from_path(path):
return None return None
# ensure we're using the canonical real path, with the bogus __synthetic__ stripped off # ensure we're using the canonical real path, with the bogus __synthetic__ stripped off
b_loaded_collection_path = os.path.dirname(os.path.realpath(to_bytes(loaded_collection_path))) b_loaded_collection_path = os.path.dirname(os.path.abspath(to_bytes(loaded_collection_path)))
# if the collection path prefix matches the path prefix we were passed, it's the same collection that's loaded # if the collection path prefix matches the path prefix we were passed, it's the same collection that's loaded
if os.path.commonprefix([b_path, b_loaded_collection_path]) == b_loaded_collection_path: if os.path.commonprefix([b_path, b_loaded_collection_path]) == b_loaded_collection_path:

@ -9,7 +9,7 @@ export ANSIBLE_HOST_PATTERN_MISMATCH=error
# FUTURE: just use INVENTORY_PATH as-is once ansible-test sets the right dir # FUTURE: just use INVENTORY_PATH as-is once ansible-test sets the right dir
ipath=../../$(basename "${INVENTORY_PATH}") ipath=../../$(basename "${INVENTORY_PATH:-../../inventory}")
export INVENTORY_PATH="$ipath" export INVENTORY_PATH="$ipath"
# test callback # test callback
@ -17,6 +17,11 @@ ANSIBLE_CALLBACK_WHITELIST=testns.testcoll.usercallback ansible localhost -m pin
# test documentation # test documentation
ansible-doc testns.testcoll.testmodule -vvv | grep -- "- normal_doc_frag" ansible-doc testns.testcoll.testmodule -vvv | grep -- "- normal_doc_frag"
# same with symlink
ln -s "${PWD}/testcoll2" ./collection_root_sys/ansible_collections/testns/testcoll2
ansible-doc testns.testcoll2.testmodule2 -vvv | grep "Test module"
# now test we can list with symlink
ansible-doc -l -vvv| grep "testns.testcoll2.testmodule2"
# test adhoc default collection resolution (use unqualified collection module with playbook dir under its collection) # test adhoc default collection resolution (use unqualified collection module with playbook dir under its collection)
echo "testing adhoc default collection support with explicit playbook dir" echo "testing adhoc default collection support with explicit playbook dir"

@ -0,0 +1,33 @@
#!/usr/bin/python
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['stableinterface'],
'supported_by': 'core'}
DOCUMENTATION = '''
---
module: testmodule2
short_description: Test module
description:
- Test module
author:
- Ansible Core Team
'''
EXAMPLES = '''
'''
RETURN = '''
'''
import json
def main():
print(json.dumps(dict(changed=False, source='sys')))
if __name__ == '__main__':
main()
Loading…
Cancel
Save