From 5d4d9d40af5232f4f58c4b9ba22e596a16603222 Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Thu, 30 Jan 2020 22:38:47 +0100 Subject: [PATCH] ansible-test - Add 'get' to the list of bad choices for state (#66921) * ansible-test - Add 'get' to the list of bad choices for state * Changelog fragment --- changelogs/fragments/66921-sanity-state-get.yaml | 2 ++ .../rst/dev_guide/developing_modules_best_practices.rst | 2 +- docs/docsite/rst/dev_guide/testing_validate-modules.rst | 2 +- .../_data/sanity/validate-modules/validate_modules/main.py | 2 +- test/sanity/ignore.txt | 3 +++ 5 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/66921-sanity-state-get.yaml diff --git a/changelogs/fragments/66921-sanity-state-get.yaml b/changelogs/fragments/66921-sanity-state-get.yaml new file mode 100644 index 00000000000..f1603729c11 --- /dev/null +++ b/changelogs/fragments/66921-sanity-state-get.yaml @@ -0,0 +1,2 @@ +minor_changes: + - 'ansible-test - Add a test to prevent ``state=get``' diff --git a/docs/docsite/rst/dev_guide/developing_modules_best_practices.rst b/docs/docsite/rst/dev_guide/developing_modules_best_practices.rst index 60251809f66..1455c94f205 100644 --- a/docs/docsite/rst/dev_guide/developing_modules_best_practices.rst +++ b/docs/docsite/rst/dev_guide/developing_modules_best_practices.rst @@ -16,7 +16,7 @@ Scoping your module(s) Especially if you want to contribute your module(s) back to Ansible Core, make sure each module includes enough logic and functionality, but not too much. If you're finding these guidelines tricky, consider :ref:`whether you really need to write a module ` at all. * Each module should have a concise and well-defined functionality. Basically, follow the UNIX philosophy of doing one thing well. -* Do not add ``list`` or ``info`` state options to an existing module - create a new ``_info`` or ``_facts`` module. +* Do not add ``get``, ``list`` or ``info`` state options to an existing module - create a new ``_info`` or ``_facts`` module. * Modules should not require that a user know all the underlying options of an API/tool to be used. For instance, if the legal values for a required module parameter cannot be documented, the module does not belong in Ansible Core. * Modules should encompass much of the logic for interacting with a resource. A lightweight wrapper around a complex API forces users to offload too much logic into their playbooks. If you want to connect Ansible to a complex API, :ref:`create multiple modules ` that interact with smaller individual pieces of the API. * Avoid creating a module that does the work of other modules; this leads to code duplication and divergence, and makes things less uniform, unpredictable and harder to maintain. Modules should be the building blocks. If you are asking 'how can I have a module execute other modules' ... you want to write a role. diff --git a/docs/docsite/rst/dev_guide/testing_validate-modules.rst b/docs/docsite/rst/dev_guide/testing_validate-modules.rst index fca483a7601..9a21e5e8611 100644 --- a/docs/docsite/rst/dev_guide/testing_validate-modules.rst +++ b/docs/docsite/rst/dev_guide/testing_validate-modules.rst @@ -126,7 +126,7 @@ Codes 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" - parameter-state-invalid-choice Parameters Error Argument ``state`` includes ``list`` or ``info`` as a choice. Functionality should be in an ``_info`` or (if further conditions apply) ``_facts`` module. + parameter-state-invalid-choice Parameters Error Argument ``state`` includes ``get``, ``list`` or ``info`` as a choice. Functionality should be in an ``_info`` or (if further conditions apply) ``_facts`` module. 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`` diff --git a/test/lib/ansible_test/_data/sanity/validate-modules/validate_modules/main.py b/test/lib/ansible_test/_data/sanity/validate-modules/validate_modules/main.py index 043f0660857..2898d062762 100644 --- a/test/lib/ansible_test/_data/sanity/validate-modules/validate_modules/main.py +++ b/test/lib/ansible_test/_data/sanity/validate-modules/validate_modules/main.py @@ -1213,7 +1213,7 @@ class ModuleValidator(Validator): msg=msg ) if not context and arg == 'state': - bad_states = set(['list', 'info']) & set(data.get('choices', set())) + bad_states = set(['list', 'info', 'get']) & set(data.get('choices', set())) for bad_state in bad_states: self.reporter.error( path=self.object_path, diff --git a/test/sanity/ignore.txt b/test/sanity/ignore.txt index be886aaf277..af937e667b7 100644 --- a/test/sanity/ignore.txt +++ b/test/sanity/ignore.txt @@ -650,6 +650,7 @@ lib/ansible/modules/cloud/amazon/redshift.py validate-modules:parameter-list-no- lib/ansible/modules/cloud/amazon/redshift_subnet_group.py validate-modules:doc-elements-mismatch lib/ansible/modules/cloud/amazon/redshift_subnet_group.py validate-modules:parameter-list-no-elements lib/ansible/modules/cloud/amazon/route53.py validate-modules:parameter-list-no-elements +lib/ansible/modules/cloud/amazon/route53.py validate-modules:parameter-state-invalid-choice lib/ansible/modules/cloud/amazon/route53_info.py validate-modules:doc-elements-mismatch lib/ansible/modules/cloud/amazon/route53_info.py validate-modules:parameter-list-no-elements lib/ansible/modules/cloud/amazon/s3_bucket_notification.py validate-modules:doc-elements-mismatch @@ -7381,6 +7382,7 @@ lib/ansible/modules/system/dconf.py validate-modules:parameter-type-not-in-doc lib/ansible/modules/system/filesystem.py pylint:blacklisted-name lib/ansible/modules/system/filesystem.py validate-modules:doc-missing-type lib/ansible/modules/system/gconftool2.py pylint:blacklisted-name +lib/ansible/modules/system/gconftool2.py validate-modules:parameter-state-invalid-choice lib/ansible/modules/system/gconftool2.py validate-modules:parameter-type-not-in-doc lib/ansible/modules/system/getent.py validate-modules:parameter-type-not-in-doc lib/ansible/modules/system/hostname.py validate-modules:invalid-ansiblemodule-schema @@ -7454,6 +7456,7 @@ lib/ansible/modules/system/user.py validate-modules:doc-default-incompatible-typ lib/ansible/modules/system/user.py validate-modules:parameter-list-no-elements lib/ansible/modules/system/user.py validate-modules:use-run-command-not-popen lib/ansible/modules/system/vdo.py validate-modules:doc-required-mismatch +lib/ansible/modules/system/xfconf.py validate-modules:parameter-state-invalid-choice lib/ansible/modules/system/xfconf.py validate-modules:parameter-type-not-in-doc lib/ansible/modules/utilities/logic/async_status.py use-argspec-type-path lib/ansible/modules/utilities/logic/async_status.py validate-modules!skip