diff options
author | Matt Clay <mclay@redhat.com> | 2021-01-08 14:31:04 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-08 16:31:04 -0600 |
commit | cdcd2ed49aecef3bd6b62dfa6847eb2149cdf268 (patch) | |
tree | 3270d721836e7893f4396b9a1f7b56ab96e5dc24 | |
parent | 0f65b901f7944f53d17306e1c76fea08e09ef126 (diff) | |
download | ansible-cdcd2ed49aecef3bd6b62dfa6847eb2149cdf268.tar.gz |
Support venv in ansible-test virtualenv scripts (#73164)
* ansible-test - prefer venv over virtualenv on Python 3 (#73000)
Also pin virtualenv to 16.7.10 for older Mac OS X systems. This was the version being installed
anway with the previous constraint (<20).
On systems with Python 3, now prefer venv over virtualenv. Test to see if venv is functional since
some systems have a non-functional venv installation (such as Debian).
(cherry picked from commit 850a77f6391cc09b7296e831877adcf4052f5404)
(cherry picked from commit a48b3d2089807ff0ab34ddacfcc90de49903d10e)
* Make the new ansible-test venv behavior opt-in
Co-authored-by: Sam Doooran <sdoran@redhat.com>
4 files changed, 17 insertions, 3 deletions
diff --git a/changelogs/fragments/ansible-test-venv-virtualenv-fallback.yml b/changelogs/fragments/ansible-test-venv-virtualenv-fallback.yml new file mode 100644 index 0000000000..6e31c00dad --- /dev/null +++ b/changelogs/fragments/ansible-test-venv-virtualenv-fallback.yml @@ -0,0 +1,2 @@ +minor_changes: + - ansible-test - virtualenv helper scripts now prefer ``venv`` on Python 3 over ``virtualenv`` if the ``ANSIBLE_TEST_PREFER_VENV`` environment variable is set diff --git a/test/lib/ansible_test/_data/injector/virtualenv-isolated.sh b/test/lib/ansible_test/_data/injector/virtualenv-isolated.sh index 82f799809e..af92a0562e 100644 --- a/test/lib/ansible_test/_data/injector/virtualenv-isolated.sh +++ b/test/lib/ansible_test/_data/injector/virtualenv-isolated.sh @@ -2,7 +2,13 @@ # Create and activate a fresh virtual environment with `source virtualenv-isolated.sh`. rm -rf "${OUTPUT_DIR}/venv" -"${ANSIBLE_TEST_PYTHON_INTERPRETER}" -m virtualenv --python "${ANSIBLE_TEST_PYTHON_INTERPRETER}" "${OUTPUT_DIR}/venv" + +# Try to use 'venv' if it is available, then fallback to 'virtualenv' since some systems provide 'venv' although it is non-functional. +if [ -z "${ANSIBLE_TEST_PREFER_VENV:-}" ] || [[ "${ANSIBLE_TEST_PYTHON_VERSION}" =~ ^2\. ]] || ! "${ANSIBLE_TEST_PYTHON_INTERPRETER}" -m venv "${OUTPUT_DIR}/venv" > /dev/null 2>&1; then + rm -rf "${OUTPUT_DIR}/venv" + "${ANSIBLE_TEST_PYTHON_INTERPRETER}" -m virtualenv --python "${ANSIBLE_TEST_PYTHON_INTERPRETER}" "${OUTPUT_DIR}/venv" +fi + set +ux source "${OUTPUT_DIR}/venv/bin/activate" set -ux diff --git a/test/lib/ansible_test/_data/injector/virtualenv.sh b/test/lib/ansible_test/_data/injector/virtualenv.sh index ccde29748c..282e6074cc 100644 --- a/test/lib/ansible_test/_data/injector/virtualenv.sh +++ b/test/lib/ansible_test/_data/injector/virtualenv.sh @@ -2,7 +2,13 @@ # Create and activate a fresh virtual environment with `source virtualenv.sh`. rm -rf "${OUTPUT_DIR}/venv" -"${ANSIBLE_TEST_PYTHON_INTERPRETER}" -m virtualenv --system-site-packages --python "${ANSIBLE_TEST_PYTHON_INTERPRETER}" "${OUTPUT_DIR}/venv" + +# Try to use 'venv' if it is available, then fallback to 'virtualenv' since some systems provide 'venv' although it is non-functional. +if [ -z "${ANSIBLE_TEST_PREFER_VENV:-}" ] || [[ "${ANSIBLE_TEST_PYTHON_VERSION}" =~ ^2\. ]] || ! "${ANSIBLE_TEST_PYTHON_INTERPRETER}" -m venv --system-site-packages "${OUTPUT_DIR}/venv" > /dev/null 2>&1; then + rm -rf "${OUTPUT_DIR}/venv" + "${ANSIBLE_TEST_PYTHON_INTERPRETER}" -m virtualenv --system-site-packages --python "${ANSIBLE_TEST_PYTHON_INTERPRETER}" "${OUTPUT_DIR}/venv" +fi + set +ux source "${OUTPUT_DIR}/venv/bin/activate" set -ux diff --git a/test/lib/ansible_test/_data/setup/remote.sh b/test/lib/ansible_test/_data/setup/remote.sh index 922bb2d545..c3b4835451 100644 --- a/test/lib/ansible_test/_data/setup/remote.sh +++ b/test/lib/ansible_test/_data/setup/remote.sh @@ -73,7 +73,7 @@ elif [ "${platform}" = "rhel" ]; then elif [ "${platform}" = "osx" ]; then while true; do pip install --disable-pip-version-check --quiet \ - 'virtualenv<20' \ + 'virtualenv==16.7.10' \ && break echo "Failed to install packages. Sleeping before trying again..." sleep 10 |