mirror of https://github.com/ansible/ansible.git
Overhaul ansible-test integration tests. (#76111)
* Overhaul ansible-test integration tests. * ansible-test - Fix import test pyyaml usage. * ansible-test - Remove unused import. * ansible-test - Fix traceback when pip is unavailable. * ansible-test - Fix typo in port forwarding message. * ansible-test - Fix controller logic in requirements install. * Fix unit tests in ansible-test integration test. Unit tests are now run for available Python versions which provide `virtualenv` (Python 2.x) or `venv` (Python 3.x).pull/76137/head
parent
b9694ce4fb
commit
cae7d2a671
@ -0,0 +1,3 @@
|
|||||||
|
bugfixes:
|
||||||
|
- ansible-test - Target integration test requirements are now correctly installed for target environments running on the controller.
|
||||||
|
- ansible-test - Automatic target requirements installation is now based on the target environment instead of the controller environment.
|
@ -0,0 +1,2 @@
|
|||||||
|
bugfixes:
|
||||||
|
- ansible-test - Fix traceback in ``import`` sanity test on Python 2.7 when ``pip`` is not available.
|
@ -0,0 +1,2 @@
|
|||||||
|
bugfixes:
|
||||||
|
- ansible-test - Fix installation and usage of ``pyyaml`` requirement for the ``import`` sanity test for collections.
|
@ -1,2 +1,3 @@
|
|||||||
shippable/posix/group1
|
shippable/posix/group1 # runs in the distro test containers
|
||||||
|
shippable/generic/group1 # runs in the default test container
|
||||||
context/controller
|
context/controller
|
||||||
|
@ -1,20 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
set -eux -o pipefail
|
|
||||||
|
|
||||||
cp -a "${TEST_DIR}/ansible_collections" "${WORK_DIR}"
|
|
||||||
cd "${WORK_DIR}/ansible_collections/ns/col_constraints"
|
|
||||||
|
|
||||||
# common args for all tests
|
|
||||||
# each test will be run in a separate venv to verify that requirements have been properly specified
|
|
||||||
common=(--venv --python "${ANSIBLE_TEST_PYTHON_VERSION}" --color --truncate 0 "${@}")
|
|
||||||
|
|
||||||
# unit tests
|
|
||||||
|
|
||||||
rm -rf "tests/output"
|
|
||||||
ansible-test units "${common[@]}"
|
|
||||||
|
|
||||||
# integration tests
|
|
||||||
|
|
||||||
rm -rf "tests/output"
|
|
||||||
ansible-test integration "${common[@]}"
|
|
@ -0,0 +1,8 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -eux -o pipefail
|
||||||
|
|
||||||
|
cp -a "${TEST_DIR}/ansible_collections" "${WORK_DIR}"
|
||||||
|
cd "${WORK_DIR}/ansible_collections/ns/col_constraints"
|
||||||
|
|
||||||
|
ansible-test integration --venv --color --truncate 0 "${@}"
|
@ -0,0 +1,8 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -eux -o pipefail
|
||||||
|
|
||||||
|
cp -a "${TEST_DIR}/ansible_collections" "${WORK_DIR}"
|
||||||
|
cd "${WORK_DIR}/ansible_collections/ns/col"
|
||||||
|
|
||||||
|
ansible-test integration --venv --color --truncate 0 "${@}"
|
@ -0,0 +1,10 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -eux -o pipefail
|
||||||
|
|
||||||
|
cp -a "${TEST_DIR}/ansible_collections" "${WORK_DIR}"
|
||||||
|
cd "${WORK_DIR}/ansible_collections/ns/col"
|
||||||
|
|
||||||
|
"${TEST_DIR}/collection-tests/update-ignore.py"
|
||||||
|
|
||||||
|
ansible-test sanity --color --truncate 0 "${@}"
|
@ -0,0 +1,11 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -eux -o pipefail
|
||||||
|
|
||||||
|
cp -a "${TEST_DIR}/ansible_collections" "${WORK_DIR}"
|
||||||
|
cd "${WORK_DIR}/ansible_collections/ns/col_constraints"
|
||||||
|
|
||||||
|
options=$("${TEST_DIR}"/collection-tests/venv-pythons.py)
|
||||||
|
IFS=', ' read -r -a pythons <<< "${options}"
|
||||||
|
|
||||||
|
ansible-test units --color --truncate 0 "${pythons[@]}" "${@}"
|
@ -0,0 +1,11 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -eux -o pipefail
|
||||||
|
|
||||||
|
cp -a "${TEST_DIR}/ansible_collections" "${WORK_DIR}"
|
||||||
|
cd "${WORK_DIR}/ansible_collections/ns/col"
|
||||||
|
|
||||||
|
options=$("${TEST_DIR}"/collection-tests/venv-pythons.py)
|
||||||
|
IFS=', ' read -r -a pythons <<< "${options}"
|
||||||
|
|
||||||
|
ansible-test units --color --truncate 0 "${pythons[@]}" "${@}"
|
@ -0,0 +1,51 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
"""Rewrite a sanity ignore file to expand Python versions for import ignores and write the file out with the correct Ansible version in the name."""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from ansible import release
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
ansible_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(release.__file__))))
|
||||||
|
source_root = os.path.join(ansible_root, 'test', 'lib')
|
||||||
|
|
||||||
|
sys.path.insert(0, source_root)
|
||||||
|
|
||||||
|
from ansible_test._internal import constants
|
||||||
|
|
||||||
|
src_path = 'tests/sanity/ignore.txt'
|
||||||
|
directory = os.path.dirname(src_path)
|
||||||
|
name, ext = os.path.splitext(os.path.basename(src_path))
|
||||||
|
major_minor = '.'.join(release.__version__.split('.')[:2])
|
||||||
|
dst_path = os.path.join(directory, f'{name}-{major_minor}{ext}')
|
||||||
|
|
||||||
|
with open(src_path) as src_file:
|
||||||
|
src_lines = src_file.read().splitlines()
|
||||||
|
|
||||||
|
dst_lines = []
|
||||||
|
|
||||||
|
for line in src_lines:
|
||||||
|
path, rule = line.split(' ')
|
||||||
|
|
||||||
|
if rule != 'import':
|
||||||
|
dst_lines.append(line)
|
||||||
|
continue
|
||||||
|
|
||||||
|
if path.startswith('plugins/module'):
|
||||||
|
python_versions = constants.SUPPORTED_PYTHON_VERSIONS
|
||||||
|
else:
|
||||||
|
python_versions = constants.CONTROLLER_PYTHON_VERSIONS
|
||||||
|
|
||||||
|
for python_version in python_versions:
|
||||||
|
dst_lines.append(f'{line}-{python_version}')
|
||||||
|
|
||||||
|
ignores = '\n'.join(dst_lines) + '\n'
|
||||||
|
|
||||||
|
with open(dst_path, 'w') as dst_file:
|
||||||
|
dst_file.write(ignores)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@ -0,0 +1,42 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
"""Return target Python options for use with ansible-test."""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from ansible import release
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
ansible_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(release.__file__))))
|
||||||
|
source_root = os.path.join(ansible_root, 'test', 'lib')
|
||||||
|
|
||||||
|
sys.path.insert(0, source_root)
|
||||||
|
|
||||||
|
from ansible_test._internal import constants
|
||||||
|
|
||||||
|
args = []
|
||||||
|
|
||||||
|
for python_version in constants.SUPPORTED_PYTHON_VERSIONS:
|
||||||
|
executable = shutil.which(f'python{python_version}')
|
||||||
|
|
||||||
|
if executable:
|
||||||
|
if python_version.startswith('2.'):
|
||||||
|
cmd = [executable, '-m', 'virtualenv', '--version']
|
||||||
|
else:
|
||||||
|
cmd = [executable, '-m', 'venv', '--help']
|
||||||
|
|
||||||
|
process = subprocess.run(cmd, capture_output=True, check=False)
|
||||||
|
|
||||||
|
print(f'{executable} - {"fail" if process.returncode else "pass"}', file=sys.stderr)
|
||||||
|
|
||||||
|
if not process.returncode:
|
||||||
|
args.extend(['--target-python', f'venv/{python_version}'])
|
||||||
|
|
||||||
|
print(' '.join(args))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@ -1,49 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
set -eux -o pipefail
|
|
||||||
|
|
||||||
cp -a "${TEST_DIR}/ansible_collections" "${WORK_DIR}"
|
|
||||||
cd "${WORK_DIR}/ansible_collections/ns/col"
|
|
||||||
|
|
||||||
# rename the sanity ignore file to match the current ansible version and update import ignores with the python version
|
|
||||||
ansible_version="$(python -c 'import ansible.release; print(".".join(ansible.release.__version__.split(".")[:2]))')"
|
|
||||||
if [[ "${ANSIBLE_TEST_PYTHON_VERSION}" =~ ^2\. ]] || [[ "${ANSIBLE_TEST_PYTHON_VERSION}" =~ ^3\.[567] ]]; then
|
|
||||||
# Non-module/module_utils plugins are not checked on these remote-only Python versions
|
|
||||||
sed "s/ import$/ import-${ANSIBLE_TEST_PYTHON_VERSION}/;" < "tests/sanity/ignore.txt" | grep -v 'plugins/[^m].* import' > "tests/sanity/ignore-${ansible_version}.txt"
|
|
||||||
else
|
|
||||||
sed "s/ import$/ import-${ANSIBLE_TEST_PYTHON_VERSION}/;" < "tests/sanity/ignore.txt" > "tests/sanity/ignore-${ansible_version}.txt"
|
|
||||||
fi
|
|
||||||
cat "tests/sanity/ignore-${ansible_version}.txt"
|
|
||||||
|
|
||||||
# common args for all tests
|
|
||||||
# each test will be run in a separate venv to verify that requirements have been properly specified
|
|
||||||
common=(--venv --python "${ANSIBLE_TEST_PYTHON_VERSION}" --color --truncate 0 "${@}")
|
|
||||||
|
|
||||||
# sanity tests
|
|
||||||
|
|
||||||
tests=()
|
|
||||||
|
|
||||||
set +x
|
|
||||||
|
|
||||||
while IFS='' read -r line; do
|
|
||||||
tests+=("$line");
|
|
||||||
done < <(
|
|
||||||
ansible-test sanity --list-tests
|
|
||||||
)
|
|
||||||
|
|
||||||
set -x
|
|
||||||
|
|
||||||
for test in "${tests[@]}"; do
|
|
||||||
rm -rf "tests/output"
|
|
||||||
ansible-test sanity "${common[@]}" --test "${test}"
|
|
||||||
done
|
|
||||||
|
|
||||||
# unit tests
|
|
||||||
|
|
||||||
rm -rf "tests/output"
|
|
||||||
ansible-test units "${common[@]}"
|
|
||||||
|
|
||||||
# integration tests
|
|
||||||
|
|
||||||
rm -rf "tests/output"
|
|
||||||
ansible-test integration "${common[@]}"
|
|
@ -0,0 +1 @@
|
|||||||
|
pyyaml == 5.4.1 # needed for yaml_to_json.py
|
Loading…
Reference in New Issue