From 2b63fdd1b8dd8383a9b09b601d80623cd76ce579 Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Thu, 11 Aug 2022 10:53:23 -0700 Subject: [PATCH] ansible-test - Fix ansible-doc sanity test FQCN. (#78518) --- .../ansible-test-ansible-doc-sanity-fqcn.yml | 3 ++ .../ansible-test-sanity-ansible-doc/aliases | 4 +++ .../ns/col/plugins/lookup/a/b/lookup2.py | 28 +++++++++++++++ .../ns/col/plugins/lookup/lookup1.py | 28 +++++++++++++++ .../ns/col/plugins/modules/a/b/module2.py | 34 +++++++++++++++++++ .../ns/col/plugins/modules/module1.py | 34 +++++++++++++++++++ .../ansible-test-sanity-ansible-doc/runme.sh | 9 +++++ .../_internal/commands/sanity/ansible_doc.py | 9 ++--- 8 files changed, 145 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/ansible-test-ansible-doc-sanity-fqcn.yml create mode 100644 test/integration/targets/ansible-test-sanity-ansible-doc/aliases create mode 100644 test/integration/targets/ansible-test-sanity-ansible-doc/ansible_collections/ns/col/plugins/lookup/a/b/lookup2.py create mode 100644 test/integration/targets/ansible-test-sanity-ansible-doc/ansible_collections/ns/col/plugins/lookup/lookup1.py create mode 100644 test/integration/targets/ansible-test-sanity-ansible-doc/ansible_collections/ns/col/plugins/modules/a/b/module2.py create mode 100644 test/integration/targets/ansible-test-sanity-ansible-doc/ansible_collections/ns/col/plugins/modules/module1.py create mode 100755 test/integration/targets/ansible-test-sanity-ansible-doc/runme.sh diff --git a/changelogs/fragments/ansible-test-ansible-doc-sanity-fqcn.yml b/changelogs/fragments/ansible-test-ansible-doc-sanity-fqcn.yml new file mode 100644 index 00000000000..910e4f01001 --- /dev/null +++ b/changelogs/fragments/ansible-test-ansible-doc-sanity-fqcn.yml @@ -0,0 +1,3 @@ +bugfixes: + - ansible-test - ansible-doc sanity test - Correctly determine the fully-qualified collection name for plugins in + subdirectories, resolving https://github.com/ansible/ansible/issues/78490. diff --git a/test/integration/targets/ansible-test-sanity-ansible-doc/aliases b/test/integration/targets/ansible-test-sanity-ansible-doc/aliases new file mode 100644 index 00000000000..7741d444515 --- /dev/null +++ b/test/integration/targets/ansible-test-sanity-ansible-doc/aliases @@ -0,0 +1,4 @@ +shippable/posix/group3 # runs in the distro test containers +shippable/generic/group1 # runs in the default test container +context/controller +needs/target/collection diff --git a/test/integration/targets/ansible-test-sanity-ansible-doc/ansible_collections/ns/col/plugins/lookup/a/b/lookup2.py b/test/integration/targets/ansible-test-sanity-ansible-doc/ansible_collections/ns/col/plugins/lookup/a/b/lookup2.py new file mode 100644 index 00000000000..5cd2cf0f30f --- /dev/null +++ b/test/integration/targets/ansible-test-sanity-ansible-doc/ansible_collections/ns/col/plugins/lookup/a/b/lookup2.py @@ -0,0 +1,28 @@ +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +DOCUMENTATION = """ + name: lookup2 + author: Ansible Core Team + short_description: hello test lookup + description: + - Hello test lookup. + options: {} +""" + +EXAMPLES = """ +- minimal: +""" + +RETURN = """ +""" + +from ansible.plugins.lookup import LookupBase + + +class LookupModule(LookupBase): + + def run(self, terms, variables=None, **kwargs): + return [] diff --git a/test/integration/targets/ansible-test-sanity-ansible-doc/ansible_collections/ns/col/plugins/lookup/lookup1.py b/test/integration/targets/ansible-test-sanity-ansible-doc/ansible_collections/ns/col/plugins/lookup/lookup1.py new file mode 100644 index 00000000000..e274f19f1b2 --- /dev/null +++ b/test/integration/targets/ansible-test-sanity-ansible-doc/ansible_collections/ns/col/plugins/lookup/lookup1.py @@ -0,0 +1,28 @@ +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +DOCUMENTATION = """ + name: lookup1 + author: Ansible Core Team + short_description: hello test lookup + description: + - Hello test lookup. + options: {} +""" + +EXAMPLES = """ +- minimal: +""" + +RETURN = """ +""" + +from ansible.plugins.lookup import LookupBase + + +class LookupModule(LookupBase): + + def run(self, terms, variables=None, **kwargs): + return [] diff --git a/test/integration/targets/ansible-test-sanity-ansible-doc/ansible_collections/ns/col/plugins/modules/a/b/module2.py b/test/integration/targets/ansible-test-sanity-ansible-doc/ansible_collections/ns/col/plugins/modules/a/b/module2.py new file mode 100644 index 00000000000..6fafa193c3f --- /dev/null +++ b/test/integration/targets/ansible-test-sanity-ansible-doc/ansible_collections/ns/col/plugins/modules/a/b/module2.py @@ -0,0 +1,34 @@ +#!/usr/bin/python +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + +DOCUMENTATION = ''' +module: module2 +short_description: Hello test module +description: Hello test module. +options: {} +author: + - Ansible Core Team +''' + +EXAMPLES = ''' +- minimal: +''' + +RETURN = '''''' + +from ansible.module_utils.basic import AnsibleModule + + +def main(): + module = AnsibleModule( + argument_spec={}, + ) + + module.exit_json() + + +if __name__ == '__main__': + main() diff --git a/test/integration/targets/ansible-test-sanity-ansible-doc/ansible_collections/ns/col/plugins/modules/module1.py b/test/integration/targets/ansible-test-sanity-ansible-doc/ansible_collections/ns/col/plugins/modules/module1.py new file mode 100644 index 00000000000..8847f5b8558 --- /dev/null +++ b/test/integration/targets/ansible-test-sanity-ansible-doc/ansible_collections/ns/col/plugins/modules/module1.py @@ -0,0 +1,34 @@ +#!/usr/bin/python +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + +DOCUMENTATION = ''' +module: module1 +short_description: Hello test module +description: Hello test module. +options: {} +author: + - Ansible Core Team +''' + +EXAMPLES = ''' +- minimal: +''' + +RETURN = '''''' + +from ansible.module_utils.basic import AnsibleModule + + +def main(): + module = AnsibleModule( + argument_spec={}, + ) + + module.exit_json() + + +if __name__ == '__main__': + main() diff --git a/test/integration/targets/ansible-test-sanity-ansible-doc/runme.sh b/test/integration/targets/ansible-test-sanity-ansible-doc/runme.sh new file mode 100755 index 00000000000..ee1a8823101 --- /dev/null +++ b/test/integration/targets/ansible-test-sanity-ansible-doc/runme.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +set -eu + +source ../collection/setup.sh + +set -x + +ansible-test sanity --test ansible-doc --color "${@}" diff --git a/test/lib/ansible_test/_internal/commands/sanity/ansible_doc.py b/test/lib/ansible_test/_internal/commands/sanity/ansible_doc.py index 7c67939cc6c..6815f8847d7 100644 --- a/test/lib/ansible_test/_internal/commands/sanity/ansible_doc.py +++ b/test/lib/ansible_test/_internal/commands/sanity/ansible_doc.py @@ -64,7 +64,6 @@ class AnsibleDocTest(SanitySingleVersion): paths = [target.path for target in targets.include] doc_targets: dict[str, list[str]] = collections.defaultdict(list) - target_paths: dict[str, dict[str, str]] = collections.defaultdict(dict) remap_types = dict( modules='module', @@ -74,13 +73,15 @@ class AnsibleDocTest(SanitySingleVersion): plugin_type = remap_types.get(plugin_type, plugin_type) for plugin_file_path in [target.name for target in targets.include if is_subdir(target.path, plugin_path)]: - plugin_name = os.path.splitext(os.path.basename(plugin_file_path))[0] + plugin_parts = os.path.relpath(plugin_file_path, plugin_path).split(os.path.sep) + plugin_name = os.path.splitext(plugin_parts[-1])[0] if plugin_name.startswith('_'): plugin_name = plugin_name[1:] - doc_targets[plugin_type].append(data_context().content.prefix + plugin_name) - target_paths[plugin_type][data_context().content.prefix + plugin_name] = plugin_file_path + plugin_fqcn = data_context().content.prefix + '.'.join(plugin_parts[:-1] + [plugin_name]) + + doc_targets[plugin_type].append(plugin_fqcn) env = ansible_environment(args, color=False) error_messages: list[SanityMessage] = []