Skip to content

Commit 5273e3b

Browse files
eramongodbrcsanchez97
authored andcommitted
CXX-2162 Use DET hygienic scripts for Python binary selection and venv creation (#913)
* Replace activate_venv.sh with activate-kmstlsvenv.sh * Replace manual Python selection in compile function * Use venv-utils.sh in stop_mongod function * Format collection.cpp and uri.cpp to address lint task failure * Guard cd to potentially missing DET repo * CXX-2628 Apply Python >=3.10 selection workaround used by C Driver * Remove special-casing of TLS test cert files
1 parent d309410 commit 5273e3b

File tree

1 file changed

+63
-26
lines changed

1 file changed

+63
-26
lines changed

.mci.yml

Lines changed: 63 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,12 @@ functions:
207207
script: |
208208
set -o errexit
209209
set -o pipefail
210-
cd drivers-evergreen-tools/.evergreen/orchestration
211-
if [ -f venv/bin/activate ]; then
212-
. venv/bin/activate
213-
elif [ -f venv/Scripts/activate ]; then
214-
. venv/Scripts/activate
210+
if cd drivers-evergreen-tools/.evergreen/orchestration; then
211+
. ../venv-utils.sh
212+
if venvactivate venv; then
213+
mongo-orchestration stop
214+
fi
215215
fi
216-
mongo-orchestration stop
217216
218217
"install_c_driver":
219218
- command: expansions.update
@@ -280,6 +279,30 @@ functions:
280279
fi
281280
282281
"run_kms_servers":
282+
- command: shell.exec
283+
params:
284+
shell: bash
285+
script: |-
286+
set -o errexit
287+
echo "Preparing CSFLE venv environment..."
288+
cd ./drivers-evergreen-tools/.evergreen/csfle
289+
# This function ensures future invocations of activate-kmstlsvenv.sh conducted in
290+
# parallel do not race to setup a venv environment; it has already been prepared.
291+
# This primarily addresses the situation where the "test" and "run_kms_servers"
292+
# functions invoke 'activate-kmstlsvenv.sh' simultaneously.
293+
if [[ "$OSTYPE" =~ cygwin && ! -d kmstlsvenv ]]; then
294+
# Avoid using Python 3.10 on Windows due to incompatible cipher suites.
295+
# See CXX-2628.
296+
. ../venv-utils.sh
297+
venvcreate "C:/python/Python39/python.exe" kmstlsvenv || # windows-2017
298+
venvcreate "C:/python/Python38/python.exe" kmstlsvenv # windows-2015
299+
python -m pip install --upgrade boto3~=1.19 pykmip~=0.10.0
300+
deactivate
301+
else
302+
. ./activate-kmstlsvenv.sh
303+
deactivate
304+
fi
305+
echo "Preparing CSFLE venv environment... done."
283306
- command: shell.exec
284307
params:
285308
background: true
@@ -288,7 +311,7 @@ functions:
288311
set -o errexit
289312
echo "Starting mock KMS servers..."
290313
cd ./drivers-evergreen-tools/.evergreen/csfle
291-
. ./activate_venv.sh
314+
. ./activate-kmstlsvenv.sh
292315
python -u kms_http_server.py --ca_file ../x509gen/ca.pem --cert_file ../x509gen/server.pem --port 8999 &
293316
python -u kms_http_server.py --ca_file ../x509gen/ca.pem --cert_file ../x509gen/expired.pem --port 9000 &
294317
python -u kms_http_server.py --ca_file ../x509gen/ca.pem --cert_file ../x509gen/wrong-host.pem --port 9001 &
@@ -326,21 +349,14 @@ functions:
326349
fi
327350
export CMAKE=${cmake}
328351
329-
if [ "x$(lsb_release -cs)" = "xtrusty" -a -f /opt/mongodbtoolchain/v2/bin/python ]; then
330-
/opt/mongodbtoolchain/v2/bin/python -m virtualenv venv
331-
elif ! python -m virtualenv venv 2>/dev/null; then
332-
/opt/mongodbtoolchain/v3/bin/python3 -m venv venv
352+
if [ ! -d ../drivers-evergreen-tools ]; then
353+
git clone --depth 1 [email protected]:mongodb-labs/drivers-evergreen-tools.git ../drivers-evergreen-tools
333354
fi
355+
. ../drivers-evergreen-tools/.evergreen/find-python3.sh
356+
. ../drivers-evergreen-tools/.evergreen/venv-utils.sh
334357
335-
cd venv
336-
if [ -f bin/activate ]; then
337-
. bin/activate
338-
./bin/pip install GitPython
339-
elif [ -f Scripts/activate ]; then
340-
. Scripts/activate
341-
./Scripts/pip install GitPython
342-
fi
343-
cd ..
358+
venvcreate "$(find_python3)" venv
359+
python -m pip install GitPython
344360
345361
export GENERATOR="${generator}"
346362
@@ -417,14 +433,35 @@ functions:
417433
# export environment variables for encryption tests
418434
set +o errexit
419435
420-
if [ "Windows_NT" == "$OS"]; then
421-
export MONGOCXX_TEST_CSFLE_TLS_CA_FILE=$DRIVERS_TOOLS\.evergreen\x509gen\ca.pem
422-
export MONGOCXX_TEST_CSFLE_TLS_CERTIFICATE_KEY_FILE=$DRIVERS_TOOLS\.evergreen\x509gen\client.pem
423-
else
424-
export MONGOCXX_TEST_CSFLE_TLS_CA_FILE=$DRIVERS_TOOLS/.evergreen/x509gen/ca.pem
425-
export MONGOCXX_TEST_CSFLE_TLS_CERTIFICATE_KEY_FILE=$DRIVERS_TOOLS/.evergreen/x509gen/client.pem
436+
# Avoid printing credentials in logs.
437+
set +o xtrace
438+
439+
echo "Setting temporary credentials..."
440+
pushd "$DRIVERS_TOOLS/.evergreen/csfle"
441+
export AWS_SECRET_ACCESS_KEY="${cse_aws_secret_access_key}"
442+
export AWS_ACCESS_KEY_ID="${cse_aws_access_key_id}"
443+
export AWS_DEFAULT_REGION="us-east-1"
444+
echo "Running activate-kmstlsvenv.sh..."
445+
. ./activate-kmstlsvenv.sh
446+
echo "Running activate-kmstlsvenv.sh... done."
447+
echo "Running set-temp-creds.sh..."
448+
. ./set-temp-creds.sh
449+
echo "Running set-temp-creds.sh... done."
450+
deactivate
451+
popd # "$DRIVERS_TOOLS/.evergreen/csfle"
452+
echo "Setting temporary credentials... done."
453+
454+
# Ensure temporary credentials were properly set.
455+
if [ -z "$CSFLE_AWS_TEMP_ACCESS_KEY_ID" ]; then
456+
echo "Failed to set temporary credentials!"
457+
exit 1
426458
fi
427459
460+
export MONGOCXX_TEST_CSFLE_TLS_CA_FILE=$DRIVERS_TOOLS/.evergreen/x509gen/ca.pem
461+
export MONGOCXX_TEST_CSFLE_TLS_CERTIFICATE_KEY_FILE=$DRIVERS_TOOLS/.evergreen/x509gen/client.pem
462+
export MONGOCXX_TEST_AWS_TEMP_ACCESS_KEY_ID="$CSFLE_AWS_TEMP_ACCESS_KEY_ID"
463+
export MONGOCXX_TEST_AWS_TEMP_SECRET_ACCESS_KEY="$CSFLE_AWS_TEMP_SECRET_ACCESS_KEY"
464+
export MONGOCXX_TEST_AWS_TEMP_SESSION_TOKEN="$CSFLE_AWS_TEMP_SESSION_TOKEN"
428465
export MONGOCXX_TEST_AWS_SECRET_ACCESS_KEY="${cse_aws_secret_access_key}"
429466
export MONGOCXX_TEST_AWS_ACCESS_KEY_ID="${cse_aws_access_key_id}"
430467
export MONGOCXX_TEST_AZURE_TENANT_ID="${cse_azure_tenant_id}"

0 commit comments

Comments
 (0)