Skip to content

PYTHON-3885 Use tox in remaining Evergreen Tests #1347

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 18 commits into from
Aug 9, 2023
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
13 changes: 8 additions & 5 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ functions:
script: |
set -o xtrace
${PREPARE_SHELL}
PYTHON_BINARY=${PYTHON_BINARY} bash ${PROJECT_DIRECTORY}/.evergreen/run-doctests.sh
PYTHON_BINARY=${PYTHON_BINARY} bash ${PROJECT_DIRECTORY}/.evergreen/tox.sh -m doc-test

"run tests":
# If testing FLE, start the KMS mock servers, first create the virtualenv.
Expand Down Expand Up @@ -477,7 +477,6 @@ functions:
fi
if [ -n "${test_loadbalancer}" ]; then
export TEST_LOADBALANCER=1
export LOAD_BALANCER=1
export SINGLE_MONGOS_LB_URI="${SINGLE_MONGOS_LB_URI}"
export MULTI_MONGOS_LB_URI="${MULTI_MONGOS_LB_URI}"
fi
Expand Down Expand Up @@ -537,8 +536,11 @@ functions:
set +x
. ./prepare_enterprise_auth.sh
rm -f ./prepare_enterprise_auth.sh

PYTHON_BINARY=${PYTHON_BINARY} PROJECT_DIRECTORY=${PROJECT_DIRECTORY} bash ${PROJECT_DIRECTORY}/.evergreen/run-enterprise-auth-tests.sh
PROJECT_DIRECTORY="${PROJECT_DIRECTORY}" \
PYTHON_BINARY="${PYTHON_BINARY}" \
TEST_ENTERPRISE_AUTH=1 \
AUTH=auth \
bash ${PROJECT_DIRECTORY}/.evergreen/tox.sh -m test-eg

"run atlas tests":
- command: shell.exec
Expand Down Expand Up @@ -964,10 +966,11 @@ functions:
working_dir: "src"
script: |
${PREPARE_SHELL}
TEST_OCSP=1 \
PYTHON_BINARY=${PYTHON_BINARY} \
CA_FILE="$DRIVERS_TOOLS/.evergreen/ocsp/${OCSP_ALGORITHM}/ca.pem" \
OCSP_TLS_SHOULD_SUCCEED="${OCSP_TLS_SHOULD_SUCCEED}" \
bash ${PROJECT_DIRECTORY}/.evergreen/run-ocsp-tests.sh
bash ${PROJECT_DIRECTORY}/.evergreen/tox.sh -m test-eg

run-valid-ocsp-server:
- command: shell.exec
Expand Down
7 changes: 0 additions & 7 deletions .evergreen/run-doctests.sh

This file was deleted.

32 changes: 0 additions & 32 deletions .evergreen/run-enterprise-auth-tests.sh

This file was deleted.

20 changes: 8 additions & 12 deletions .evergreen/run-mongodb-aws-ecs-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,12 @@ set -o xtrace

# Install python3.7 with pip.
apt-get update
apt install python3.7 python3-pip -y
apt-get install python3.7 python3-pip build-essential python3.7-dev -y

authtest () {
echo "Running MONGODB-AWS ECS authentication tests with $PYTHON"
$PYTHON --version
$PYTHON -m pip install --upgrade wheel setuptools pip
cd src
$PYTHON -m pip install '.[aws]'
$PYTHON test/auth_aws/test_auth_aws.py -v
cd -
}

PYTHON="python3.7" authtest
export PYTHON_BINARY="python3.7"
export TEST_AUTH_AWS=1
export AUTH="auth"
export SET_XTRACE_ON=1
cd src
python3.7 -m pip install --user tox
bash .evergreen/tox.sh -m test-eg
35 changes: 5 additions & 30 deletions .evergreen/run-mongodb-aws-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,37 +39,12 @@ fi
# show test output
set -x

# Workaround macOS python 3.9 incompatibility with system virtualenv.
if [ "$(uname -s)" = "Darwin" ]; then
VIRTUALENV="/Library/Frameworks/Python.framework/Versions/3.9/bin/python3 -m virtualenv"
else
VIRTUALENV=$(command -v virtualenv)
fi

authtest () {
if [ "Windows_NT" = "$OS" ]; then
PYTHON=$(cygpath -m $PYTHON)
fi

echo "Running MONGODB-AWS authentication tests with $PYTHON"
$PYTHON --version

$VIRTUALENV -p $PYTHON --never-download venvaws
if [ "Windows_NT" = "$OS" ]; then
. venvaws/Scripts/activate
else
. venvaws/bin/activate
fi
python -m pip install '.[aws]'
python test/auth_aws/test_auth_aws.py -v
deactivate
rm -rf venvaws
}

PYTHON=${PYTHON_BINARY:-}
if [ -z "$PYTHON" ]; then
if [ -z "$PYTHON_BINARY" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this file at all? What if we put the new contents directly into config.yml?

Copy link
Member Author

Choose a reason for hiding this comment

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

We would still run these two files as entrypoints for local testing. I wanted to keep the logic out of config.yml where possible, and there are parts of this that we don't want to echo and parts that we do.

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense!

echo "Cannot test without specifying PYTHON_BINARY"
exit 1
fi

authtest
export TEST_AUTH_AWS=1
export AUTH="auth"
export SET_XTRACE_ON=1
bash ./.evergreen/tox.sh -m test-eg
40 changes: 6 additions & 34 deletions .evergreen/run-mongodb-oidc-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,41 +45,13 @@ if [ "$ASSERT_NO_URI_CREDS" = "true" ]; then
fi
fi

# show test output
set -x

# Workaround macOS python 3.9 incompatibility with system virtualenv.
if [ "$(uname -s)" = "Darwin" ]; then
VIRTUALENV="/Library/Frameworks/Python.framework/Versions/3.9/bin/python3 -m virtualenv"
else
VIRTUALENV=$(command -v virtualenv)
fi

authtest () {
if [ "Windows_NT" = "$OS" ]; then
PYTHON=$(cygpath -m $PYTHON)
fi

echo "Running MONGODB-OIDC authentication tests with $PYTHON"
$PYTHON --version

$VIRTUALENV -p $PYTHON --never-download venvoidc
if [ "Windows_NT" = "$OS" ]; then
. venvoidc/Scripts/activate
else
. venvoidc/bin/activate
fi
python -m pip install -U pip setuptools
python -m pip install '.[aws]'
python test/auth_aws/test_auth_oidc.py -v
deactivate
rm -rf venvoidc
}

PYTHON=${PYTHON_BINARY:-}
if [ -z "$PYTHON" ]; then
if [ -z "$PYTHON_BINARY" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

Same for this file

echo "Cannot test without specifying PYTHON_BINARY"
exit 1
fi

authtest
export TEST_AUTH_OIDC=1
export AUTH_MECH="SCRAM-SHA-256"
export AUTH="auth"
export SET_XTRACE_ON=1
bash ./.evergreen/tox.sh -m test-eg
25 changes: 0 additions & 25 deletions .evergreen/run-ocsp-tests.sh

This file was deleted.

21 changes: 4 additions & 17 deletions .evergreen/run-perf-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,8 @@ cd ..
export TEST_PATH="${PROJECT_DIRECTORY}/driver-performance-test-data"
export OUTPUT_FILE="${PROJECT_DIRECTORY}/results.json"

MTCBIN=/opt/mongodbtoolchain/v3/bin
VIRTUALENV="$MTCBIN/virtualenv -p $MTCBIN/python3"
export PYTHON_BINARY=/opt/mongodbtoolchain/v3/bin/python3
export C_EXTENSIONS=1
export PERF_TEST=1

$VIRTUALENV pyperftest
. pyperftest/bin/activate
python -m pip install simplejson

python setup.py build_ext -i
start_time=$(date +%s)
python test/performance/perf_test.py --locals
end_time=$(date +%s)
elapsed_secs=$((end_time-start_time))

cat results.json

echo "{\"failures\": 0, \"results\": [{\"status\": \"pass\", \"exit_code\": 0, \"test_file\": \"BenchMarkTests\", \"start\": $start_time, \"end\": $end_time, \"elapsed\": $elapsed_secs}]}" > report.json

cat report.json
bash ./.evergreen/tox.sh -m test-eg
78 changes: 72 additions & 6 deletions .evergreen/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ set -o errexit # Exit the script with error if any of the commands fail
# TEST_FLE_AZURE_AUTO If non-empy, test auto FLE on Azure
# TEST_FLE_GCP_AUTO If non-empy, test auto FLE on GCP
# TEST_PYOPENSSL If non-empy, test with PyOpenSSL
# TEST_ENTERPRISE_AUTH If non-empty, test with Enterprise Auth
# TEST_AUTH_AWS If non-empty, test AWS Auth Mechanism
# TEST_AUTH_OIDC If non-empty, test OIDC Auth Mechanism
# TEST_PERF If non-empty, run performance tests
# TEST_OCSP If non-empty, run OCSP tests
# TEST_ENCRYPTION_PYOPENSSL If non-empy, test encryption with PyOpenSSL

if [ -n "${SET_XTRACE_ON}" ]; then
Expand Down Expand Up @@ -48,6 +53,34 @@ if [ "$AUTH" != "noauth" ]; then
fi
fi

if [ -n "$TEST_ENTERPRISE_AUTH" ]; then
if [ "Windows_NT" = "$OS" ]; then
echo "Setting GSSAPI_PASS"
export GSSAPI_PASS=${SASL_PASS}
export GSSAPI_CANONICALIZE="true"
else
# BUILD-3830
touch krb5.conf.empty
export KRB5_CONFIG=${PROJECT_DIRECTORY}/.evergreen/krb5.conf.empty

echo "Writing keytab"
echo ${KEYTAB_BASE64} | base64 -d > ${PROJECT_DIRECTORY}/.evergreen/drivers.keytab
echo "Running kinit"
kinit -k -t ${PROJECT_DIRECTORY}/.evergreen/drivers.keytab -p ${PRINCIPAL}
fi
echo "Setting GSSAPI variables"
export GSSAPI_HOST=${SASL_HOST}
export GSSAPI_PORT=${SASL_PORT}
export GSSAPI_PRINCIPAL=${PRINCIPAL}
fi

if [ -n "$TEST_LOADBALANCER" ]; then
export LOAD_BALANCER=1
export SINGLE_MONGOS_LB_URI="${SINGLE_MONGOS_LB_URI:-mongodb://127.0.0.1:8000/?loadBalanced=true}"
export MULTI_MONGOS_LB_URI="${MULTI_MONGOS_LB_URI:-mongodb://127.0.0.1:8001/?loadBalanced=true}"
export TEST_ARGS="test/test_load_balancer.py"
fi

if [ "$SSL" != "nossl" ]; then
export CLIENT_PEM="$DRIVERS_TOOLS/.evergreen/x509gen/client.pem"
export CA_PEM="$DRIVERS_TOOLS/.evergreen/x509gen/ca.pem"
Expand All @@ -59,30 +92,30 @@ if [ "$SSL" != "nossl" ]; then
fi

if [ "$COMPRESSORS" = "snappy" ]; then
pip install '.[snappy]'
python -m pip install '.[snappy]'
PYTHON=python
elif [ "$COMPRESSORS" = "zstd" ]; then
pip install zstandard
python -m pip install zstandard
fi

# PyOpenSSL test setup.
if [ -n "$TEST_PYOPENSSL" ]; then
pip install '.[ocsp]'
python -m pip install '.[ocsp]'
fi

if [ -n "$TEST_ENCRYPTION" ] || [ -n "$TEST_FLE_AZURE_AUTO" ] || [ -n "$TEST_FLE_GCP_AUTO" ]; then

# Work around for root certifi not being installed.
# TODO: Remove after PYTHON-3827
if [ "$(uname -s)" = "Darwin" ]; then
pip install certifi
python -m pip install certifi
CERT_PATH=$(python -c "import certifi; print(certifi.where())")
export SSL_CERT_FILE=${CERT_PATH}
export REQUESTS_CA_BUNDLE=${CERT_PATH}
export AWS_CA_BUNDLE=${CERT_PATH}
fi

pip install '.[encryption]'
python -m pip install '.[encryption]'

if [ "Windows_NT" = "$OS" ]; then # Magic variable in cygwin
# PYTHON-2808 Ensure this machine has the CA cert for google KMS.
Expand Down Expand Up @@ -128,7 +161,7 @@ fi

if [ -n "$TEST_ENCRYPTION" ]; then
if [ -n "$TEST_ENCRYPTION_PYOPENSSL" ]; then
pip install '.[ocsp]'
python -m pip install '.[ocsp]'
fi

# Get access to the AWS temporary credentials:
Expand Down Expand Up @@ -172,6 +205,27 @@ if [ -n "$TEST_DATA_LAKE" ] && [ -z "$TEST_ARGS" ]; then
TEST_ARGS="test/test_data_lake.py"
fi

if [ -n "$TEST_OCSP" ]; then
python -m pip install ".[ocsp]"
TEST_ARGS="test/ocsp/test_ocsp.py"
fi

if [ -n "$TEST_AUTH_AWS" ]; then
python -m pip install ".[aws]"
TEST_ARGS="test/auth_aws/test_auth_aws.py"
fi

if [ -n "$TEST_AUTH_OIDC" ]; then
python -m pip install ".[aws]"
TEST_ARGS="test/auth_aws/test_auth_oidc.py"
fi

if [ -n "$PERF_TEST" ]; then
python -m pip install simplejson
start_time=$(date +%s)
TEST_ARGS="test/performance/perf_test.py"
fi

echo "Running $AUTH tests over $SSL with python $PYTHON"
python -c 'import sys; print(sys.version)'

Expand Down Expand Up @@ -199,3 +253,15 @@ else
python -m pip install $GREEN_FRAMEWORK
python green_framework_test.py $GREEN_FRAMEWORK
fi

# Handle perf test post actions.
if [ -n "$PERF_TEST" ]; then
end_time=$(date +%s)
elapsed_secs=$((end_time-start_time))

cat results.json

echo "{\"failures\": 0, \"results\": [{\"status\": \"pass\", \"exit_code\": 0, \"test_file\": \"BenchMarkTests\", \"start\": $start_time, \"end\": $end_time, \"elapsed\": $elapsed_secs}]}" > report.json

cat report.json
fi
Loading