diff options
author | Matt Clay <mclay@redhat.com> | 2020-03-20 06:05:43 +0100 |
---|---|---|
committer | Matt Martz <matt@sivel.net> | 2020-03-23 17:14:21 +0100 |
commit | 5a1b59adf9d4638beecae2cbd4392ece4e20792b (patch) | |
tree | 6d1d312b0c83a92d8cd347f5ce0a01632eaf8a00 /test/integration/targets/builtin_vars_prompt | |
parent | Fix ansible-test import analysis for collections. (#68352) (diff) | |
download | ansible-5a1b59adf9d4638beecae2cbd4392ece4e20792b.tar.xz ansible-5a1b59adf9d4638beecae2cbd4392ece4e20792b.zip |
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/builtin_vars_prompt')
12 files changed, 284 insertions, 0 deletions
diff --git a/test/integration/targets/builtin_vars_prompt/aliases b/test/integration/targets/builtin_vars_prompt/aliases new file mode 100644 index 0000000000..4317d11262 --- /dev/null +++ b/test/integration/targets/builtin_vars_prompt/aliases @@ -0,0 +1,3 @@ +setup/always/setup_passlib +setup/always/setup_pexpect +shippable/posix/group4 diff --git a/test/integration/targets/builtin_vars_prompt/runme.sh b/test/integration/targets/builtin_vars_prompt/runme.sh new file mode 100755 index 0000000000..af5557940e --- /dev/null +++ b/test/integration/targets/builtin_vars_prompt/runme.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +set -eux + +# Interactively test vars_prompt +python test-vars_prompt.py -i ../../inventory "$@" diff --git a/test/integration/targets/builtin_vars_prompt/test-vars_prompt.py b/test/integration/targets/builtin_vars_prompt/test-vars_prompt.py new file mode 100644 index 0000000000..6c805fdd90 --- /dev/null +++ b/test/integration/targets/builtin_vars_prompt/test-vars_prompt.py @@ -0,0 +1,127 @@ +#!/usr/bin/env python + +import os +import pexpect +import sys + +from ansible.module_utils.six import PY2 + +if PY2: + log_buffer = sys.stdout +else: + log_buffer = sys.stdout.buffer + +env_vars = { + 'ANSIBLE_ROLES_PATH': './roles', + 'ANSIBLE_NOCOLOR': 'True', + 'ANSIBLE_RETRY_FILES_ENABLED': 'False', +} + + +def run_test(playbook, test_spec, args=None, timeout=10, env=None): + + if not env: + env = os.environ.copy() + env.update(env_vars) + + if not args: + args = sys.argv[1:] + + vars_prompt_test = pexpect.spawn( + 'ansible-playbook', + args=[playbook] + args, + timeout=timeout, + env=env, + ) + + vars_prompt_test.logfile = log_buffer + for item in test_spec[0]: + vars_prompt_test.expect(item[0]) + if item[1]: + vars_prompt_test.send(item[1]) + vars_prompt_test.expect(test_spec[1]) + vars_prompt_test.expect(pexpect.EOF) + vars_prompt_test.close() + + +# These are the tests to run. Each test is a playbook and a test_spec. +# +# The test_spec is a list with two elements. +# +# The first element is a list of two element tuples. The first is the regexp to look +# for in the output, the second is the line to send. +# +# The last element is the last string of text to look for in the output. +# +tests = [ + # Basic vars_prompt + {'playbook': 'vars_prompt-1.yml', + 'test_spec': [ + [('input:', 'some input\r')], + '"input": "some input"']}, + + # Custom prompt + {'playbook': 'vars_prompt-2.yml', + 'test_spec': [ + [('Enter some input:', 'some more input\r')], + '"input": "some more input"']}, + + # Test confirm, both correct and incorrect + {'playbook': 'vars_prompt-3.yml', + 'test_spec': [ + [('input:', 'confirm me\r'), + ('confirm input:', 'confirm me\r')], + '"input": "confirm me"']}, + + {'playbook': 'vars_prompt-3.yml', + 'test_spec': [ + [('input:', 'confirm me\r'), + ('confirm input:', 'incorrect\r'), + (r'\*\*\*\*\* VALUES ENTERED DO NOT MATCH \*\*\*\*', ''), + ('input:', 'confirm me\r'), + ('confirm input:', 'confirm me\r')], + '"input": "confirm me"']}, + + # Test private + {'playbook': 'vars_prompt-4.yml', + 'test_spec': [ + [('not_secret', 'this is displayed\r'), + ('this is displayed', '')], + '"not_secret": "this is displayed"']}, + + # Test hashing + {'playbook': 'vars_prompt-5.yml', + 'test_spec': [ + [('password', 'Scenic-Improving-Payphone\r'), + ('confirm password', 'Scenic-Improving-Payphone\r')], + r'"password": "\$6\$']}, + + # Test variables in prompt field + # https://github.com/ansible/ansible/issues/32723 + {'playbook': 'vars_prompt-6.yml', + 'test_spec': [ + [('prompt from variable:', 'input\r')], + '']}, + + # Test play vars coming from vars_prompt + # https://github.com/ansible/ansible/issues/37984 + {'playbook': 'vars_prompt-7.yml', + 'test_spec': [ + [('prompting for host:', 'testhost\r')], + r'testhost.*ok=1']}, + + # Test play unsafe toggle + {'playbook': 'unsafe.yml', + 'test_spec': [ + [('prompting for variable:', '{{whole}}\r')], + r'testhost.*ok=2']}, + + # Test unsupported keys + {'playbook': 'unsupported.yml', + 'test_spec': [ + [], + "Invalid vars_prompt data structure, found unsupported key 'when'"]}, +] + +for t in tests: + run_test(playbook=t['playbook'], test_spec=t['test_spec']) diff --git a/test/integration/targets/builtin_vars_prompt/unsafe.yml b/test/integration/targets/builtin_vars_prompt/unsafe.yml new file mode 100644 index 0000000000..348ce152d6 --- /dev/null +++ b/test/integration/targets/builtin_vars_prompt/unsafe.yml @@ -0,0 +1,20 @@ +- name: Test vars_prompt unsafe + hosts: testhost + become: no + gather_facts: no + vars: + whole: INVALID + vars_prompt: + - name: input + prompt: prompting for variable + unsafe: true + + tasks: + - name: + assert: + that: + - input != whole + - input != 'INVALID' + + - debug: + var: input diff --git a/test/integration/targets/builtin_vars_prompt/unsupported.yml b/test/integration/targets/builtin_vars_prompt/unsupported.yml new file mode 100644 index 0000000000..eab02fd64f --- /dev/null +++ b/test/integration/targets/builtin_vars_prompt/unsupported.yml @@ -0,0 +1,18 @@ +- name: Test vars_prompt unsupported key + hosts: testhost + become: no + gather_facts: no + vars_prompt: + - name: input + prompt: prompting for variable + # Unsupported key for vars_prompt + when: foo is defined + + tasks: + - name: + assert: + that: + - input is not defined + + - debug: + var: input diff --git a/test/integration/targets/builtin_vars_prompt/vars_prompt-1.yml b/test/integration/targets/builtin_vars_prompt/vars_prompt-1.yml new file mode 100644 index 0000000000..727c60e7fa --- /dev/null +++ b/test/integration/targets/builtin_vars_prompt/vars_prompt-1.yml @@ -0,0 +1,15 @@ +- name: Basic vars_prompt test + hosts: testhost + become: no + gather_facts: no + + vars_prompt: + - name: input + + tasks: + - assert: + that: + - input == 'some input' + + - debug: + var: input diff --git a/test/integration/targets/builtin_vars_prompt/vars_prompt-2.yml b/test/integration/targets/builtin_vars_prompt/vars_prompt-2.yml new file mode 100644 index 0000000000..d8f20db801 --- /dev/null +++ b/test/integration/targets/builtin_vars_prompt/vars_prompt-2.yml @@ -0,0 +1,16 @@ +- name: Test vars_prompt custom prompt + hosts: testhost + become: no + gather_facts: no + + vars_prompt: + - name: input + prompt: "Enter some input" + + tasks: + - assert: + that: + - input == 'some more input' + + - debug: + var: input diff --git a/test/integration/targets/builtin_vars_prompt/vars_prompt-3.yml b/test/integration/targets/builtin_vars_prompt/vars_prompt-3.yml new file mode 100644 index 0000000000..f8148182b8 --- /dev/null +++ b/test/integration/targets/builtin_vars_prompt/vars_prompt-3.yml @@ -0,0 +1,17 @@ +- name: Test vars_prompt confirm + hosts: testhost + become: no + gather_facts: no + + vars_prompt: + - name: input + confirm: yes + + tasks: + - name: + assert: + that: + - input == 'confirm me' + + - debug: + var: input diff --git a/test/integration/targets/builtin_vars_prompt/vars_prompt-4.yml b/test/integration/targets/builtin_vars_prompt/vars_prompt-4.yml new file mode 100644 index 0000000000..d33cc90215 --- /dev/null +++ b/test/integration/targets/builtin_vars_prompt/vars_prompt-4.yml @@ -0,0 +1,16 @@ +- name: Test vars_prompt not private + hosts: testhost + become: no + gather_facts: no + + vars_prompt: + - name: not_secret + private: no + + tasks: + - assert: + that: + - not_secret == 'this is displayed' + + - debug: + var: not_secret diff --git a/test/integration/targets/builtin_vars_prompt/vars_prompt-5.yml b/test/integration/targets/builtin_vars_prompt/vars_prompt-5.yml new file mode 100644 index 0000000000..62c8ad8efa --- /dev/null +++ b/test/integration/targets/builtin_vars_prompt/vars_prompt-5.yml @@ -0,0 +1,14 @@ +- name: Test vars_prompt hashing + hosts: testhost + become: no + gather_facts: no + + vars_prompt: + - name: password + confirm: yes + encrypt: sha512_crypt + salt: 'jESIyad4F08hP3Ta' + + tasks: + - debug: + var: password diff --git a/test/integration/targets/builtin_vars_prompt/vars_prompt-6.yml b/test/integration/targets/builtin_vars_prompt/vars_prompt-6.yml new file mode 100644 index 0000000000..ea3fe6209c --- /dev/null +++ b/test/integration/targets/builtin_vars_prompt/vars_prompt-6.yml @@ -0,0 +1,20 @@ +- name: Test vars_prompt custom variables in prompt + hosts: testhost + become: no + gather_facts: no + + vars: + prompt_var: prompt from variable + + vars_prompt: + - name: input + prompt: "{{ prompt_var }}" + + tasks: + - name: + assert: + that: + - input == 'input' + + - debug: + var: input diff --git a/test/integration/targets/builtin_vars_prompt/vars_prompt-7.yml b/test/integration/targets/builtin_vars_prompt/vars_prompt-7.yml new file mode 100644 index 0000000000..a6b086d0d7 --- /dev/null +++ b/test/integration/targets/builtin_vars_prompt/vars_prompt-7.yml @@ -0,0 +1,12 @@ +- name: Test vars_prompt play vars + hosts: "{{ target_hosts }}" + become: no + gather_facts: no + + vars_prompt: + - name: target_hosts + prompt: prompting for host + private: no + + tasks: + - ping: |