From e6e19e37f729e89060fdf313c24b91f2f1426bd3 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Tue, 28 Nov 2023 07:09:29 -0800 Subject: [PATCH] validate-modules: Check for correct values in choice (#82266) * validate-modules: Check for correct values in choice * validate-modules test now checks the length of choices and correct option values inside the choice. Fixes: #82179 Signed-off-by: Abhijeet Kasurde * Fix sanity tests Signed-off-by: Abhijeet Kasurde --------- Signed-off-by: Abhijeet Kasurde --- .../plugins/modules/invalid_choice_value.py | 33 +++++++++++++++++++ .../expected.txt | 1 + .../validate_modules/utils.py | 2 +- 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 test/integration/targets/ansible-test-sanity-validate-modules/ansible_collections/ns/col/plugins/modules/invalid_choice_value.py diff --git a/test/integration/targets/ansible-test-sanity-validate-modules/ansible_collections/ns/col/plugins/modules/invalid_choice_value.py b/test/integration/targets/ansible-test-sanity-validate-modules/ansible_collections/ns/col/plugins/modules/invalid_choice_value.py new file mode 100644 index 00000000000..42b315de55a --- /dev/null +++ b/test/integration/targets/ansible-test-sanity-validate-modules/ansible_collections/ns/col/plugins/modules/invalid_choice_value.py @@ -0,0 +1,33 @@ +#!/usr/bin/python +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import annotations + +DOCUMENTATION = """ +module: invalid_choice_value +short_description: Test for equal length of chocies with correct options +description: Test for equal length of chocies with correct options +author: + - Ansible Core Team +options: + caching: + description: + - Type of Caching. + type: str + choices: + - ReadOnly + - ReadWrite +""" + +EXAMPLES = """#""" +RETURN = """""" + +from ansible.module_utils.basic import AnsibleModule + + +if __name__ == "__main__": + module = AnsibleModule( + argument_spec=dict(caching=dict(type="str", choices=["ReadOnly", "ReadOnly"])), + supports_check_mode=False, + ) + module.exit_json() diff --git a/test/integration/targets/ansible-test-sanity-validate-modules/expected.txt b/test/integration/targets/ansible-test-sanity-validate-modules/expected.txt index 93355b5fcef..ef805f4a703 100644 --- a/test/integration/targets/ansible-test-sanity-validate-modules/expected.txt +++ b/test/integration/targets/ansible-test-sanity-validate-modules/expected.txt @@ -4,6 +4,7 @@ plugins/modules/check_mode_attribute_2.py:0:0: attributes-check-mode: The module plugins/modules/check_mode_attribute_3.py:0:0: attributes-check-mode: The module does declare support for check mode, but the check_mode attribute's support value is 'none' plugins/modules/check_mode_attribute_4.py:0:0: attributes-check-mode-details: The module declares it does not fully support check mode, but has no details on what exactly that means plugins/modules/import_order.py:7:0: import-before-documentation: Import found before documentation variables. All imports must appear below DOCUMENTATION/EXAMPLES/RETURN. +plugins/modules/invalid_choice_value.py:0:0: doc-choices-do-not-match-spec: Argument 'caching' in argument_spec defines choices as (['ReadOnly', 'ReadOnly']) but documentation defines choices as (['ReadOnly', 'ReadWrite']) plugins/modules/invalid_yaml_syntax.py:0:0: deprecation-mismatch: "meta/runtime.yml" and DOCUMENTATION.deprecation do not agree. plugins/modules/invalid_yaml_syntax.py:0:0: missing-documentation: No DOCUMENTATION provided plugins/modules/invalid_yaml_syntax.py:7:15: documentation-syntax-error: DOCUMENTATION is not valid YAML diff --git a/test/lib/ansible_test/_util/controller/sanity/validate-modules/validate_modules/utils.py b/test/lib/ansible_test/_util/controller/sanity/validate-modules/validate_modules/utils.py index 15cb7037282..84bab285f28 100644 --- a/test/lib/ansible_test/_util/controller/sanity/validate-modules/validate_modules/utils.py +++ b/test/lib/ansible_test/_util/controller/sanity/validate-modules/validate_modules/utils.py @@ -192,7 +192,7 @@ def compare_unordered_lists(a, b): - unordered lists - unhashable elements """ - return len(a) == len(b) and all(x in b for x in a) + return len(a) == len(b) and all(x in b for x in a) and all(x in a for x in b) class NoArgsAnsibleModule(AnsibleModule):