Skip to content

Commit 42c0841

Browse files
authored
PYTHON-3906 Use AWS Secrets for Atlas tests (#1342)
1 parent 02de1ba commit 42c0841

File tree

4 files changed

+27
-33
lines changed

4 files changed

+27
-33
lines changed

.evergreen/config.yml

+6-24
Original file line numberDiff line numberDiff line change
@@ -543,40 +543,22 @@ functions:
543543
bash ${PROJECT_DIRECTORY}/.evergreen/tox.sh -m test-eg
544544
545545
"run atlas tests":
546-
- command: shell.exec
547-
type: test
546+
- command: ec2.assume_role
548547
params:
549-
silent: true
550-
working_dir: "src"
551-
script: |
552-
cat <<EOT > prepare_atlas_connectivity.sh
553-
export ATLAS_FREE='${atlas_free}'
554-
export ATLAS_REPL='${atlas_repl}'
555-
export ATLAS_SHRD='${atlas_shrd}'
556-
export ATLAS_TLS11='${atlas_tls11}'
557-
export ATLAS_TLS12='${atlas_tls12}'
558-
export ATLAS_SERVERLESS='${atlas_serverless}'
559-
export ATLAS_SRV_FREE='${atlas_srv_free}'
560-
export ATLAS_SRV_REPL='${atlas_srv_repl}'
561-
export ATLAS_SRV_SHRD='${atlas_srv_shrd}'
562-
export ATLAS_SRV_TLS11='${atlas_srv_tls11}'
563-
export ATLAS_SRV_TLS12='${atlas_srv_tls12}'
564-
export ATLAS_SRV_SERVERLESS='${atlas_srv_serverless}'
565-
EOT
548+
role_arn: ${aws_test_secrets_role}
566549
- command: shell.exec
567550
type: test
568551
params:
552+
add_expansions_to_env: true
569553
working_dir: "src"
570554
script: |
571555
# Disable xtrace for security reasons (just in case it was accidentally set).
572556
set +x
573-
574-
. ./prepare_atlas_connectivity.sh
575-
rm -f ./prepare_atlas_connectivity.sh
576-
577557
set -o errexit
578558
set -o xtrace
579-
${PYTHON_BINARY} -m tox -m test-atlas
559+
560+
bash ${PROJECT_DIRECTORY}/.evergreen/tox.sh -m aws-secrets -- drivers/atlas_connect
561+
TEST_ATLAS=1 bash ${PROJECT_DIRECTORY}/.evergreen/tox.sh -m test-eg
580562
581563
"add aws auth variables to file":
582564
- command: shell.exec

.evergreen/run-tests.sh

+10
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ set -o errexit # Exit the script with error if any of the commands fail
2626
# TEST_PERF If non-empty, run performance tests
2727
# TEST_OCSP If non-empty, run OCSP tests
2828
# TEST_ENCRYPTION_PYOPENSSL If non-empy, test encryption with PyOpenSSL
29+
# TEST_ATLAS If non-empty, test Atlas connections
2930

3031
if [ -n "${SET_XTRACE_ON}" ]; then
3132
set -o xtrace
@@ -205,6 +206,10 @@ if [ -n "$TEST_DATA_LAKE" ] && [ -z "$TEST_ARGS" ]; then
205206
TEST_ARGS="test/test_data_lake.py"
206207
fi
207208

209+
if [ -n "$TEST_ATLAS" ]; then
210+
TEST_ARGS="test/atlas/test_connection.py"
211+
fi
212+
208213
if [ -n "$TEST_OCSP" ]; then
209214
python -m pip install ".[ocsp]"
210215
TEST_ARGS="test/ocsp/test_ocsp.py"
@@ -229,6 +234,11 @@ fi
229234
echo "Running $AUTH tests over $SSL with python $PYTHON"
230235
python -c 'import sys; print(sys.version)'
231236

237+
# Try to source exported AWS Secrets
238+
if [ -f ./secrets-export.sh ]; then
239+
source ./secrets-export.sh
240+
fi
241+
232242
# Run the tests, and store the results in Evergreen compatible XUnit XML
233243
# files in the xunit-results/ directory.
234244

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ mongocryptd.pid
1717
.idea/
1818
.nova/
1919
venv/
20+
secrets-expansion.yml
21+
secrets-export.sh
2022

2123
# Lambda temp files
2224
test/lambda/.aws-sam

tox.ini

+9-9
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ labels = # Use labels and -m instead of -e so that tox -m <label> fails instantl
3838
doc = doc
3939
doc-test = doc-test
4040
linkcheck = linkcheck
41-
test-atlas = test-atlas
4241
test-mockupdb = test-mockupdb
42+
aws-secrets = aws-secrets
4343

4444
[testenv:test]
4545
description = run base set of unit tests with no extra functionality
@@ -143,14 +143,6 @@ deps =
143143
commands =
144144
sphinx-build -E -b linkcheck doc ./doc/_build/linkcheck
145145

146-
[testenv:test-atlas]
147-
description = run atlas connection tests
148-
deps =
149-
{[testenv:test]deps}
150-
passenv = *
151-
commands =
152-
python -m pytest -v {posargs} ./test/atlas/test_connection.py
153-
154146
[testenv:test-mockupdb]
155147
description = run mockupdb tests
156148
deps =
@@ -159,3 +151,11 @@ deps =
159151
passenv = *
160152
commands =
161153
python -m pytest -v {posargs} ./test/mockupdb
154+
155+
[testenv:aws-secrets]
156+
deps =
157+
PyYAML
158+
boto3
159+
passenv = *
160+
commands =
161+
python {env:DRIVERS_TOOLS}/.evergreen/auth_aws/setup_secrets.py {posargs}

0 commit comments

Comments
 (0)