diff options
author | Matt Clay <matt@mystile.com> | 2021-12-06 15:14:36 -0800 |
---|---|---|
committer | Matt Clay <matt@mystile.com> | 2021-12-07 17:23:16 -0800 |
commit | a6be3165e0ee416f8d10590bdd876145365bd59a (patch) | |
tree | 49c9ba8c6ace805bcd838eb5543f6633cdf194d1 | |
parent | 21c65df1fbfccbf7dda72212a4086d0db0043221 (diff) | |
download | ansible-a6be3165e0ee416f8d10590bdd876145365bd59a.tar.gz |
[stable-2.11] ansible-test - Fix traceback in validate-modules test.
(cherry picked from commit 41ee4a5b128542252dfd4763c46e0399334270a5)
Co-authored-by: Matt Clay <matt@mystile.com>
3 files changed, 27 insertions, 2 deletions
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 0000000000..311b7667ec --- /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 0000000000..176376abab --- /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/_data/sanity/validate-modules/validate_modules/main.py b/test/lib/ansible_test/_data/sanity/validate-modules/validate_modules/main.py index 5b61f44b38..e6be1e5c99 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 @@ -605,7 +605,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_main_call(self, look_for="main"): """ Ensure that the module ends with: @@ -2230,7 +2230,7 @@ class ModuleValidator(Validator): main = self._find_main_call() self._find_module_utils(main) 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() |