From 5f76bd2af7deb2a04e0415b54be263f5c9b22a07 Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Thu, 8 Oct 2020 08:51:26 -0700 Subject: [PATCH] Support collection constraints in ansible-test. This allows collections to specify requirements and constraints for packages that ansible-test has requirements or constraints for. --- .../ansible-test-collection-constraints.yml | 2 ++ .../tests/integration/constraints.txt | 1 + .../tests/integration/requirements.txt | 1 + .../targets/constraints/tasks/main.yml | 7 +++++++ .../tests/unit/constraints.txt | 1 + .../unit/plugins/modules/test_constraints.py | 8 ++++++++ .../tests/unit/requirements.txt | 1 + .../collection-tests/constraints.sh | 20 +++++++++++++++++++ test/lib/ansible_test/_internal/executor.py | 12 +++++++++++ 9 files changed, 53 insertions(+) create mode 100644 changelogs/fragments/ansible-test-collection-constraints.yml create mode 100644 test/integration/targets/ansible-test/ansible_collections/ns/col_constraints/tests/integration/constraints.txt create mode 100644 test/integration/targets/ansible-test/ansible_collections/ns/col_constraints/tests/integration/requirements.txt create mode 100644 test/integration/targets/ansible-test/ansible_collections/ns/col_constraints/tests/integration/targets/constraints/tasks/main.yml create mode 100644 test/integration/targets/ansible-test/ansible_collections/ns/col_constraints/tests/unit/constraints.txt create mode 100644 test/integration/targets/ansible-test/ansible_collections/ns/col_constraints/tests/unit/plugins/modules/test_constraints.py create mode 100644 test/integration/targets/ansible-test/ansible_collections/ns/col_constraints/tests/unit/requirements.txt create mode 100755 test/integration/targets/ansible-test/collection-tests/constraints.sh diff --git a/changelogs/fragments/ansible-test-collection-constraints.yml b/changelogs/fragments/ansible-test-collection-constraints.yml new file mode 100644 index 00000000000..40004470938 --- /dev/null +++ b/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. diff --git a/test/integration/targets/ansible-test/ansible_collections/ns/col_constraints/tests/integration/constraints.txt b/test/integration/targets/ansible-test/ansible_collections/ns/col_constraints/tests/integration/constraints.txt new file mode 100644 index 00000000000..01bb5cfff3d --- /dev/null +++ b/test/integration/targets/ansible-test/ansible_collections/ns/col_constraints/tests/integration/constraints.txt @@ -0,0 +1 @@ +botocore == 1.13.49 diff --git a/test/integration/targets/ansible-test/ansible_collections/ns/col_constraints/tests/integration/requirements.txt b/test/integration/targets/ansible-test/ansible_collections/ns/col_constraints/tests/integration/requirements.txt new file mode 100644 index 00000000000..c5b9e129e10 --- /dev/null +++ b/test/integration/targets/ansible-test/ansible_collections/ns/col_constraints/tests/integration/requirements.txt @@ -0,0 +1 @@ +botocore diff --git a/test/integration/targets/ansible-test/ansible_collections/ns/col_constraints/tests/integration/targets/constraints/tasks/main.yml b/test/integration/targets/ansible-test/ansible_collections/ns/col_constraints/tests/integration/targets/constraints/tasks/main.yml new file mode 100644 index 00000000000..c2c1f1a4c2e --- /dev/null +++ b/test/integration/targets/ansible-test/ansible_collections/ns/col_constraints/tests/integration/targets/constraints/tasks/main.yml @@ -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"' diff --git a/test/integration/targets/ansible-test/ansible_collections/ns/col_constraints/tests/unit/constraints.txt b/test/integration/targets/ansible-test/ansible_collections/ns/col_constraints/tests/unit/constraints.txt new file mode 100644 index 00000000000..d0986894147 --- /dev/null +++ b/test/integration/targets/ansible-test/ansible_collections/ns/col_constraints/tests/unit/constraints.txt @@ -0,0 +1 @@ +botocore == 1.13.50 diff --git a/test/integration/targets/ansible-test/ansible_collections/ns/col_constraints/tests/unit/plugins/modules/test_constraints.py b/test/integration/targets/ansible-test/ansible_collections/ns/col_constraints/tests/unit/plugins/modules/test_constraints.py new file mode 100644 index 00000000000..857e8e557ff --- /dev/null +++ b/test/integration/targets/ansible-test/ansible_collections/ns/col_constraints/tests/unit/plugins/modules/test_constraints.py @@ -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' diff --git a/test/integration/targets/ansible-test/ansible_collections/ns/col_constraints/tests/unit/requirements.txt b/test/integration/targets/ansible-test/ansible_collections/ns/col_constraints/tests/unit/requirements.txt new file mode 100644 index 00000000000..c5b9e129e10 --- /dev/null +++ b/test/integration/targets/ansible-test/ansible_collections/ns/col_constraints/tests/unit/requirements.txt @@ -0,0 +1 @@ +botocore diff --git a/test/integration/targets/ansible-test/collection-tests/constraints.sh b/test/integration/targets/ansible-test/collection-tests/constraints.sh new file mode 100755 index 00000000000..d3bbc6abe96 --- /dev/null +++ b/test/integration/targets/ansible-test/collection-tests/constraints.sh @@ -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[@]}" diff --git a/test/lib/ansible_test/_internal/executor.py b/test/lib/ansible_test/_internal/executor.py index c399cd9a9ff..f93e388a19b 100644 --- a/test/lib/ansible_test/_internal/executor.py +++ b/test/lib/ansible_test/_internal/executor.py @@ -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 = [] @@ -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') @@ -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): 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 @@ -466,6 +474,10 @@ def generate_pip_install(pip, command, packages=None, constraints=None, use_cons 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