Skip to content

PYTHON-3906 Use AWS Secrets for Atlas tests #1342

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 15, 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
30 changes: 6 additions & 24 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -543,40 +543,22 @@ functions:
bash ${PROJECT_DIRECTORY}/.evergreen/tox.sh -m test-eg

"run atlas tests":
- command: shell.exec
type: test
- command: ec2.assume_role
params:
silent: true
working_dir: "src"
script: |
cat <<EOT > prepare_atlas_connectivity.sh
export ATLAS_FREE='${atlas_free}'
export ATLAS_REPL='${atlas_repl}'
export ATLAS_SHRD='${atlas_shrd}'
export ATLAS_TLS11='${atlas_tls11}'
export ATLAS_TLS12='${atlas_tls12}'
export ATLAS_SERVERLESS='${atlas_serverless}'
export ATLAS_SRV_FREE='${atlas_srv_free}'
export ATLAS_SRV_REPL='${atlas_srv_repl}'
export ATLAS_SRV_SHRD='${atlas_srv_shrd}'
export ATLAS_SRV_TLS11='${atlas_srv_tls11}'
export ATLAS_SRV_TLS12='${atlas_srv_tls12}'
export ATLAS_SRV_SERVERLESS='${atlas_srv_serverless}'
EOT
role_arn: ${aws_test_secrets_role}
- command: shell.exec
type: test
params:
add_expansions_to_env: true
working_dir: "src"
script: |
# Disable xtrace for security reasons (just in case it was accidentally set).
set +x

. ./prepare_atlas_connectivity.sh
rm -f ./prepare_atlas_connectivity.sh

set -o errexit
set -o xtrace
${PYTHON_BINARY} -m tox -m test-atlas

bash ${PROJECT_DIRECTORY}/.evergreen/tox.sh -m aws-secrets -- drivers/atlas_connect
TEST_ATLAS=1 bash ${PROJECT_DIRECTORY}/.evergreen/tox.sh -m test-eg

"add aws auth variables to file":
- command: shell.exec
Expand Down
10 changes: 10 additions & 0 deletions .evergreen/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ set -o errexit # Exit the script with error if any of the commands fail
# 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
# TEST_ATLAS If non-empty, test Atlas connections

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

if [ -n "$TEST_ATLAS" ]; then
TEST_ARGS="test/atlas/test_connection.py"
fi

if [ -n "$TEST_OCSP" ]; then
python -m pip install ".[ocsp]"
TEST_ARGS="test/ocsp/test_ocsp.py"
Expand All @@ -229,6 +234,11 @@ fi
echo "Running $AUTH tests over $SSL with python $PYTHON"
python -c 'import sys; print(sys.version)'

# Try to source exported AWS Secrets
if [ -f ./secrets-export.sh ]; then
source ./secrets-export.sh
fi

# Run the tests, and store the results in Evergreen compatible XUnit XML
# files in the xunit-results/ directory.

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ mongocryptd.pid
.idea/
.nova/
venv/
secrets-expansion.yml
secrets-export.sh

# Lambda temp files
test/lambda/.aws-sam
Expand Down
18 changes: 9 additions & 9 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ labels = # Use labels and -m instead of -e so that tox -m <label> fails instantl
doc = doc
doc-test = doc-test
linkcheck = linkcheck
test-atlas = test-atlas
test-mockupdb = test-mockupdb
aws-secrets = aws-secrets

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

[testenv:test-atlas]
description = run atlas connection tests
deps =
{[testenv:test]deps}
passenv = *
commands =
python -m pytest -v {posargs} ./test/atlas/test_connection.py

[testenv:test-mockupdb]
description = run mockupdb tests
deps =
Expand All @@ -159,3 +151,11 @@ deps =
passenv = *
commands =
python -m pytest -v {posargs} ./test/mockupdb

[testenv:aws-secrets]
deps =
PyYAML
boto3
passenv = *
commands =
python {env:DRIVERS_TOOLS}/.evergreen/auth_aws/setup_secrets.py {posargs}