Skip to content

Commit

Permalink
test-module: define ansible_version attribute
Browse files Browse the repository at this point in the history
Executed command:

    ./hacking/test-module -m lib/ansible/modules/cloud/scaleway/scaleway_security_group.py -a ...

Fix this exception found while testing scaleway_security_group module:

    Traceback (most recent call last):
      File "~/debug_dir/__main__.py", line 240, in <module>
        main()
      File "~/debug_dir/__main__.py", line 236, in main
        core(module)
      File "~/debug_dir/__main__.py", line 209, in core
        api = Scaleway(module=module)
      File "~/debug_dir/ansible/module_utils/scaleway.py", line 58, in __init__
        'User-Agent': self.get_user_agent_string(module),
      File "~/debug_dir/ansible/module_utils/scaleway.py", line 99, in get_user_agent_string
        return "ansible %s Python %s" % (module.ansible_version, sys.version.split(' ')[0])
    AttributeError: 'AnsibleModule' object has no attribute 'ansible_version'
  • Loading branch information
pilou- authored and mscherer committed Oct 18, 2018
1 parent 7231f7d commit 92103bf
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions hacking/test-module
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import sys
import traceback
import shutil

from ansible.release import __version__
import ansible.utils.vars as utils_vars
from ansible.parsing.dataloader import DataLoader
from ansible.parsing.utils.jsonify import jsonify
Expand Down Expand Up @@ -124,6 +125,7 @@ def boilerplate_module(modfile, args, interpreters, check, destfile):
complex_args['_ansible_selinux_special_fs'] = C.DEFAULT_SELINUX_SPECIAL_FS
complex_args['_ansible_tmpdir'] = C.DEFAULT_LOCAL_TMP
complex_args['_ansible_keep_remote_files'] = C.DEFAULT_KEEP_REMOTE_FILES
complex_args['_ansible_version'] = __version__

if args.startswith("@"):
# Argument is a YAML file (JSON is a subset of YAML)
Expand Down

0 comments on commit 92103bf

Please sign in to comment.