1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/test/sanity/validate-modules
John R Barker 04e816e13b Stricter module documentation validation (#22353)
Raise the bar for module `DOCUMENTAION`
This validator update was used to find the issues in https://github.com/ansible/ansible/pull/22297/files

**Validation**
* Updated Validation and docs to enforce more (items fixed in https://github.com/ansible/ansible/pull/22297/files)
* Use `suboptions` to document complex options 
* Validate module name
* Validate deprecated modules have correct ANSIBLE_METADATA

**Module Documentation Generation**
* Document `suboptions:` Example https://gist.github.com/gundalow/4bdc3669d696268328ccc18528cc6718
* Tidy up HTML generation (valid HTML, no empty lists, etc)
 
**Documentation**
* Clarify the steps for deprecating a module
* Use correct RST headings
* Document `suboptions:` (options)
* Document `contains:` (returns)


**Details**
The aim is to get this (and corresponding module updates) complete by the time `devel` becomes `2.4`, as this allows us to raise the bar for new modules

Example `suboptions` https://gist.github.com/gundalow/4bdc3669d696268328ccc18528cc6718

The aim is to get this PR integrated into `devel` *before* we branch `stable-2.3`, this will allows us to:
* Raise the bar for new modules in 2.4
* Ensure the generated module documentation for 2.3 and higher is improved, important as we will be doing versioned docs moving forward.
2017-03-13 19:49:27 +00:00
..
__init__.py Port sivel/ansible-validate-modules into Ansible 2016-10-13 14:36:22 +01:00
module_args.py validate-modules --arg-spec (#21331) 2017-02-15 08:09:08 +00:00
README.rst Ensure that a deprecated module has DOCUMENTATION.deprecated (#22090) 2017-02-28 16:43:43 +00:00
schema.py Stricter module documentation validation (#22353) 2017-03-13 19:49:27 +00:00
skip.txt Remove remnants of obsolete fireball mode. 2016-12-09 16:56:34 -07:00
test_validate_modules_regex.py Update validate-modules (#20932) 2017-02-02 11:45:22 -08:00
utils.py Validate EXAMPLES as YAML 2017-02-15 13:01:43 -08:00
validate-modules Stricter module documentation validation (#22353) 2017-03-13 19:49:27 +00:00

validate-modules
================

Python program to help test or validate Ansible modules.

Originally developed by Matt Martz (@sivel)

Usage
~~~~~

.. code:: shell

    cd /path/to/ansible/source
    source hacking/env-setup
    test/sanity/validate-modules/validate-modules /path/to/modules

Help
~~~~

.. code:: shell

    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 "-"

Codes
~~~~~~~

Errors
^^^^^^

+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| code    | sample message                                                                                                                             |
+=========+============================================================================================================================================+
| **1xx** | **Locations**                                                                                                                              |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 101     | Interpreter line is not ``#!/usr/bin/python``                                                                                              |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 102     | Interpreter line is not ``#!powershell``                                                                                                   |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 103     | Did not find a call to ``main()``                                                                                                          |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 104     | Call to ``main()`` not the last line                                                                                                       |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 105     | GPLv3 license header not found                                                                                                             |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 106     | Import found before documentation variables. All imports must appear below ``DOCUMENTATION``/``EXAMPLES``/``RETURN``/``ANSIBLE_METADATA``  |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 107     | Imports should be directly below ``DOCUMENTATION``/``EXAMPLES``/``RETURN``/``ANSIBLE_METADATA``                                            |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| **2xx** | **Imports**                                                                                                                                |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 201     | Did not find a ``module_utils`` import                                                                                                     |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 203     | ``requests`` import found, should use ``ansible.module_utils.urls`` instead                                                                |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 204     | ``boto`` import found, new modules should use ``boto3``                                                                                    |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 205     | ``sys.exit()`` call found. Should be ``exit_json``/``fail_json``                                                                           |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 206     | ``WANT_JSON`` not found in module                                                                                                          |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 207     | ``REPLACER_WINDOWS`` not found in module                                                                                                   |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 208     | ``module_utils`` imports should import specific components, not ``*``                                                                      |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| **3xx** | **Documentation**                                                                                                                          |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 301     | No ``DOCUMENTATION`` provided                                                                                                              |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 302     | ``DOCUMENTATION`` is not valid YAML                                                                                                        |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 303     | ``DOCUMENTATION`` fragment missing                                                                                                         |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 304     | Unknown ``DOCUMENTATION`` error                                                                                                            |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 305     | Invalid ``DOCUMENTATION`` schema                                                                                                           |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 306     | Module level ``version_added`` is not a valid version number                                                                               |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 307     | Module level ``version_added`` is incorrect                                                                                                |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 308     | ``version_added`` for new option is not a valid version number                                                                             |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 309     | ``version_added`` for new option is incorrect                                                                                              |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 310     | No ``EXAMPLES`` provided                                                                                                                   |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 311     | ``EXAMPLES`` is not valid YAML                                                                                                             |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 312     | No ``RETURN`` documentation provided                                                                                                       |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 313     | ``RETURN`` is not valid YAML                                                                                                               |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 314     | No ``ANSIBLE_METADATA`` provided                                                                                                           |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 315     | ``ANSIBLE_METADATA`` is not valid YAML                                                                                                     |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 316     | Invalid ``ANSIBLE_METADATA`` schema                                                                                                        |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 317     | option is marked as required but specifies a default. Arguments with a default should not be marked as required                            |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 318     | Module deprecated, but DOCUMENTATION.deprecated is missing                                                                                 |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| **4xx** | **Syntax**                                                                                                                                 |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 401     | Python ``SyntaxError`` while parsing module                                                                                                |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 402     | Indentation contains tabs                                                                                                                  |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 403     | Type comparison using ``type()`` found. Use ``isinstance()`` instead                                                                       |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| **5xx** | **Naming**                                                                                                                                 |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 501     | Official Ansible modules must have a ``.py`` extension for python modules or a ``.ps1`` for powershell modules                             |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 502     | Ansible module subdirectories must contain an ``__init__.py``                                                                              |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 503     | Missing python documentation file                                                                                                          |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+

Warnings
^^^^^^^^

+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| code    | sample message                                                                                                                             |
+=========+============================================================================================================================================+
| **1xx** | **Locations**                                                                                                                              |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 107     | Imports should be directly below ``DOCUMENTATION``/``EXAMPLES``/``RETURN``/``ANSIBLE_METADATA`` for legacy modules                         |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| **2xx** | **Imports**                                                                                                                                |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 208     | ``module_utils`` imports should import specific components for legacy module, not ``*``                                                    |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 291     | Try/Except ``HAS_`` expression missing                                                                                                     |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 292     | Did not find ``ansible.module_utils.basic`` import                                                                                         |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| **3xx** | **Documentation**                                                                                                                          |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 312     | No ``RETURN`` documentation provided for legacy module                                                                                     |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 391     | Unknown pre-existing ``DOCUMENTATION`` error                                                                                               |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 392     | Pre-existing ``DOCUMENTATION`` fragment missing                                                                                            |
+---------+--------------------------------------------------------------------------------------------------------------------------------------------+