Validate DOCUMENTATION schema

reviewable/pr18001/r3
Matt Martz 9 years ago committed by John Barker
parent 10d683a962
commit a103f81513

@ -18,6 +18,8 @@ from ansible.module_utils import basic as module_utils_basic
from ansible.plugins import module_loader from ansible.plugins import module_loader
from ansible.utils.module_docs import BLACKLIST_MODULES, get_docstring from ansible.utils.module_docs import BLACKLIST_MODULES, get_docstring
from schema import doc_schema, option_schema
from utils import CaptureStd, find_globals from utils import CaptureStd, find_globals
import yaml import yaml
@ -345,6 +347,26 @@ class ModuleValidator(Validator):
return docs return docs
def _validate_docs_schema(self, doc):
errors = []
try:
doc_schema(doc)
except Exception as e:
errors.extend(e.errors)
for key, option in doc.get('options', {}).iteritems():
try:
option_schema(option)
except Exception as e:
for error in e.errors:
error.path[:0] = ['options', key]
errors.extend(e.errors)
for error in errors:
path = [str(p) for p in error.path]
self.errors.append('DOCUMENTATION.%s: %s' %
('.'.join(path), error.error_message))
def _validate_docs(self): def _validate_docs(self):
doc_info = self._get_docs() doc_info = self._get_docs()
try: try:
@ -378,6 +400,7 @@ class ModuleValidator(Validator):
self.errors.append('Unknown DOCUMENTATION error, see ' self.errors.append('Unknown DOCUMENTATION error, see '
'TRACE') 'TRACE')
self._validate_docs_schema(doc)
self._check_version_added(doc) self._check_version_added(doc)
self._check_for_new_args(doc) self._check_for_new_args(doc)
@ -451,7 +474,6 @@ class ModuleValidator(Validator):
'TRACE') 'TRACE')
return return
try: try:
mod_version_added = StrictVersion( mod_version_added = StrictVersion(
str(existing_doc.get('version_added', '0.0')) str(existing_doc.get('version_added', '0.0'))

@ -0,0 +1,27 @@
from voluptuous import ALLOW_EXTRA, Any, Required, Schema
option_schema = Schema(
{
Required('description'): Any(basestring, [basestring]),
'required': bool,
'choices': Any(list, basestring),
'aliases': list,
'version_added': Any(basestring, float)
},
extra=ALLOW_EXTRA
)
doc_schema = Schema(
{
Required('module'): basestring,
'short_description': Any(basestring, [basestring]),
'description': Any(basestring, [basestring]),
'version_added': Any(basestring, float),
'author': Any(None, basestring, [basestring]),
'notes': Any(None, [basestring]),
'requirements': [basestring],
'options': Any(None, dict),
'extends_documentation_fragment': Any(basestring, [basestring])
},
extra=ALLOW_EXTRA
)
Loading…
Cancel
Save