Skip to content

Commit

Permalink
[stable-2.10] Support collection constraints in ansible-test. (#72157)
Browse files Browse the repository at this point in the history
This allows collections to specify requirements and constraints for packages that ansible-test has requirements or constraints for.
(cherry picked from commit 5f76bd2)

Co-authored-by: Matt Clay <matt@mystile.com>
  • Loading branch information
mattclay and mattclay committed Oct 8, 2020
1 parent f57b149 commit 49504da
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 0 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/ansible-test-collection-constraints.yml
@@ -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 @@
botocore == 1.13.49
@@ -0,0 +1 @@
botocore
@@ -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 @@
botocore == 1.13.50
@@ -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 @@
botocore
@@ -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[@]}"
12 changes: 12 additions & 0 deletions test/lib/ansible_test/_internal/executor.py
Expand Up @@ -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')
requirements = os.path.join(ANSIBLE_TEST_DATA_ROOT, 'requirements', '%s.txt' % ('%s.%s' % (command, context) if context else command))
content_constraints = None

options = []

Expand All @@ -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):
options += ['-r', requirements]

content_constraints = os.path.join(data_context().content.unit_path, 'constraints.txt')

if command in ('integration', 'windows-integration', 'network-integration'):
requirements = os.path.join(data_context().content.integration_path, 'requirements.txt')

Expand All @@ -459,13 +462,22 @@ def generate_pip_install(pip, command, packages=None, constraints=None, use_cons
if os.path.exists(requirements) and os.path.getsize(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:
options += packages

if not options:
return None

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])

return pip + ['install', '--disable-pip-version-check'] + options
Expand Down

0 comments on commit 49504da

Please sign in to comment.