Fix loading namespaced doc_fragments from collections (#55249)

* Fix loading namespaced doc_fragments

The syntax for specifying a different fragment name was already
using '.' as a separator, so the code needed to be tweaked to
avoid choking on names like `testns.testcoll.fragname` and
`testns.testcoll.fragname.altvar`.

`get_plugin_class()` returns 'docfragment' for the fragment loader;
mangling `subdir` provides consistent alignment with the normal plugin
directory names and avoids needing special handling of plugin types
with 'module' in the name.

* Add changelog entry
This commit is contained in:
flowerysong 2019-05-02 21:15:58 -04:00 committed by ansibot
parent fcca1a124d
commit 2ef8b297ff
6 changed files with 39 additions and 9 deletions

View file

@ -50,14 +50,20 @@ def add_fragments(doc, filename, fragment_loader):
# Allow the module to specify a var other than DOCUMENTATION
# to pull the fragment from, using dot notation as a separator
for fragment_slug in fragments:
fallback_name = None
fragment_slug = fragment_slug.lower()
if '.' in fragment_slug:
fragment_name, fragment_var = fragment_slug.split('.', 1)
fallback_name = fragment_slug
fragment_name, fragment_var = fragment_slug.rsplit('.', 1)
fragment_var = fragment_var.upper()
else:
fragment_name, fragment_var = fragment_slug, 'DOCUMENTATION'
fragment_class = fragment_loader.get(fragment_name)
if fragment_class is None and fallback_name:
fragment_class = fragment_loader.get(fallback_name)
fragment_var = 'DOCUMENTATION'
if fragment_class is None:
raise AnsibleAssertionError('fragment_class is None')