Fix incorrect assumptions in integration tests. (#58365)

* Fix nested template test.

There were two issues with the previous implementation:

1. The LOGNAME environment variable may not be set.
2. The comparison assumed that testhost is localhost.

* Fix variable display for cartesian lookup test.

* Fix vars list test.

The test assumed that the ansible_user variable is always set,
which is not guaranteed when using connections other than local.

* Fix supervisorctl integration test.

Use ansible_user_id instead of ansible_user since ansible_user
is not guaranteed to be available when the connection is not local.

* Fix file integration test.

Use ansible_user_id instead of ansible_user since ansible_user
is not guaranteed to be available when the connection is not local.

* Fix expect integration test.

Do not assume module_utils is available for utility scripts.

* Fix python_requirements_info integration test.

Check for pip instead of ansible, since ansible is not guaranteed
to be installed when using a connection other than local.

* Fix ansible-runner integration test.

Use implicit localhost to run the test since it requires access
to the ansible installation currently being tested.

* Fix tower_common integration test.

Accept errors on stdout or stderr.

* Fix tower_user integration test.

Recognize errors on stdout or stderr.
This commit is contained in:
Matt Clay 2019-06-25 18:39:41 -07:00 committed by GitHub
parent c604e347b2
commit 013b0039ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 34 additions and 22 deletions

View file

@ -0,0 +1 @@
# no hosts required, test only requires implicit localhost

View file

@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -eux
ANSIBLE_ROLES_PATH=../ ansible-playbook test.yml -e '@../../integration_config.yml' -i inventory "$@"

View file

@ -0,0 +1,3 @@
- hosts: localhost
roles:
- ansible-runner

View file

@ -1,10 +1,12 @@
import sys
from ansible.module_utils.six.moves import input
try:
input_function = raw_input
except NameError:
input_function = input
prompts = sys.argv[1:] or ['foo']
for prompt in prompts:
user_input = input(prompt)
user_input = input_function(prompt)
print(user_input)

View file

@ -515,7 +515,7 @@
# https://github.com/ansible/ansible/issues/50943
# Need to use /tmp as nobody can't access output_dir at all
- name: create file as root with all write permissions
file: dest=/tmp/write_utime state=touch mode=0666 owner={{ansible_user}}
file: dest=/tmp/write_utime state=touch mode=0666 owner={{ansible_user_id}}
- name: Pause to ensure stat times are not the exact same
pause:

View file

@ -188,23 +188,24 @@
- name: set variable that clashes
set_fact:
LOGNAME: foobar
PATH: foobar
- name: get LOGNAME environment var value
shell: echo {{ '$LOGNAME' }}
register: known_var_value
- name: do the lookup for env LOGNAME
- name: get PATH environment var value
set_fact:
test_val: "{{ lookup('env', 'LOGNAME') }}"
known_var_value: "{{ lookup('pipe', 'echo $PATH') }}"
- name: do the lookup for env PATH
set_fact:
test_val: "{{ lookup('env', 'PATH') }}"
- debug: var=test_val
- name: compare values
assert:
that:
- "test_val == known_var_value.stdout"
- "test_val != ''"
- "test_val == known_var_value"
- name: set with_dict
@ -243,7 +244,7 @@
- "'{{ badssl_host_substring }}' in web_data"
- name: Test cartesian lookup
debug: var={{item}}
debug: var=item
with_cartesian:
- ["A", "B", "C"]
- ["1", "2", "3"]
@ -296,9 +297,9 @@
- name: Test that we can give a list of values to var and receive a list of values back
set_fact:
var_host_info: '{{ query("vars", "ansible_host", "ansible_user") }}'
var_host_info: '{{ query("vars", "ansible_host", "ansible_connection") }}'
- assert:
that:
- 'var_host_info[0] == ansible_host'
- 'var_host_info[1] == ansible_user'
- 'var_host_info[1] == ansible_connection'

View file

@ -12,11 +12,11 @@
python_requirements_info:
dependencies:
- notreal<1
- ansible>2
- pip>1
register: dep_info
- name: ensure python_requirements_info returns desired info
assert:
that:
- "'installed' in dep_info.valid.ansible"
- "'installed' in dep_info.valid.pip"
- "'notreal' in dep_info.not_found"

View file

@ -4,7 +4,7 @@ logfile={{ remote_dir }}/supervisord.log
[program:py1]
command={{ ansible_python.executable }} -i -u -
user={{ ansible_user }}
user={{ ansible_user_id }}
autostart=false
autorestart=false
stdout_logfile={{ remote_dir }}/py1.log
@ -12,7 +12,7 @@ redirect_stderr=yes
[program:py2]
command={{ ansible_python.executable }} -i -u -
user={{ ansible_user }}
user={{ ansible_user_id }}
autostart=false
autorestart=false
stdout_logfile={{ remote_dir }}/py2.log

View file

@ -21,8 +21,8 @@
that:
- check_ssl_is_used is failed
- >
'Could not establish a secure connection' in check_ssl_is_used.module_stderr
or 'OpenSSL.SSL.Error' in check_ssl_is_used.module_stderr
'Could not establish a secure connection' in (check_ssl_is_used.module_stderr + check_ssl_is_used.module_stdout)
or 'OpenSSL.SSL.Error' in (check_ssl_is_used.module_stderr + check_ssl_is_used.module_stdout)
# 'Could not establish a secure connection': when pyOpenSSL isn't available
# 'OpenSSL.SSL.Error': with pyOpenSSL, see https://github.com/urllib3/urllib3/pull/1517

View file

@ -90,4 +90,4 @@
- assert:
that:
- "'not verify ssl with non-https protocol' in result.exception"
- "'not verify ssl with non-https protocol' in (result.module_stdout + result.module_stderr)"