Repository: ansible/ansible
Pull request: Fix test-module failing to validate args
##### SUMMARY
<!--- Describe the change, including rationale and design decisions -->
The test-module pass a wrong argument _ansible_tmp cause the validation failed.
Change the argument _ansible_tmp to _ansible_tmpdir to fix this.
<!--- If you are fixing an existing issue, please include "Fixes #nnn" in your
commit message and your description; but you should still explain what
the change does.-->
Fixes #40817 
Co-authored-by: Sviat <wk@sydorenko.org.ua>
##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Bugfix Pull Request


##### COMPONENT NAME
<!--- Name of the module, plugin, module or task -->
test-module
##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes below -->
```
devel
```


##### ADDITIONAL INFORMATION
<!--- Include additional information to help people understand the change here.
For bugs that don't have a linked bug report, a step-by-step reproduction
of the problem is helpful. -->
N/A
<!--- Paste verbatim command output below, e.g. before and after your change -->
```

```


Problem statement:
hacking/test-module adds an unexpected "_ansible_tmp" parameter
##### SUMMARY
It looks like `hacking/test-module` adds an unexpected `_ansible_tmp` parameter during execution.

##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
homebrew_cask

##### ANSIBLE VERSION
```
± ansible --version
ansible 2.7.0dev0 (homebrew_cask_sudo_fix cb636eb522) last updated 2018/05/29 05:27:55 (GMT -400)
  config file = /Users/dan/.ansible.cfg
  configured module search path = ['/Users/dan/src/ansible/library']
  ansible python module location = /Users/dan/src/ansible/lib/ansible
  executable location = /Users/dan/src/ansible/bin/ansible
  python version = 3.6.3 (default, Oct 21 2017, 11:37:52) [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)]
```

##### CONFIGURATION
```
ANSIBLE_NOCOWS(env: ANSIBLE_NOCOWS) = True
DEFAULT_HASH_BEHAVIOUR(/Users/dan/.ansible.cfg) = merge
DEFAULT_MODULE_PATH(env: ANSIBLE_LIBRARY) = ['/Users/dan/src/ansible/library']
```

##### OS / ENVIRONMENT
OS X --> OS X

##### STEPS TO REPRODUCE
- run `./hacking/test-module -m ./lib/ansible/modules/packaging/os/homebrew_cask.py -a 'name=virtualbox state=installed'`

##### EXPECTED RESULTS
The module runs as expected.

##### ACTUAL RESULTS
Module sees and fails to handle an `_ansible_tmp` parameter.

```
* including generated source, if any, saving to: /Users/dan/.ansible_module_generated
* ansiballz module detected; extracted module source to: /Users/dan/debug_dir
***********************************
RAW OUTPUT

{"msg": "Unsupported parameters for (basic.py) module: _ansible_tmp Supported parameters include: accept_external_apps, ansible_password, install_options, name, path, state, update_homebrew, upgrade_all", "failed": true, "invocation": {"module_args": {"state": "installed", "_ansible_tmp": "/Users/dan/.ansible/tmp/ansible-local-2618r53wit6l", "name": "virtualbox"}}}


***********************************
PARSED OUTPUT
{
    "failed": true,
    "invocation": {
        "module_args": {
            "_ansible_tmp": "/Users/dan/.ansible/tmp/ansible-local-2618r53wit6l",
            "name": "virtualbox",
            "state": "installed"
        }
    },
    "msg": "Unsupported parameters for (basic.py) module: _ansible_tmp Supported parameters include: accept_external_apps, ansible_password, install_options, name, path, state, update_homebrew, upgrade_all"
}
```

Hints from issue discussion:
Files identified in the description:
* [lib/ansible/modules/packaging/os/homebrew_cask.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/packaging/os/homebrew_cask.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @enriclluelles @indrajitr
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
it is normal to have one or more `_ansible_<x>` keys which are used by `AnsibleModule` internally.
@webknjaz can you please investigate this?
I believe `_ansible_tmp` just needs renamed to `_ansible_tmpdir` in `test-module`.
> I believe `_ansible_tmp` just needs renamed to `_ansible_tmpdir` in `test-module`.

And I confirm that this fixes the issue.

Commit message: Fix the file doesn't access bug in freebsd

Prior to this change, test-module will raise "No such file" error since freebsd doesn't have /usr/bin/python.

Patch to review:
diff --git a/hacking/test-module b/hacking/test-module
index c07d973fe12138..c56b8b72166626 100755
--- a/hacking/test-module
+++ b/hacking/test-module
@@ -125,7 +125,7 @@ def boilerplate_module(modfile, args, interpreters, check, destfile):
 
     # default selinux fs list is pass in as _ansible_selinux_special_fs arg
     complex_args['_ansible_selinux_special_fs'] = C.DEFAULT_SELINUX_SPECIAL_FS
-    complex_args['_ansible_tmp'] = C.DEFAULT_LOCAL_TMP
+    complex_args['_ansible_tmpdir'] = C.DEFAULT_LOCAL_TMP
     complex_args['_ansible_keep_remote_files'] = C.DEFAULT_KEEP_REMOTE_FILES
 
     if args.startswith("@"):
diff --git a/test/integration/targets/test_infra/runme.sh b/test/integration/targets/test_infra/runme.sh
index a0951ad2b58c1c..bc273d2d9026b3 100755
--- a/test/integration/targets/test_infra/runme.sh
+++ b/test/integration/targets/test_infra/runme.sh
@@ -21,3 +21,7 @@ echo "rc was $APB_RC (must be non-zero)"
 echo "ensure playbook output shows assert/fail works (True)"
 echo "$PB_OUT" | grep -F "fail works (True)" || exit 1
 echo "$PB_OUT" | grep -F "assert works (True)" || exit 1
+
+# ensure test-module script works well
+PING_MODULE_PATH="$(pwd)/../../../../lib/ansible/modules/system/ping.py"
+../../../../hacking/test-module -m "$PING_MODULE_PATH" -I ansible_python_interpreter=$(which python)


Code review comments:
diff_hunk: @@ -21,3 +21,7 @@ echo "rc was $APB_RC (must be non-zero)"
 echo "ensure playbook output shows assert/fail works (True)"
 echo "$PB_OUT" | grep -F "fail works (True)" || exit 1
 echo "$PB_OUT" | grep -F "assert works (True)" || exit 1
+
+# ensure test-module script works well
+PING_MODULE_PATH="$(pwd)/../../../../lib/ansible/modules/system/ping.py"
+../../../../hacking/test-module -m "$PING_MODULE_PATH" -I ansible_python_interpreter=$(which python)
path: test/integration/targets/test_infra/runme.sh
text: @user1:
> test/integration/targets/test_infra/runme.sh:27:86: SC2046 Quote this to prevent word splitting.

@author this linter message means that in the event of command in `$(...)` expression returning smth with space the command fill likely break. For example, if it returns `/usr/bin/env python` it will result in smth like `...  -I ansible_python_interpreter=/usr/bin/env python`, which is not what you want. Instead, you expect all of it to go to the same arg, like `...  -I ansible_python_interpreter="/usr/bin/env python"`.

To fix this, just wrap argument with double quotes `"` (single quotes prevent bash expression interpolation, which will break things).