Add module support to yamllint sanity test. (#34964)

* Add module support to yamllint sanity test.
* Fix duplicate keys in module RETURN docs.
* Fix syntax in return_common docs fragment.
* Fix duplicate keys in module EXAMPLES docs.
This commit is contained in:
Matt Clay 2018-01-16 15:08:56 -08:00 committed by GitHub
parent 240024ea4a
commit 227ff61f9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
53 changed files with 533 additions and 344 deletions

View file

@ -1,8 +1,8 @@
"""Sanity test using yamllint."""
from __future__ import absolute_import, print_function
import json
import os
import re
from lib.sanity import (
SanitySingleVersion,
@ -15,7 +15,6 @@ from lib.sanity import (
from lib.util import (
SubprocessError,
run_command,
find_executable,
)
from lib.config import (
@ -31,15 +30,42 @@ class YamllintTest(SanitySingleVersion):
:type targets: SanityTargets
:rtype: SanityResult
"""
paths = sorted(i.path for i in targets.include if os.path.splitext(i.path)[1] in ('.yml', '.yaml'))
paths = [
[i.path for i in targets.include if os.path.splitext(i.path)[1] in ('.yml', '.yaml')],
[i.path for i in targets.include if os.path.splitext(i.path)[1] == '.py' and
os.path.basename(i.path) != '__init__.py' and
i.path.startswith('lib/ansible/modules/')],
[i.path for i in targets.include if os.path.splitext(i.path)[1] == '.py' and
os.path.basename(i.path) != '__init__.py' and
i.path.startswith('lib/ansible/utils/module_docs_fragments/')],
]
paths = [sorted(p) for p in paths if p]
if not paths:
return SanitySkipped(self.name)
results = []
for test_paths in paths:
results += self.test_paths(args, test_paths)
if results:
return SanityFailure(self.name, messages=results)
return SanitySuccess(self.name)
def test_paths(self, args, paths):
"""
:type args: SanityConfig
:type paths: list[str]
:rtype: list[SanityMessage]
"""
cmd = [
'python%s' % args.python_version,
find_executable('yamllint'),
'--format', 'parsable',
'test/sanity/yamllint/yamllinter.py',
] + paths
try:
@ -54,11 +80,9 @@ class YamllintTest(SanitySingleVersion):
raise SubprocessError(cmd=cmd, status=status, stderr=stderr, stdout=stdout)
if args.explain:
return SanitySuccess(self.name)
return []
pattern = r'^(?P<path>[^:]*):(?P<line>[0-9]+):(?P<column>[0-9]+): \[(?P<level>warning|error)\] (?P<message>.*)$'
results = [re.search(pattern, line).groupdict() for line in stdout.splitlines()]
results = json.loads(stdout)['messages']
results = [SanityMessage(
message=r['message'],
@ -68,7 +92,4 @@ class YamllintTest(SanitySingleVersion):
level=r['level'],
) for r in results]
if results:
return SanityFailure(self.name, messages=results)
return SanitySuccess(self.name)
return results