From 41ee4a5b128542252dfd4763c46e0399334270a5 Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Mon, 6 Dec 2021 15:14:36 -0800 Subject: [PATCH] ansible-test - Fix traceback in validate-modules test. --- ...ible-test-validate-modules-no-callable.yml | 2 ++ .../ns/col/plugins/modules/no_callable.py | 23 +++++++++++++++++++ .../validate-modules/validate_modules/main.py | 4 ++-- 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/ansible-test-validate-modules-no-callable.yml create mode 100644 test/integration/targets/ansible-test/ansible_collections/ns/col/plugins/modules/no_callable.py diff --git a/changelogs/fragments/ansible-test-validate-modules-no-callable.yml b/changelogs/fragments/ansible-test-validate-modules-no-callable.yml new file mode 100644 index 00000000000..311b7667ec6 --- /dev/null +++ b/changelogs/fragments/ansible-test-validate-modules-no-callable.yml @@ -0,0 +1,2 @@ +bugfixes: + - ansible-test - Fix traceback in the ``validate-modules`` sanity test when testing an Ansible module without any callables. diff --git a/test/integration/targets/ansible-test/ansible_collections/ns/col/plugins/modules/no_callable.py b/test/integration/targets/ansible-test/ansible_collections/ns/col/plugins/modules/no_callable.py new file mode 100644 index 00000000000..176376abab4 --- /dev/null +++ b/test/integration/targets/ansible-test/ansible_collections/ns/col/plugins/modules/no_callable.py @@ -0,0 +1,23 @@ +#!/usr/bin/python +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + +DOCUMENTATION = ''' +module: no_callable +short_description: No callale test module +description: No callable test module. +author: + - Ansible Core Team +''' + +EXAMPLES = '''#''' +RETURN = '''''' + +from ansible.module_utils.basic import AnsibleModule + + +if __name__ == '__main__': + module = AnsibleModule(argument_spec=dict()) + module.exit_json() diff --git a/test/lib/ansible_test/_util/controller/sanity/validate-modules/validate_modules/main.py b/test/lib/ansible_test/_util/controller/sanity/validate-modules/validate_modules/main.py index 9f4f5c474d5..278d57aecc3 100644 --- a/test/lib/ansible_test/_util/controller/sanity/validate-modules/validate_modules/main.py +++ b/test/lib/ansible_test/_util/controller/sanity/validate-modules/validate_modules/main.py @@ -606,7 +606,7 @@ class ModuleValidator(Validator): if isinstance(child, (ast.FunctionDef, ast.ClassDef)): linenos.append(child.lineno) - return min(linenos) + return min(linenos) if linenos else None def _find_has_import(self): for child in self.ast.body: @@ -2179,7 +2179,7 @@ class ModuleValidator(Validator): self._find_rejectlist_imports() self._find_module_utils() self._find_has_import() - first_callable = self._get_first_callable() + first_callable = self._get_first_callable() or 1000000 # use a bogus "high" line number if no callable exists self._ensure_imports_below_docs(doc_info, first_callable) self._check_for_subprocess() self._check_for_os_call()