* Add sanity test for required parameters, update ignore.txt, and add changelog.
15 KiB
- orphan
validate-modules
Topics
Python program to help test or validate Ansible modules.
validate-modules
is one of the ansible-test
Sanity Tests, see testing_sanity
for more information.
Originally developed by Matt Martz (@sivel)
Usage
cd /path/to/ansible/source
source hacking/env-setup
ansible-test sanity --test validate-modules
Help
usage: validate-modules [-h] [-w] [--exclude EXCLUDE] [--arg-spec]
[--base-branch BASE_BRANCH] [--format {json,plain}]
[--output OUTPUT]
modules [modules ...]
positional arguments:
modules Path to module or module directory
optional arguments:
-h, --help show this help message and exit
-w, --warnings Show warnings
--exclude EXCLUDE RegEx exclusion pattern
--arg-spec Analyze module argument spec
--base-branch BASE_BRANCH
Used in determining if new options were added
--format {json,plain}
Output format. Default: "plain"
--output OUTPUT Output location, use "-" for stdout. Default "-"
Extending validate-modules
The validate-modules
tool has a schema.py
that is used to validate the YAML blocks, such as
DOCUMENTATION
and RETURNS
.
Codes
Error Code | Type | Level | Sample Message |
---|---|---|---|
|
Syntax | Error | Execution of the module did not result in initialization of AnsibleModule |
|
Documentation | Error | Module marked as deprecated or removed in at least one of the filename, its metadata, or in DOCUMENTATION (setting DOCUMENTATION.deprecated for deprecation or removing all Documentation for removed) but not in all three places. |
|
Documentation | Error | Value for "choices" from the argument_spec does not match the documentation |
|
Documentation | Error | Choices value from the documentation is not compatible with type defined in the argument_spec |
|
Documentation | Error | Value for "default" from the argument_spec does not match the documentation |
|
Documentation | Error | Default value from the documentation is not compatible with type defined in the argument_spec |
|
Documentation | Error | Documentation doesn't specify a type but argument in
argument_spec use default type (str ) |
|
Documentation | Error | argument in argument_spec is required but documentation says it is not, or vice versa |
|
Documentation | Error | Argument_spec defines type different than documentation does |
|
Documentation | Error | Unknown DOCUMENTATION error |
|
Documentation | Error | Invalid DOCUMENTATION schema |
|
Imports | Error | Only the following from __future__ imports are allowed:
absolute_import , division , and
print_function . |
|
Imports | Error | Import found before documentation variables. All imports must appear
below
DOCUMENTATION /EXAMPLES /RETURN /ANSIBLE_METADATA |
|
Documentation | Error | Exception attempting to import module for
argument_spec introspection |
|
Locations | Warning | Imports should be directly below
DOCUMENTATION /EXAMPLES /RETURN /ANSIBLE_METADATA
for legacy modules |
|
Imports | Error | Imports should be directly below
DOCUMENTATION /EXAMPLES /RETURN /ANSIBLE_METADATA |
|
Documentation | Error | Choices value from the argument_spec is not compatible with type defined in the argument_spec |
|
Documentation | Error | Default value from the argument_spec is not compatible with type defined in the argument_spec |
|
Documentation | Error | Argument in argument_spec must be a dictionary/hash when used |
|
Documentation | Error | Suboptions in argument_spec are invalid |
|
Documentation | Error | DOCUMENTATION is not valid YAML |
|
Documentation | Error | DOCUMENTATION.options must be a dictionary/hash when
used |
|
Documentation | Error | EXAMPLES is not valid YAML |
|
Naming | Error | Official Ansible modules must have a .py extension for
python modules or a .ps1 for powershell modules |
|
Documentation | Error | ANSIBLE_METADATA.status of deprecated or removed can't
include other statuses |
|
Documentation | Error | ANSIBLE_METADATA was not provided as a dict, YAML not
supported, Invalid ANSIBLE_METADATA schema |
|
Documentation | Error | AnsibleModule schema validation error |
|
Naming | Error | Module #AnsibleRequires -CSharpUtil should not end in
.cs, Module #Requires should not end in .psm1 |
|
Syntax | Error | Call to main() not the last line (or
removed_module() in the case of deprecated & docs only
modules) |
|
Documentation | Error | ANSIBLE_METADATA cannot be changed in a point release
for a stable branch |
|
Documentation | Error | DOCUMENTATION fragment missing |
|
Documentation | Warning | Pre-existing DOCUMENTATION fragment missing |
|
Documentation | Error | No DOCUMENTATION provided |
|
Documentation | Error | No EXAMPLES provided |
|
Documentation | Error | GPLv3 license header not found |
|
Syntax | Error | Next to last line is not
if __name__ == "__main__": |
|
Syntax | Error | Did not find a call to main() (or
removed_module() in the case of deprecated & docs only
modules) |
|
Documentation | Error | No ANSIBLE_METADATA provided |
|
Imports | Warning | Did not find ansible.module_utils.basic import |
|
Imports | Error | No Ansible.ModuleUtils or C# Ansible util
requirements/imports found |
|
Syntax | Error | Interpreter line is not #!powershell |
|
Naming | Error | Missing python documentation file |
|
Syntax | Error | Interpreter line is not #!/usr/bin/python |
|
Documentation | Error | No RETURN documentation provided |
|
Documentation | Warning | No RETURN documentation provided for legacy module |
|
Documentation | Error | Argument in argument_spec has sub-options but documentation does not define sub-options |
|
Documentation | Error | Module level version_added is incorrect |
|
Documentation | Error | Module level version_added is not a valid version
number |
|
Imports | Error | module_utils imports should import specific components,
not * |
|
Imports | Error | Ansible.ModuleUtils requirements do not support
multiple modules per statement |
|
Imports | Error | Ansible C# util requirements do not support multiple utils per statement |
|
Documentation | Error | Option is marked as required but specifies a default. Arguments with a default should not be marked as required |
|
Documentation | Error | Argument is listed in DOCUMENTATION.options, but not accepted by the module |
|
Documentation | Error | version_added for new option is incorrect |
|
Documentation | Error | version_added for new option is not a valid version
number |
|
Documentation | Error | Argument in argument_spec is not a valid python identifier |
|
Documentation | Error | Value for "elements" is valid only when value of "type" is
list |
|
Documentation | Error | Argument_spec implies type="str" but documentation
defines it as different data type |
|
Documentation | Error | Type value is defined in argument_spec but
documentation doesn't specify a type |
|
Parameters | Error | argument in argument_spec has at least one alias specified multiple times in aliases |
|
Parameters | Error | argument in argument_spec is specified as its own alias |
|
Documentation | Error | argument in argument_spec with aliases is documented multiple times |
|
Syntax | Error | Python SyntaxError while parsing module |
|
Documentation | Error | RETURN is not valid YAML, RETURN fragments
missing or invalid |
|
Naming | Error | Ansible module subdirectories must contain an
__init__.py |
|
Imports | Warning | Try/Except HAS_ expression missing |
|
Documentation | Error | Argument is listed in the argument_spec, but not documented in the module |
|
Syntax | Error | Type comparison using type() found. Use
isinstance() instead |
|
Documentation | Warning | Unknown pre-existing DOCUMENTATION error |
|
Imports | Error | boto import found, new modules should use
boto3 |
|
Imports | Error | sys.exit() call found. Should be
exit_json /fail_json |
|
Imports | Error | requests import found, should use
ansible.module_utils.urls instead |
|
Imports | Error | os.call used instead of
module.run_command |
|
Imports | Error | subprocess.Popen used instead of
module.run_command |
|
Documentation | Error | GPLv3 license header should be the short form <copyright> for new modules |