Add sanity test to require elements entry when argument type=list (#66386)

* Require elements entry for lists

* Bulk add initial test/sanity/ignore.txt
This commit is contained in:
Mark Chappell 2020-01-28 16:23:22 +01:00 committed by Sloane Hertel
parent 6901c9c61c
commit 5ff899662d
4 changed files with 1309 additions and 0 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- "ansible-test - the module validation code now checks whether ``elements`` is defined when ``type=list``"

View file

@ -123,6 +123,7 @@ Codes
parameter-alias-repeated Parameters Error argument in argument_spec has at least one alias specified multiple times in aliases
parameter-alias-self Parameters Error argument in argument_spec is specified as its own alias
parameter-documented-multiple-times Documentation Error argument in argument_spec with aliases is documented multiple times
parameter-list-no-elements Parameters Error argument in argument_spec "type" is specified as ``list`` without defining "elements"
python-syntax-error Syntax Error Python ``SyntaxError`` while parsing module
return-syntax-error Documentation Error ``RETURN`` is not valid YAML, ``RETURN`` fragments missing or invalid
subdirectory-missing-init Naming Error Ansible module subdirectories must contain an ``__init__.py``

View file

@ -1255,6 +1255,16 @@ class ModuleValidator(Validator):
_type_checker = module._CHECK_ARGUMENT_TYPES_DISPATCHER.get(_type)
_elements = data.get('elements')
if (_type == 'list') and not _elements:
msg = "Argument '%s' in argument_spec" % arg
if context:
msg += " found in %s" % " -> ".join(context)
msg += " defines type as list but elements is not defined"
self.reporter.error(
path=self.object_path,
code='parameter-list-no-elements',
msg=msg
)
if _elements:
if not callable(_elements):
module._CHECK_ARGUMENT_TYPES_DISPATCHER.get(_elements)

File diff suppressed because it is too large Load diff