Support test and filter plugins in ansible-doc sanity test (#77737)

* Support test and filter plugins in ansible-doc sanity test.

* Move integration target non-filter file check_pylint.py from filter/ to plugin_utils/.
pull/77725/head
Felix Fontein 2 years ago committed by GitHub
parent 1a47a21b65
commit 1852f9fab4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
minor_changes:
- "ansible-test sanity --test ansible-doc - now also lists documentation for test and filter plugins that are documented (https://github.com/ansible/ansible/pull/77737)."

@ -126,9 +126,13 @@ TARGET_SANITY_ROOT = os.path.join(ANSIBLE_TEST_TARGET_ROOT, 'sanity')
# NOTE: must match ansible.constants.DOCUMENTABLE_PLUGINS, but with 'module' replaced by 'modules'!
DOCUMENTABLE_PLUGINS = (
'become', 'cache', 'callback', 'cliconf', 'connection', 'httpapi', 'inventory', 'lookup', 'netconf', 'modules', 'shell', 'strategy', 'vars'
'become', 'cache', 'callback', 'cliconf', 'connection', 'filter', 'httpapi', 'inventory',
'lookup', 'netconf', 'modules', 'shell', 'strategy', 'test', 'vars',
)
# Plugin types that can have multiple plugins per file, and where filenames not always correspond to plugin names
MULTI_FILE_PLUGINS = ('filter', 'test', )
created_venvs: list[str] = []

@ -2,11 +2,13 @@
from __future__ import annotations
import collections
import json
import os
import re
from . import (
DOCUMENTABLE_PLUGINS,
MULTI_FILE_PLUGINS,
SanitySingleVersion,
SanityFailure,
SanitySuccess,
@ -84,6 +86,41 @@ class AnsibleDocTest(SanitySingleVersion):
doc_targets[plugin_type].append(plugin_fqcn)
env = ansible_environment(args, color=False)
for doc_type in MULTI_FILE_PLUGINS:
if doc_targets.get(doc_type):
# List plugins
cmd = ['ansible-doc', '-l', '--json', '-t', doc_type]
prefix = data_context().content.prefix if data_context().content.collection else 'ansible.builtin.'
cmd.append(prefix[:-1])
try:
stdout, stderr = intercept_python(args, python, cmd, env, capture=True)
status = 0
except SubprocessError as ex:
stdout = ex.stdout
stderr = ex.stderr
status = ex.status
if status:
summary = '%s' % SubprocessError(cmd=cmd, status=status, stderr=stderr)
return SanityFailure(self.name, summary=summary)
if stdout:
display.info(stdout.strip(), verbosity=3)
if stderr:
summary = 'Output on stderr from ansible-doc is considered an error.\n\n%s' % SubprocessError(cmd, stderr=stderr)
return SanityFailure(self.name, summary=summary)
plugin_list_json = json.loads(stdout)
doc_targets[doc_type] = []
for plugin_name, plugin_value in sorted(plugin_list_json.items()):
if plugin_value != 'UNDOCUMENTED':
doc_targets[doc_type].append(plugin_name)
if not doc_targets[doc_type]:
del doc_targets[doc_type]
error_messages: list[SanityMessage] = []
for doc_type in sorted(doc_targets):

@ -8,6 +8,7 @@ import typing as t
from . import (
DOCUMENTABLE_PLUGINS,
MULTI_FILE_PLUGINS,
SanitySingleVersion,
SanityMessage,
SanityFailure,
@ -110,6 +111,10 @@ class ValidateModulesTest(SanitySingleVersion):
for target in targets.include:
target_per_type[self.get_plugin_type(target)].append(target)
# Remove plugins that cannot be associated to a single file (test and filter plugins).
for plugin_type in MULTI_FILE_PLUGINS:
target_per_type.pop(plugin_type, None)
cmd = [
python.path,
os.path.join(SANITY_ROOT, 'validate-modules', 'validate.py'),

Loading…
Cancel
Save