Skip to content

PYTHON-1960 Use a virtualenv to run encryption tests #508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions .evergreen/run-tests.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
set -o errexit # Exit the script with error if any of the commands fail

# Supported/used environment variables:
Expand Down Expand Up @@ -47,6 +47,9 @@ if [ "$SSL" != "nossl" ]; then
export CA_PEM="$DRIVERS_TOOLS/.evergreen/x509gen/ca.pem"
fi

# For createvirtualenv.
. .evergreen/utils.sh

if [ -z "$PYTHON_BINARY" ]; then
VIRTUALENV=$(command -v virtualenv) || true
if [ -z "$VIRTUALENV" ]; then
Expand Down Expand Up @@ -109,6 +112,7 @@ if [ -n "$TEST_PYOPENSSL" ]; then
. pyopenssltest/bin/activate
fi
trap "deactivate; rm -rf pyopenssltest" EXIT HUP
PYTHON=python

IS_PYTHON_2=$(python -c "import sys; sys.stdout.write('1' if sys.version_info < (3,) else '0')")
if [ $IS_PYTHON_2 = "1" ]; then
Expand All @@ -125,6 +129,14 @@ if [ -n "$TEST_PYOPENSSL" ]; then
fi

if [ -n "$TEST_ENCRYPTION" ]; then
createvirtualenv $PYTHON venv-encryption
trap "deactivate; rm -rf venv-encryption" EXIT HUP
PYTHON=python

if [ "Windows_NT" = "$OS" ]; then # Magic variable in cygwin
$PYTHON -m pip install -U setuptools
fi

if [ -z "$LIBMONGOCRYPT_URL" ]; then
echo "Cannot test client side encryption without LIBMONGOCRYPT_URL!"
exit 1
Expand Down Expand Up @@ -152,13 +164,13 @@ if [ -n "$TEST_ENCRYPTION" ]; then
exit 1
fi

git clone --branch master [email protected]:mongodb/libmongocrypt.git libmongocrypt_git
$PYTHON -m pip install --upgrade ./libmongocrypt_git/bindings/python
# TODO: use a virtualenv
trap "$PYTHON -m pip uninstall -y pymongocrypt" EXIT HUP
$PYTHON -c "import pymongocrypt; print('pymongocrypt version: '+pymongocrypt.__version__)"
$PYTHON -c "import pymongocrypt; print('libmongocrypt version: '+pymongocrypt.libmongocrypt_version())"
# PATH is set by PREPARE_SHELL.
# TODO: Test with 'pip install pymongocrypt'
git clone --branch master https://github.com/mongodb/libmongocrypt.git libmongocrypt_git
python -m pip install --upgrade ./libmongocrypt_git/bindings/python
python -c "import pymongocrypt; print('pymongocrypt version: '+pymongocrypt.__version__)"
python -c "import pymongocrypt; print('libmongocrypt version: '+pymongocrypt.libmongocrypt_version())"
# PATH is updated by PREPARE_SHELL for access to mongocryptd.

fi

PYTHON_IMPL=$($PYTHON -c "import platform, sys; sys.stdout.write(platform.python_implementation())")
Expand Down
4 changes: 2 additions & 2 deletions .evergreen/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# createvirtualenv /path/to/python /output/path/for/venv
# * param1: Python binary to use for the virtualenv
# * param2: Path to the virtualenv to create
function createvirtualenv {
createvirtualenv () {
PYTHON=$1
VENVPATH=$2
if $PYTHON -m virtualenv --version; then
Expand All @@ -28,7 +28,7 @@ function createvirtualenv {
# * param1: Python binary to test
# * param2: Path to the wheel or egg file to install
# * param3 (optional): If set to a non-empty string, don't create a virtualenv. Used in manylinux containers.
function testinstall {
testinstall () {
PYTHON=$1
RELEASE=$2
NO_VIRTUALENV=$3
Expand Down