summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGonéri Le Bouder <goneri@lebouder.net>2021-02-02 22:29:36 +0100
committerGitHub <noreply@github.com>2021-02-02 22:29:36 +0100
commit7cf80f50d16b7a7a2ba9f1318bdca5df53936369 (patch)
tree583a4170b567785defa27948e63edf996e75f674
parenthostname: fix references in docs (#73454) (diff)
downloadansible-7cf80f50d16b7a7a2ba9f1318bdca5df53936369.tar.xz
ansible-7cf80f50d16b7a7a2ba9f1318bdca5df53936369.zip
validate_modules: fails with .id attribute not found (#73322)
* validate_modules: fails with .id attribute not found This patch addresses a problem in the `found_try_except_import` test. This module tries to identify lines like: `HAS_FOO = True` In this case, the target (`HAS_FOO`) is of type `ast.Name` and has a `id` attribute which provide the name. In my case, I've a line that set a module attribute`. In this case, the target (`module.var`) has the type `ast.Attribute` and no `id` attribute. The code trigger an `AttributeError` exception. This patch ensures we compare a `ast.Name`. * Update test/lib/ansible_test/_data/sanity/validate-modules/validate_modules/main.py
-rw-r--r--changelogs/fragments/validate-modules_found_try_except_import_fails_module_attribute.yaml3
-rw-r--r--test/lib/ansible_test/_data/sanity/validate-modules/validate_modules/main.py2
2 files changed, 5 insertions, 0 deletions
diff --git a/changelogs/fragments/validate-modules_found_try_except_import_fails_module_attribute.yaml b/changelogs/fragments/validate-modules_found_try_except_import_fails_module_attribute.yaml
new file mode 100644
index 0000000000..b14be52a3f
--- /dev/null
+++ b/changelogs/fragments/validate-modules_found_try_except_import_fails_module_attribute.yaml
@@ -0,0 +1,3 @@
+---
+bugfixes:
+- validate-modules - do not raise an ``AttributeError`` if a value is assigned to a module attribute in a try/except block.
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 921c43e1fb..1ffc57ad04 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
@@ -666,6 +666,8 @@ class ModuleValidator(Validator):
found_try_except_import = True
if isinstance(grandchild, ast.Assign):
for target in grandchild.targets:
+ if not isinstance(target, ast.Name):
+ continue
if target.id.lower().startswith('has_'):
found_has = True
if found_try_except_import and not found_has: