Skip to content
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

PYTHON-2608 Fix KMS TLS testing on Python <3.5 #671

Merged
merged 3 commits into from Jul 12, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .evergreen/config.yml
Expand Up @@ -426,6 +426,7 @@ functions:
fi

PYTHON_BINARY=${PYTHON_BINARY} \
PYTHON3_BINARY=${python3_binary} \
GREEN_FRAMEWORK=${GREEN_FRAMEWORK} \
C_EXTENSIONS=${C_EXTENSIONS} \
COVERAGE=${COVERAGE} \
Expand Down Expand Up @@ -1697,6 +1698,7 @@ axes:
run_on: rhel70-small
batchtime: 10080 # 7 days
variables:
python3_binary: "/opt/python/3.6/bin/python3"
libmongocrypt_url: https://s3.amazonaws.com/mciuploads/libmongocrypt/rhel-70-64-bit/master/latest/libmongocrypt.tar.gz
- id: suse12-x86-64-test
display_name: "SUSE 12 (x86_64)"
Expand Down
14 changes: 14 additions & 0 deletions .evergreen/run-tests.sh
Expand Up @@ -6,6 +6,7 @@ set -o errexit # Exit the script with error if any of the commands fail
# AUTH Set to enable authentication. Defaults to "noauth"
# SSL Set to enable SSL. Defaults to "nossl"
# PYTHON_BINARY The Python version to use. Defaults to whatever is available
# PYTHON3_BINARY Path to a working Python 3.5+ binary.
# GREEN_FRAMEWORK The green framework to test with, if any.
# C_EXTENSIONS Pass --no_ext to setup.py, or not.
# COVERAGE If non-empty, run the test suite with coverage.
Expand All @@ -22,6 +23,7 @@ fi
AUTH=${AUTH:-noauth}
SSL=${SSL:-nossl}
PYTHON_BINARY=${PYTHON_BINARY:-}
PYTHON3_BINARY=${PYTHON3_BINARY:-python3}
GREEN_FRAMEWORK=${GREEN_FRAMEWORK:-}
C_EXTENSIONS=${C_EXTENSIONS:-}
COVERAGE=${COVERAGE:-}
Expand Down Expand Up @@ -170,11 +172,23 @@ if [ -n "$TEST_ENCRYPTION" ]; then
# Remove after BUILD-13574.
python -m pip install certifi
fi
# The mock KMS server requires Python >=3.5 with boto3.
IS_PRE_35=$(python -c "import sys; sys.stdout.write('1' if sys.version_info < (3, 5) else '0')")
if [ $IS_PRE_35 = "1" ]; then
deactivate
createvirtualenv $PYTHON3_BINARY venv-kms
python -m pip install boto3
fi
pushd ${DRIVERS_TOOLS}/.evergreen/csfle
python -u lib/kms_http_server.py --ca_file ../x509gen/ca.pem --cert_file ../x509gen/expired.pem --port 8000 &
python -u lib/kms_http_server.py --ca_file ../x509gen/ca.pem --cert_file ../x509gen/wrong-host.pem --port 8001 &
trap 'kill $(jobs -p)' EXIT HUP
popd
# Restore the test virtualenv.
if [ $IS_PRE_35 = "1" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add an activatevritualenv function to utils.sh and just call that from both createvirtualenv and also here? It'll be much cleaner.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

deactivate
activatevritualenv venv-encryption
fi
fi

PYTHON_IMPL=$($PYTHON -c "import platform, sys; sys.stdout.write(platform.python_implementation())")
Expand Down
18 changes: 13 additions & 5 deletions .evergreen/utils.sh
@@ -1,5 +1,17 @@
#!/bin/bash -ex

# Usage:
# activatevritualenv /path/to/venv
# * param1: Path to the virtualenv to activate
activatevritualenv () {
VENVPATH=$1
if [ "Windows_NT" = "$OS" ]; then
. $VENVPATH/Scripts/activate
else
. $VENVPATH/bin/activate
fi
}

# Usage:
# createvirtualenv /path/to/python /output/path/for/venv
# * param1: Python binary to use for the virtualenv
Expand All @@ -18,11 +30,7 @@ createvirtualenv () {
exit 1
fi
$VIRTUALENV $VENVPATH
if [ "Windows_NT" = "$OS" ]; then
. $VENVPATH/Scripts/activate
else
. $VENVPATH/bin/activate
fi
activatevritualenv $VENVPATH
# Upgrade to the latest versions of pip setuptools wheel so that
# pip can always download the latest cryptography+cffi wheels.
PYTHON_VERSION=$(python -c 'import sys;print("%s.%s" % sys.version_info[:2])')
Expand Down