From b143fdea54cb11e5bde9c6c63080baa3b4b3d4dc Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Tue, 21 Feb 2017 19:42:39 -0600 Subject: [PATCH] DOC options must be a dict when used with extends_documentation_fragment (#21745) * Fix string formatting * Provide better tracebacks * When options is None and extends_documentation_fragment is in use, add an error that options must be a dict * If options was specified and not a dict, then error --- lib/ansible/utils/module_docs.py | 2 +- test/sanity/validate-modules/validate-modules | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/ansible/utils/module_docs.py b/lib/ansible/utils/module_docs.py index 47e0b59a942..b7ffcda3add 100755 --- a/lib/ansible/utils/module_docs.py +++ b/lib/ansible/utils/module_docs.py @@ -117,7 +117,7 @@ def get_docstring(filename, verbose=False): elif isinstance(doc[key], MutableSequence): doc[key] = sorted(frozenset(doc[key] + value)) else: - raise Exception("Attempt to extend a documentation fragement (%s) of unknown type: %s" (fragment_name, filename)) + raise Exception("Attempt to extend a documentation fragement (%s) of unknown type: %s" % (fragment_name, filename)) elif 'EXAMPLES' == theid: plainexamples = child.value.s[1:] # Skip first empty line diff --git a/test/sanity/validate-modules/validate-modules b/test/sanity/validate-modules/validate-modules index 2cc44e817ea..e5c0d3bf016 100755 --- a/test/sanity/validate-modules/validate-modules +++ b/test/sanity/validate-modules/validate-modules @@ -28,6 +28,7 @@ import re import subprocess import sys import tempfile +import traceback from collections import OrderedDict from contextlib import contextmanager @@ -569,13 +570,20 @@ class ModuleValidator(Validator): 303, 'DOCUMENTATION fragment missing: %s' % fragment )) - except Exception as e: - self.traces.append(e) + except Exception: + self.traces.append(traceback.format_exc()) self.errors.append(( 304, 'Unknown DOCUMENTATION error, see TRACE' )) + if 'options' in doc and doc['options'] is None and doc.get('extends_documentation_fragment'): + self.errors.append(( + 305, + ('DOCUMENTATION.options must be a dictionary/hash when used ' + 'with DOCUMENTATION.extends_documentation_fragment') + )) + self._validate_docs_schema(doc, doc_schema, 'DOCUMENTATION', 305) self._check_version_added(doc) self._check_for_new_args(doc) @@ -760,8 +768,8 @@ class ModuleValidator(Validator): self.errors.append((401, 'Python SyntaxError while parsing module')) try: compile(self.text, self.path, 'exec') - except Exception as e: - self.traces.append(e) + except Exception: + self.traces.append(traceback.format_exc()) return if self._python_module():