From 33ab3ed6ba142f23e55d449638f0d3ab36522f25 Mon Sep 17 00:00:00 2001 From: Shane Harvey Date: Fri, 9 Jul 2021 17:20:51 -0700 Subject: [PATCH 1/3] PYTHON-2608 Fix KMS TLS testing on Python <3.5 --- .evergreen/config.yml | 2 ++ .evergreen/run-tests.sh | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/.evergreen/config.yml b/.evergreen/config.yml index 01daef35aa..10665b43f8 100644 --- a/.evergreen/config.yml +++ b/.evergreen/config.yml @@ -426,6 +426,7 @@ functions: fi PYTHON_BINARY=${PYTHON_BINARY} \ + PYTHON3_BINARY=${python3_binary} \ GREEN_FRAMEWORK=${GREEN_FRAMEWORK} \ C_EXTENSIONS=${C_EXTENSIONS} \ COVERAGE=${COVERAGE} \ @@ -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)" diff --git a/.evergreen/run-tests.sh b/.evergreen/run-tests.sh index f1d290474a..9f688c4014 100755 --- a/.evergreen/run-tests.sh +++ b/.evergreen/run-tests.sh @@ -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. @@ -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:-} @@ -170,11 +172,27 @@ 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 + deactivate + if [ "Windows_NT" = "$OS" ]; then + . venv-encryption/Scripts/activate + else + . venv-encryption/bin/activate + fi + fi fi PYTHON_IMPL=$($PYTHON -c "import platform, sys; sys.stdout.write(platform.python_implementation())") From 71ff44141bfb8a1a309ffd42518781e53e35ed3d Mon Sep 17 00:00:00 2001 From: Shane Harvey Date: Mon, 12 Jul 2021 15:34:41 -0700 Subject: [PATCH 2/3] PYTHON-2608 activatevritualenv --- .evergreen/run-tests.sh | 6 +----- .evergreen/utils.sh | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/.evergreen/run-tests.sh b/.evergreen/run-tests.sh index 9f688c4014..a10b5b571d 100755 --- a/.evergreen/run-tests.sh +++ b/.evergreen/run-tests.sh @@ -187,11 +187,7 @@ if [ -n "$TEST_ENCRYPTION" ]; then # Restore the test virtualenv. if [ $IS_PRE_35 = "1" ]; then deactivate - if [ "Windows_NT" = "$OS" ]; then - . venv-encryption/Scripts/activate - else - . venv-encryption/bin/activate - fi + activatevritualenv venv-encryption fi fi diff --git a/.evergreen/utils.sh b/.evergreen/utils.sh index 27e9d04db3..a9008661df 100755 --- a/.evergreen/utils.sh +++ b/.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 @@ -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])') From f9a2b8857101aa43006d4e7e8e9772dfe2f8640a Mon Sep 17 00:00:00 2001 From: Shane Harvey Date: Mon, 12 Jul 2021 16:23:24 -0700 Subject: [PATCH 3/3] Revert "PYTHON-2608 activatevritualenv" This reverts commit 71ff44141bfb8a1a309ffd42518781e53e35ed3d. --- .evergreen/run-tests.sh | 6 +++++- .evergreen/utils.sh | 18 +++++------------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/.evergreen/run-tests.sh b/.evergreen/run-tests.sh index a10b5b571d..9f688c4014 100755 --- a/.evergreen/run-tests.sh +++ b/.evergreen/run-tests.sh @@ -187,7 +187,11 @@ if [ -n "$TEST_ENCRYPTION" ]; then # Restore the test virtualenv. if [ $IS_PRE_35 = "1" ]; then deactivate - activatevritualenv venv-encryption + if [ "Windows_NT" = "$OS" ]; then + . venv-encryption/Scripts/activate + else + . venv-encryption/bin/activate + fi fi fi diff --git a/.evergreen/utils.sh b/.evergreen/utils.sh index a9008661df..27e9d04db3 100755 --- a/.evergreen/utils.sh +++ b/.evergreen/utils.sh @@ -1,17 +1,5 @@ #!/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 @@ -30,7 +18,11 @@ createvirtualenv () { exit 1 fi $VIRTUALENV $VENVPATH - activatevritualenv $VENVPATH + if [ "Windows_NT" = "$OS" ]; then + . $VENVPATH/Scripts/activate + else + . $VENVPATH/bin/activate + fi # 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])')