Support collection constraints in ansible-test.

This allows collections to specify requirements and constraints for packages that ansible-test has requirements or constraints for.
pull/72163/head
Matt Clay 4 years ago
parent 2f8dbf673e
commit 5f76bd2af7

@ -0,0 +1,2 @@
minor_changes:
- ansible-test - Collections can now specify pip constraints for unit and integration test requirements using ``tests/unit/constraints.txt`` and ``tests/integration/constraints.txt`` respectively.

@ -0,0 +1,7 @@
- name: get botocore version
command: python -c "import botocore; print(botocore.__version__)"
register: botocore_version
- name: check botocore version
assert:
that:
- 'botocore_version.stdout == "1.13.49"'

@ -0,0 +1,8 @@
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import botocore
def test_constraints():
assert botocore.__version__ == '1.13.50'

@ -0,0 +1,20 @@
#!/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[@]}"

@ -430,6 +430,7 @@ def generate_pip_install(pip, command, packages=None, constraints=None, use_cons
""" """
constraints = constraints or os.path.join(ANSIBLE_TEST_DATA_ROOT, 'requirements', 'constraints.txt') constraints = constraints or os.path.join(ANSIBLE_TEST_DATA_ROOT, 'requirements', 'constraints.txt')
requirements = os.path.join(ANSIBLE_TEST_DATA_ROOT, 'requirements', '%s.txt' % ('%s.%s' % (command, context) if context else command)) requirements = os.path.join(ANSIBLE_TEST_DATA_ROOT, 'requirements', '%s.txt' % ('%s.%s' % (command, context) if context else command))
content_constraints = None
options = [] options = []
@ -448,6 +449,8 @@ def generate_pip_install(pip, command, packages=None, constraints=None, use_cons
if os.path.exists(requirements) and os.path.getsize(requirements): if os.path.exists(requirements) and os.path.getsize(requirements):
options += ['-r', requirements] options += ['-r', requirements]
content_constraints = os.path.join(data_context().content.unit_path, 'constraints.txt')
if command in ('integration', 'windows-integration', 'network-integration'): if command in ('integration', 'windows-integration', 'network-integration'):
requirements = os.path.join(data_context().content.integration_path, 'requirements.txt') requirements = os.path.join(data_context().content.integration_path, 'requirements.txt')
@ -459,6 +462,11 @@ def generate_pip_install(pip, command, packages=None, constraints=None, use_cons
if os.path.exists(requirements) and os.path.getsize(requirements): if os.path.exists(requirements) and os.path.getsize(requirements):
options += ['-r', requirements] options += ['-r', requirements]
content_constraints = os.path.join(data_context().content.integration_path, 'constraints.txt')
if command.startswith('integration.cloud.'):
content_constraints = os.path.join(data_context().content.integration_path, 'constraints.txt')
if packages: if packages:
options += packages options += packages
@ -466,6 +474,10 @@ def generate_pip_install(pip, command, packages=None, constraints=None, use_cons
return None return None
if use_constraints: if use_constraints:
if content_constraints and os.path.exists(content_constraints) and os.path.getsize(content_constraints):
# listing content constraints first gives them priority over constraints provided by ansible-test
options.extend(['-c', content_constraints])
options.extend(['-c', constraints]) options.extend(['-c', constraints])
return pip + ['install', '--disable-pip-version-check'] + options return pip + ['install', '--disable-pip-version-check'] + options

Loading…
Cancel
Save