summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Clay <matt@mystile.com>2021-12-06 15:14:36 -0800
committerMatt Clay <matt@mystile.com>2021-12-07 17:23:19 -0800
commit70e75e6a3b22c550ba633a9e2bf8aae7568b5220 (patch)
tree1f34158ed81d1a885214ea354ce1d661b4c7dd20
parente1425c0e43f823a1e45494e1b5867ce7e3a222eb (diff)
downloadansible-70e75e6a3b22c550ba633a9e2bf8aae7568b5220.tar.gz
[stable-2.10] ansible-test - Fix traceback in validate-modules test.
(cherry picked from commit 41ee4a5b128542252dfd4763c46e0399334270a5) Co-authored-by: Matt Clay <matt@mystile.com>
-rw-r--r--changelogs/fragments/ansible-test-validate-modules-no-callable.yml2
-rw-r--r--test/integration/targets/ansible-test/ansible_collections/ns/col/plugins/modules/no_callable.py23
-rw-r--r--test/lib/ansible_test/_data/sanity/validate-modules/validate_modules/main.py4
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 e7379288d7..731c0e45bb 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
@@ -583,7 +583,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:
@@ -2192,7 +2192,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()