summaryrefslogtreecommitdiff
path: root/test/integration/targets/infra
diff options
context:
space:
mode:
authorMatt Clay <mclay@redhat.com>2020-03-19 22:05:43 -0700
committerGitHub <noreply@github.com>2020-03-19 22:05:43 -0700
commit383ef3ea80bcb269d10b4fb2be23c7146d78242d (patch)
tree6d1d312b0c83a92d8cd347f5ce0a01632eaf8a00 /test/integration/targets/infra
parent0ca3feb8616c54a445e608a5f5470cb421bcf1f0 (diff)
downloadansible-383ef3ea80bcb269d10b4fb2be23c7146d78242d.tar.gz
Rename tests (#68356)
* Rename `tests` test to match plugin type. * Rename `test_infra` test to avoid confusion. This test target is not a test for test plugins. * Rename `vars_prompt` test to avoid confusion. * Update sanity ignores.
Diffstat (limited to 'test/integration/targets/infra')
-rw-r--r--test/integration/targets/infra/aliases3
-rw-r--r--test/integration/targets/infra/inventory.local2
-rw-r--r--test/integration/targets/infra/library/test.py21
-rwxr-xr-xtest/integration/targets/infra/runme.sh39
-rw-r--r--test/integration/targets/infra/test_test_infra.yml25
5 files changed, 90 insertions, 0 deletions
diff --git a/test/integration/targets/infra/aliases b/test/integration/targets/infra/aliases
new file mode 100644
index 0000000000..d342950a28
--- /dev/null
+++ b/test/integration/targets/infra/aliases
@@ -0,0 +1,3 @@
+shippable/posix/group3
+needs/file/hacking/test-module.py
+needs/file/lib/ansible/modules/system/ping.py
diff --git a/test/integration/targets/infra/inventory.local b/test/integration/targets/infra/inventory.local
new file mode 100644
index 0000000000..2baa1f88fb
--- /dev/null
+++ b/test/integration/targets/infra/inventory.local
@@ -0,0 +1,2 @@
+testhost ansible_connection=local
+
diff --git a/test/integration/targets/infra/library/test.py b/test/integration/targets/infra/library/test.py
new file mode 100644
index 0000000000..9386057517
--- /dev/null
+++ b/test/integration/targets/infra/library/test.py
@@ -0,0 +1,21 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+from ansible.module_utils.basic import AnsibleModule
+
+
+def main():
+ module = AnsibleModule(
+ argument_spec=dict(),
+ )
+ result = {
+ 'selinux_special_fs': module._selinux_special_fs,
+ 'tmpdir': module._tmpdir,
+ 'keep_remote_files': module._keep_remote_files,
+ 'version': module.ansible_version,
+ }
+ module.exit_json(**result)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/test/integration/targets/infra/runme.sh b/test/integration/targets/infra/runme.sh
new file mode 100755
index 0000000000..7996a43140
--- /dev/null
+++ b/test/integration/targets/infra/runme.sh
@@ -0,0 +1,39 @@
+#!/usr/bin/env bash
+
+set -ux
+
+# ensure fail/assert work locally and can stop execution with non-zero exit code
+PB_OUT=$(ansible-playbook -i inventory.local test_test_infra.yml)
+APB_RC=$?
+echo "$PB_OUT"
+echo "rc was $APB_RC (must be non-zero)"
+[ ${APB_RC} -ne 0 ]
+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 we work using all specified test args, overridden inventory, etc
+PB_OUT=$(ansible-playbook -i ../../inventory test_test_infra.yml "$@")
+APB_RC=$?
+echo "$PB_OUT"
+echo "rc was $APB_RC (must be non-zero)"
+[ ${APB_RC} -ne 0 ]
+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
+
+set -e
+
+PING_MODULE_PATH="../../../../lib/ansible/modules/system/ping.py"
+
+# ensure test-module.py script works without passing Python interpreter path
+../../../../hacking/test-module.py -m "$PING_MODULE_PATH"
+
+# ensure test-module.py script works well
+../../../../hacking/test-module.py -m "$PING_MODULE_PATH" -I ansible_python_interpreter="$(which python)"
+
+# ensure module.ansible_version is defined when using test-module.py
+../../../../hacking/test-module.py -m library/test.py -I ansible_python_interpreter="$(which python)" <<< '{"ANSIBLE_MODULE_ARGS": {}}'
+
+# ensure exercising module code locally works
+python -m ansible.modules.files.file <<< '{"ANSIBLE_MODULE_ARGS": {"path": "/path/to/file", "state": "absent"}}'
diff --git a/test/integration/targets/infra/test_test_infra.yml b/test/integration/targets/infra/test_test_infra.yml
new file mode 100644
index 0000000000..706f9b8fca
--- /dev/null
+++ b/test/integration/targets/infra/test_test_infra.yml
@@ -0,0 +1,25 @@
+- hosts: testhost
+ gather_facts: no
+ tags:
+ - always
+ tasks:
+ - name: ensure fail action produces a failing result
+ fail:
+ ignore_errors: yes
+ register: fail_out
+
+ - debug:
+ msg: fail works ({{ fail_out.failed }})
+
+ - name: ensure assert produces a failing result
+ assert:
+ that: false
+ ignore_errors: yes
+ register: assert_out
+
+ - debug:
+ msg: assert works ({{ assert_out.failed }})
+
+ - name: EXPECTED FAILURE ensure fail action stops execution
+ fail:
+ msg: fail actually failed (this is expected)