Merge branch 'master' of github.com:mongodb/mongo-python-driver

This commit is contained in:
Steven Silvester 2025-03-06 20:10:25 -06:00
commit 28dded80dd
No known key found for this signature in database
GPG Key ID: B1BF5EC3A8B32F91
12 changed files with 586 additions and 510 deletions

View File

@ -201,17 +201,17 @@ functions:
params:
file: "src/xunit-results/TEST-*.xml"
"bootstrap mongo-orchestration":
"run-server":
- command: subprocess.exec
params:
binary: bash
include_expansions_in_env: [VERSION, TOPOLOGY, AUTH, SSL, ORCHESTRATION_FILE, LOAD_BALANCER,
STORAGE_ENGINE, REQUIRE_API_VERSION, DRIVERS_TOOLS, TEST_CRYPT_SHARED, AUTH_AWS]
args:
- src/.evergreen/scripts/bootstrap-mongo-orchestration.sh
working_dir: "src"
include_expansions_in_env: [VERSION, TOPOLOGY, AUTH, SSL, ORCHESTRATION_FILE,
STORAGE_ENGINE, REQUIRE_API_VERSION, DRIVERS_TOOLS, TEST_CRYPT_SHARED, AUTH_AWS, LOAD_BALANCER]
args: [.evergreen/just.sh, run-server, "${TEST_NAME}", "${SUB_TEST_NAME}"]
- command: expansions.update
params:
file: mo-expansion.yml
file: ${DRIVERS_TOOLS}/mo-expansion.yml
"bootstrap data lake":
- command: subprocess.exec
@ -227,13 +227,6 @@ functions:
args:
- ${DRIVERS_TOOLS}/.evergreen/atlas_data_lake/run-mongohouse-image.sh
"stop mongo-orchestration":
- command: subprocess.exec
params:
binary: bash
args:
- ${DRIVERS_TOOLS}/.evergreen/stop-orchestration.sh
"run mod_wsgi tests":
- command: subprocess.exec
type: test
@ -423,7 +416,6 @@ post:
- func: "upload coverage"
- func: "upload mo artifacts"
- func: "upload test results"
- func: "stop mongo-orchestration"
- func: "cleanup"
task_groups:
@ -587,10 +579,7 @@ tasks:
- name: "doctests"
tags: ["doctests"]
commands:
- func: "bootstrap mongo-orchestration"
vars:
VERSION: "latest"
TOPOLOGY: "server"
- func: "run-server"
- func: "run doctests"
- name: "test-serverless"
@ -603,16 +592,13 @@ tasks:
- name: "test-enterprise-auth"
tags: ["enterprise-auth"]
commands:
- func: "bootstrap mongo-orchestration"
vars:
VERSION: "latest"
TOPOLOGY: "server"
- func: "run-server"
- func: "assume ec2 role"
- func: "run enterprise auth tests"
- name: "test-search-index-helpers"
commands:
- func: "bootstrap mongo-orchestration"
- func: "run-server"
vars:
VERSION: "6.0"
TOPOLOGY: "replica_set"
@ -624,28 +610,23 @@ tasks:
- name: "mod-wsgi-standalone"
tags: ["mod_wsgi"]
commands:
- func: "bootstrap mongo-orchestration"
- func: "run-server"
vars:
VERSION: "latest"
TOPOLOGY: "server"
- func: "run mod_wsgi tests"
- name: "mod-wsgi-replica-set"
tags: ["mod_wsgi"]
commands:
- func: "bootstrap mongo-orchestration"
- func: "run-server"
vars:
VERSION: "latest"
TOPOLOGY: "replica_set"
- func: "run mod_wsgi tests"
- name: "mod-wsgi-embedded-mode-standalone"
tags: ["mod_wsgi"]
commands:
- func: "bootstrap mongo-orchestration"
vars:
VERSION: "latest"
TOPOLOGY: "server"
- func: "run-server"
- func: "run mod_wsgi tests"
vars:
MOD_WSGI_EMBEDDED: "1"
@ -653,9 +634,8 @@ tasks:
- name: "mod-wsgi-embedded-mode-replica-set"
tags: ["mod_wsgi"]
commands:
- func: "bootstrap mongo-orchestration"
- func: "run-server"
vars:
VERSION: "latest"
TOPOLOGY: "replica_set"
- func: "run mod_wsgi tests"
vars:
@ -669,7 +649,7 @@ tasks:
- name: "free-threading"
tags: ["free-threading"]
commands:
- func: "bootstrap mongo-orchestration"
- func: "run-server"
vars:
VERSION: "8.0"
TOPOLOGY: "replica_set"
@ -711,7 +691,7 @@ tasks:
vars:
OCSP_ALGORITHM: "rsa"
SERVER_TYPE: "valid"
- func: "bootstrap mongo-orchestration"
- func: "run-server"
vars:
ORCHESTRATION_FILE: "rsa-basic-tls-ocsp-mustStaple.json"
- func: run-ocsp-test
@ -726,7 +706,7 @@ tasks:
vars:
OCSP_ALGORITHM: "rsa"
SERVER_TYPE: "revoked"
- func: "bootstrap mongo-orchestration"
- func: "run-server"
vars:
ORCHESTRATION_FILE: "rsa-basic-tls-ocsp-mustStaple.json"
- func: run-ocsp-test
@ -741,7 +721,7 @@ tasks:
vars:
OCSP_ALGORITHM: "rsa"
SERVER_TYPE: valid
- func: "bootstrap mongo-orchestration"
- func: "run-server"
vars:
ORCHESTRATION_FILE: "rsa-basic-tls-ocsp-disableStapling.json"
- func: run-ocsp-test
@ -756,7 +736,7 @@ tasks:
vars:
OCSP_ALGORITHM: "rsa"
SERVER_TYPE: revoked
- func: "bootstrap mongo-orchestration"
- func: "run-server"
vars:
ORCHESTRATION_FILE: "rsa-basic-tls-ocsp-disableStapling.json"
- func: run-ocsp-test
@ -767,7 +747,7 @@ tasks:
- name: test-ocsp-rsa-soft-fail
tags: ["ocsp", "ocsp-rsa"]
commands:
- func: "bootstrap mongo-orchestration"
- func: "run-server"
vars:
ORCHESTRATION_FILE: "rsa-basic-tls-ocsp-disableStapling.json"
- func: run-ocsp-test
@ -782,7 +762,7 @@ tasks:
vars:
OCSP_ALGORITHM: "rsa"
SERVER_TYPE: revoked
- func: "bootstrap mongo-orchestration"
- func: "run-server"
vars:
ORCHESTRATION_FILE: "rsa-basic-tls-ocsp-mustStaple-disableStapling.json"
- func: run-ocsp-test
@ -793,7 +773,7 @@ tasks:
- name: test-ocsp-rsa-malicious-no-responder-mustStaple-server-does-not-staple
tags: ["ocsp", "ocsp-rsa"]
commands:
- func: "bootstrap mongo-orchestration"
- func: "run-server"
vars:
ORCHESTRATION_FILE: "rsa-basic-tls-ocsp-mustStaple-disableStapling.json"
- func: run-ocsp-test
@ -808,7 +788,7 @@ tasks:
vars:
OCSP_ALGORITHM: "rsa"
SERVER_TYPE: valid-delegate
- func: "bootstrap mongo-orchestration"
- func: "run-server"
vars:
ORCHESTRATION_FILE: "rsa-basic-tls-ocsp-mustStaple.json"
- func: run-ocsp-test
@ -823,7 +803,7 @@ tasks:
vars:
OCSP_ALGORITHM: "rsa"
SERVER_TYPE: revoked-delegate
- func: "bootstrap mongo-orchestration"
- func: "run-server"
vars:
ORCHESTRATION_FILE: "rsa-basic-tls-ocsp-mustStaple.json"
- func: run-ocsp-test
@ -838,7 +818,7 @@ tasks:
vars:
OCSP_ALGORITHM: "rsa"
SERVER_TYPE: valid-delegate
- func: "bootstrap mongo-orchestration"
- func: "run-server"
vars:
ORCHESTRATION_FILE: "rsa-basic-tls-ocsp-disableStapling.json"
- func: run-ocsp-test
@ -853,7 +833,7 @@ tasks:
vars:
OCSP_ALGORITHM: "rsa"
SERVER_TYPE: revoked-delegate
- func: "bootstrap mongo-orchestration"
- func: "run-server"
vars:
ORCHESTRATION_FILE: "rsa-basic-tls-ocsp-disableStapling.json"
- func: run-ocsp-test
@ -868,7 +848,7 @@ tasks:
vars:
OCSP_ALGORITHM: "rsa"
SERVER_TYPE: revoked-delegate
- func: "bootstrap mongo-orchestration"
- func: "run-server"
vars:
ORCHESTRATION_FILE: "rsa-basic-tls-ocsp-mustStaple-disableStapling.json"
- func: run-ocsp-test
@ -883,7 +863,7 @@ tasks:
vars:
OCSP_ALGORITHM: "ecdsa"
SERVER_TYPE: valid
- func: "bootstrap mongo-orchestration"
- func: "run-server"
vars:
ORCHESTRATION_FILE: "ecdsa-basic-tls-ocsp-mustStaple.json"
- func: run-ocsp-test
@ -898,7 +878,7 @@ tasks:
vars:
OCSP_ALGORITHM: "ecdsa"
SERVER_TYPE: revoked
- func: "bootstrap mongo-orchestration"
- func: "run-server"
vars:
ORCHESTRATION_FILE: "ecdsa-basic-tls-ocsp-mustStaple.json"
- func: run-ocsp-test
@ -913,7 +893,7 @@ tasks:
vars:
OCSP_ALGORITHM: "ecdsa"
SERVER_TYPE: valid
- func: "bootstrap mongo-orchestration"
- func: "run-server"
vars:
ORCHESTRATION_FILE: "ecdsa-basic-tls-ocsp-disableStapling.json"
- func: run-ocsp-test
@ -928,7 +908,7 @@ tasks:
vars:
OCSP_ALGORITHM: "ecdsa"
SERVER_TYPE: revoked
- func: "bootstrap mongo-orchestration"
- func: "run-server"
vars:
ORCHESTRATION_FILE: "ecdsa-basic-tls-ocsp-disableStapling.json"
- func: run-ocsp-test
@ -939,7 +919,7 @@ tasks:
- name: test-ocsp-ecdsa-soft-fail
tags: ["ocsp", "ocsp-ecdsa"]
commands:
- func: "bootstrap mongo-orchestration"
- func: "run-server"
vars:
ORCHESTRATION_FILE: "ecdsa-basic-tls-ocsp-disableStapling.json"
- func: run-ocsp-test
@ -954,7 +934,7 @@ tasks:
vars:
OCSP_ALGORITHM: "ecdsa"
SERVER_TYPE: revoked
- func: "bootstrap mongo-orchestration"
- func: "run-server"
vars:
ORCHESTRATION_FILE: "ecdsa-basic-tls-ocsp-mustStaple-disableStapling.json"
- func: run-ocsp-test
@ -965,7 +945,7 @@ tasks:
- name: test-ocsp-ecdsa-malicious-no-responder-mustStaple-server-does-not-staple
tags: ["ocsp", "ocsp-ecdsa"]
commands:
- func: "bootstrap mongo-orchestration"
- func: "run-server"
vars:
ORCHESTRATION_FILE: "ecdsa-basic-tls-ocsp-mustStaple-disableStapling.json"
- func: run-ocsp-test
@ -980,7 +960,7 @@ tasks:
vars:
OCSP_ALGORITHM: "ecdsa"
SERVER_TYPE: valid-delegate
- func: "bootstrap mongo-orchestration"
- func: "run-server"
vars:
ORCHESTRATION_FILE: "ecdsa-basic-tls-ocsp-mustStaple.json"
- func: run-ocsp-test
@ -995,7 +975,7 @@ tasks:
vars:
OCSP_ALGORITHM: "ecdsa"
SERVER_TYPE: revoked-delegate
- func: "bootstrap mongo-orchestration"
- func: "run-server"
vars:
ORCHESTRATION_FILE: "ecdsa-basic-tls-ocsp-mustStaple.json"
- func: run-ocsp-test
@ -1010,7 +990,7 @@ tasks:
vars:
OCSP_ALGORITHM: "ecdsa"
SERVER_TYPE: valid-delegate
- func: "bootstrap mongo-orchestration"
- func: "run-server"
vars:
ORCHESTRATION_FILE: "ecdsa-basic-tls-ocsp-disableStapling.json"
- func: run-ocsp-test
@ -1025,7 +1005,7 @@ tasks:
vars:
OCSP_ALGORITHM: "ecdsa"
SERVER_TYPE: revoked-delegate
- func: "bootstrap mongo-orchestration"
- func: "run-server"
vars:
ORCHESTRATION_FILE: "ecdsa-basic-tls-ocsp-disableStapling.json"
- func: run-ocsp-test
@ -1040,7 +1020,7 @@ tasks:
vars:
OCSP_ALGORITHM: "ecdsa"
SERVER_TYPE: valid-delegate
- func: "bootstrap mongo-orchestration"
- func: "run-server"
vars:
ORCHESTRATION_FILE: "ecdsa-basic-tls-ocsp-mustStaple-disableStapling.json"
- func: run-ocsp-test
@ -1115,10 +1095,9 @@ tasks:
- name: "perf-6.0-standalone"
tags: ["perf"]
commands:
- func: "bootstrap mongo-orchestration"
- func: "run-server"
vars:
VERSION: "v6.0-perf"
TOPOLOGY: "server"
- func: "run perf tests"
- func: "attach benchmark test results"
- func: "send dashboard data"
@ -1126,10 +1105,9 @@ tasks:
- name: "perf-6.0-standalone-ssl"
tags: ["perf"]
commands:
- func: "bootstrap mongo-orchestration"
- func: "run-server"
vars:
VERSION: "v6.0-perf"
TOPOLOGY: "server"
SSL: "ssl"
- func: "run perf tests"
- func: "attach benchmark test results"
@ -1138,10 +1116,9 @@ tasks:
- name: "perf-8.0-standalone"
tags: ["perf"]
commands:
- func: "bootstrap mongo-orchestration"
- func: "run-server"
vars:
VERSION: "8.0"
TOPOLOGY: "server"
- func: "run perf tests"
- func: "attach benchmark test results"
- func: "send dashboard data"

File diff suppressed because it is too large Load Diff

View File

@ -1,30 +0,0 @@
#!/bin/bash
set -eu
HERE=$(dirname ${BASH_SOURCE:-$0})
HERE="$( cd -- "$HERE" > /dev/null 2>&1 && pwd )"
ROOT=$(dirname "$(dirname $HERE)")
if [ -z "${TEST_CRYPT_SHARED:-}" ]; then
export SKIP_CRYPT_SHARED=1
fi
# Override the tls files if applicable.
if [ "${SSL:-}" == "ssl" ]; then
export TLS_CERT_KEY_FILE=${ROOT}/test/certificates/client.pem
export TLS_PEM_KEY_FILE=${ROOT}/test/certificates/server.pem
export TLS_CA_FILE=${ROOT}/test/certificates/ca.pem
fi
MONGODB_VERSION=${VERSION:-} \
TOPOLOGY=${TOPOLOGY:-} \
AUTH=${AUTH:-} \
SSL=${SSL:-} \
STORAGE_ENGINE=${STORAGE_ENGINE:-} \
DISABLE_TEST_COMMANDS=${DISABLE_TEST_COMMANDS:-} \
ORCHESTRATION_FILE=${ORCHESTRATION_FILE:-} \
REQUIRE_API_VERSION=${REQUIRE_API_VERSION:-} \
LOAD_BALANCER=${LOAD_BALANCER:-} \
bash ${DRIVERS_TOOLS}/.evergreen/run-orchestration.sh
# run-orchestration generates expansion file with the MONGODB_URI for the cluster

View File

@ -795,20 +795,20 @@ def create_server_tasks():
for topo, version, (auth, ssl), sync in product(TOPOLOGIES, ALL_VERSIONS, AUTH_SSLS, SYNCS):
name = f"test-{version}-{topo}-{auth}-{ssl}-{sync}".lower()
tags = [version, topo, auth, ssl, sync]
bootstrap_vars = dict(
server_vars = dict(
VERSION=version,
TOPOLOGY=topo if topo != "standalone" else "server",
AUTH=auth,
SSL=ssl,
)
bootstrap_func = FunctionCall(func="bootstrap mongo-orchestration", vars=bootstrap_vars)
server_func = FunctionCall(func="run-server", vars=server_vars)
test_vars = dict(AUTH=auth, SSL=ssl, SYNC=sync)
if sync == "sync":
test_vars["TEST_NAME"] = "default_sync"
elif sync == "async":
test_vars["TEST_NAME"] = "default_async"
test_func = FunctionCall(func="run tests", vars=test_vars)
tasks.append(EvgTask(name=name, tags=tags, commands=[bootstrap_func, test_func]))
tasks.append(EvgTask(name=name, tags=tags, commands=[server_func, test_func]))
return tasks
@ -817,11 +817,13 @@ def create_load_balancer_tasks():
for auth, ssl in AUTH_SSLS:
name = f"test-load-balancer-{auth}-{ssl}".lower()
tags = ["load-balancer", auth, ssl]
bootstrap_vars = dict(TOPOLOGY="sharded_cluster", AUTH=auth, SSL=ssl, LOAD_BALANCER="true")
bootstrap_func = FunctionCall(func="bootstrap mongo-orchestration", vars=bootstrap_vars)
server_vars = dict(
TOPOLOGY="sharded_cluster", AUTH=auth, SSL=ssl, TEST_NAME="load_balancer"
)
server_func = FunctionCall(func="run-server", vars=server_vars)
test_vars = dict(AUTH=auth, SSL=ssl, TEST_NAME="load_balancer")
test_func = FunctionCall(func="run tests", vars=test_vars)
tasks.append(EvgTask(name=name, tags=tags, commands=[bootstrap_func, test_func]))
tasks.append(EvgTask(name=name, tags=tags, commands=[server_func, test_func]))
return tasks
@ -837,7 +839,7 @@ def create_kms_tasks():
sub_test_name += "-fail"
commands = []
if not success:
commands.append(FunctionCall(func="bootstrap mongo-orchestration"))
commands.append(FunctionCall(func="run-server"))
test_vars = dict(TEST_NAME="kms", SUB_TEST_NAME=sub_test_name)
test_func = FunctionCall(func="run tests", vars=test_vars)
commands.append(test_func)
@ -859,15 +861,15 @@ def create_aws_tasks():
for version in get_versions_from("4.4"):
base_name = f"test-auth-aws-{version}"
base_tags = ["auth-aws"]
bootstrap_vars = dict(AUTH_AWS="1", VERSION=version)
bootstrap_func = FunctionCall(func="bootstrap mongo-orchestration", vars=bootstrap_vars)
server_vars = dict(AUTH_AWS="1", VERSION=version)
server_func = FunctionCall(func="run-server", vars=server_vars)
assume_func = FunctionCall(func="assume ec2 role")
for test_type in aws_test_types:
tags = [*base_tags, f"auth-aws-{test_type}"]
name = f"{base_name}-{test_type}"
test_vars = dict(TEST_NAME="auth_aws", SUB_TEST_NAME=test_type)
test_func = FunctionCall(func="run tests", vars=test_vars)
funcs = [bootstrap_func, assume_func, test_func]
funcs = [server_func, assume_func, test_func]
tasks.append(EvgTask(name=name, tags=tags, commands=funcs))
tags = [*base_tags, "auth-aws-web-identity"]
@ -876,7 +878,7 @@ def create_aws_tasks():
TEST_NAME="auth_aws", SUB_TEST_NAME="web-identity", AWS_ROLE_SESSION_NAME="test"
)
test_func = FunctionCall(func="run tests", vars=test_vars)
funcs = [bootstrap_func, assume_func, test_func]
funcs = [server_func, assume_func, test_func]
tasks.append(EvgTask(name=name, tags=tags, commands=funcs))
return tasks

View File

@ -0,0 +1,13 @@
#!/bin/bash
set -eu
HERE=$(dirname ${BASH_SOURCE:-$0})
# Try to source the env file.
if [ -f $HERE/env.sh ]; then
echo "Sourcing env file"
source $HERE/env.sh
fi
uv run $HERE/run_server.py "$@"

View File

@ -0,0 +1,50 @@
from __future__ import annotations
import os
from typing import Any
from utils import DRIVERS_TOOLS, ROOT, get_test_options, run_command
def set_env(name: str, value: Any = "1") -> None:
os.environ[name] = str(value)
def start_server():
opts, extra_opts = get_test_options(
"Run a MongoDB server. All given flags will be passed to run-orchestration.sh in DRIVERS_TOOLS.",
require_sub_test_name=False,
allow_extra_opts=True,
)
test_name = opts.test_name
if opts.auth:
extra_opts.append("--auth")
if opts.verbose:
extra_opts.append("-v")
elif opts.quiet:
extra_opts.append("-q")
if test_name == "auth_aws":
set_env("AUTH_AWS")
elif test_name == "load_balancer":
set_env("LOAD_BALANCER")
if not os.environ.get("TEST_CRYPT_SHARED"):
set_env("SKIP_CRYPT_SHARED")
if opts.ssl:
extra_opts.append("--ssl")
certs = ROOT / "test/certificates"
set_env("TLS_CERT_KEY_FILE", certs / "client.pem")
set_env("TLS_PEM_KEY_FILE", certs / "server.pem")
set_env("TLS_CA_FILE", certs / "ca.pem")
cmd = ["bash", f"{DRIVERS_TOOLS}/.evergreen/run-orchestration.sh", *extra_opts]
run_command(cmd, cwd=DRIVERS_TOOLS)
if __name__ == "__main__":
start_server()

View File

@ -1,9 +1,7 @@
from __future__ import annotations
import argparse
import base64
import io
import logging
import os
import platform
import shutil
@ -19,7 +17,9 @@ from utils import (
LOGGER,
PLATFORM,
ROOT,
TEST_SUITE_MAP,
Distro,
get_test_options,
read_env,
run_command,
write_env,
@ -28,30 +28,6 @@ from utils import (
# Passthrough environment variables.
PASS_THROUGH_ENV = ["GREEN_FRAMEWORK", "NO_EXT", "MONGODB_API_VERSION", "DEBUG_LOG"]
# Map the test name to a test suite.
TEST_SUITE_MAP = {
"atlas": "atlas",
"auth_aws": "auth_aws",
"auth_oidc": "auth_oidc",
"data_lake": "data_lake",
"default": "",
"default_async": "default_async",
"default_sync": "default",
"encryption": "encryption",
"enterprise_auth": "auth",
"index_management": "index_management",
"kms": "kms",
"load_balancer": "load_balancer",
"mockupdb": "mockupdb",
"pyopenssl": "",
"ocsp": "ocsp",
"perf": "perf",
"serverless": "",
}
# Tests that require a sub test suite.
SUB_TEST_REQUIRED = ["auth_aws", "kms"]
# Map the test name to test extra.
EXTRAS_MAP = {
"auth_aws": "aws",
@ -73,35 +49,6 @@ def is_set(var: str) -> bool:
return len(value.strip()) > 0
def get_options():
parser = argparse.ArgumentParser(
description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
)
parser.add_argument(
"test_name",
choices=sorted(TEST_SUITE_MAP),
nargs="?",
default="default",
help="The name of the test suite to set up, typically the same name as a pytest marker.",
)
parser.add_argument("sub_test_name", nargs="?", help="The sub test name, for example 'azure'")
parser.add_argument(
"--verbose", "-v", action="store_true", help="Whether to log at the DEBUG level"
)
parser.add_argument(
"--quiet", "-q", action="store_true", help="Whether to log at the WARNING level"
)
parser.add_argument("--auth", action="store_true", help="Whether to add authentication")
parser.add_argument("--ssl", action="store_true", help="Whether to add TLS configuration")
# Get the options.
opts = parser.parse_args()
if opts.verbose:
LOGGER.setLevel(logging.DEBUG)
elif opts.quiet:
LOGGER.setLevel(logging.WARNING)
return opts
def get_distro() -> Distro:
name = ""
version_id = ""
@ -166,20 +113,11 @@ def setup_libmongocrypt():
def handle_test_env() -> None:
opts = get_options()
opts, _ = get_test_options("Set up the test environment and services.")
test_name = opts.test_name
sub_test_name = opts.sub_test_name
if test_name in SUB_TEST_REQUIRED and not sub_test_name:
raise ValueError(f"Test '{test_name}' requires a sub_test_name")
AUTH = os.environ.get("AUTH", "noauth")
if opts.auth or "auth" in test_name:
AUTH = "auth"
# 'auth_aws ecs' shouldn't have extra auth set.
if test_name == "auth_aws" and sub_test_name == "ecs":
AUTH = "noauth"
SSL = os.environ.get("SSL", "nossl")
if opts.ssl:
SSL = "ssl"
AUTH = "auth" if opts.auth else "noauth"
SSL = "ssl" if opts.ssl else "nossl"
TEST_ARGS = ""
# Start compiling the args we'll pass to uv.

View File

@ -0,0 +1,14 @@
#!/bin/bash
set -eu
HERE=$(dirname ${BASH_SOURCE:-$0})
HERE="$( cd -- "$HERE" > /dev/null 2>&1 && pwd )"
# Try to source the env file.
if [ -f $HERE/env.sh ]; then
echo "Sourcing env file"
source $HERE/env.sh
fi
bash ${DRIVERS_TOOLS}/.evergreen/stop-orchestration.sh

View File

@ -1,5 +1,6 @@
from __future__ import annotations
import argparse
import dataclasses
import logging
import os
@ -26,6 +27,89 @@ class Distro:
arch: str
# Map the test name to a test suite.
TEST_SUITE_MAP = {
"atlas": "atlas",
"auth_aws": "auth_aws",
"auth_oidc": "auth_oidc",
"data_lake": "data_lake",
"default": "",
"default_async": "default_async",
"default_sync": "default",
"encryption": "encryption",
"enterprise_auth": "auth",
"index_management": "index_management",
"kms": "kms",
"load_balancer": "load_balancer",
"mockupdb": "mockupdb",
"pyopenssl": "",
"ocsp": "ocsp",
"perf": "perf",
"serverless": "",
}
# Tests that require a sub test suite.
SUB_TEST_REQUIRED = ["auth_aws", "kms"]
def get_test_options(
description, require_sub_test_name=True, allow_extra_opts=False
) -> tuple[argparse.Namespace, list[str]]:
parser = argparse.ArgumentParser(
description=description, formatter_class=argparse.RawDescriptionHelpFormatter
)
if require_sub_test_name:
parser.add_argument(
"test_name",
choices=sorted(TEST_SUITE_MAP),
nargs="?",
default="default",
help="The optional name of the test suite to set up, typically the same name as a pytest marker.",
)
parser.add_argument(
"sub_test_name", nargs="?", help="The optional sub test name, for example 'azure'."
)
else:
parser.add_argument(
"test_name",
choices=sorted(TEST_SUITE_MAP),
nargs="?",
default="default",
help="The optional name of the test suite to be run, which informs the server configuration.",
)
parser.add_argument(
"--verbose", "-v", action="store_true", help="Whether to log at the DEBUG level"
)
parser.add_argument(
"--quiet", "-q", action="store_true", help="Whether to log at the WARNING level"
)
parser.add_argument("--auth", action="store_true", help="Whether to add authentication")
parser.add_argument("--ssl", action="store_true", help="Whether to add TLS configuration")
# Get the options.
if not allow_extra_opts:
opts, extra_opts = parser.parse_args(), []
else:
opts, extra_opts = parser.parse_known_args()
if opts.verbose:
LOGGER.setLevel(logging.DEBUG)
elif opts.quiet:
LOGGER.setLevel(logging.WARNING)
# Handle validation and environment variable overrides.
test_name = opts.test_name
sub_test_name = opts.sub_test_name if require_sub_test_name else ""
if require_sub_test_name and test_name in SUB_TEST_REQUIRED and not sub_test_name:
raise ValueError(f"Test '{test_name}' requires a sub_test_name")
if "auth" in test_name or os.environ.get("AUTH") == "auth":
opts.auth = True
# 'auth_aws ecs' shouldn't have extra auth set.
if test_name == "auth_aws" and sub_test_name == "ecs":
opts.auth = False
if os.environ.get("SSL") == "ssl":
opts.ssl = True
return opts, extra_opts
def read_env(path: Path | str) -> dict[str, Any]:
config = dict()
with Path(path).open() as fid:
@ -47,8 +131,10 @@ def write_env(name: str, value: Any = "1") -> None:
fid.write(f'export {name}="{value}"\n')
def run_command(cmd: str, **kwargs: Any) -> None:
LOGGER.info("Running command %s...", cmd)
def run_command(cmd: str | list[str], **kwargs: Any) -> None:
if isinstance(cmd, list):
cmd = " ".join(cmd)
LOGGER.info("Running command '%s'...", cmd)
kwargs.setdefault("check", True)
subprocess.run(shlex.split(cmd), **kwargs) # noqa: PLW1510, S603
LOGGER.info("Running command %s... done.", cmd)
LOGGER.info("Running command '%s'... done.", cmd)

View File

@ -204,25 +204,56 @@ the pages will re-render and the browser will automatically refresh.
`just test test/test_change_stream.py::TestUnifiedChangeStreamsErrors::test_change_stream_errors_on_ElectionInProgress`.
- Use the `-k` argument to select tests by pattern.
## Running Load Balancer Tests Locally
- Install `haproxy` (available as `brew install haproxy` on macOS).
- Clone `drivers-evergreen-tools`:
`git clone git@github.com:mongodb-labs/drivers-evergreen-tools.git`.
- Start the servers using
`LOAD_BALANCER=true TOPOLOGY=sharded_cluster AUTH=noauth SSL=nossl MONGODB_VERSION=6.0 DRIVERS_TOOLS=$PWD/drivers-evergreen-tools MONGO_ORCHESTRATION_HOME=$PWD/drivers-evergreen-tools/.evergreen/orchestration $PWD/drivers-evergreen-tools/.evergreen/run-orchestration.sh`.
- Set up the test using:
`MONGODB_URI='mongodb://localhost:27017,localhost:27018/' just setup-tests load-balancer`.
- Run the tests from the `pymongo` checkout directory using:
`just run-tests`.
## Running tests that require secrets, services, or other configuration
### Prerequisites
## Running Encryption Tests Locally
- Clone `drivers-evergreen-tools`:
`git clone git@github.com:mongodb-labs/drivers-evergreen-tools.git`.
- Run `export DRIVERS_TOOLS=$PWD/drivers-evergreen-tools`
- Run `AWS_PROFILE=<profile> just setup-tests encryption` after setting up your AWS profile with `aws configure sso`.
`git clone git@github.com:mongodb-labs/drivers-evergreen-tools.git`.
- Run `export DRIVERS_TOOLS=$PWD/drivers-evergreen-tools`. This can be put into a `.bashrc` file
for convenience.
- Set up access to [Drivers test secrets](https://github.com/mongodb-labs/drivers-evergreen-tools/tree/master/.evergreen/secrets_handling#secrets-handling).
### Usage
- Run `just run-server` with optional args to set up the server.
All given flags will be passed to `run-orchestration.sh` in `DRIVERS_TOOLS`.
- Run `just setup-tests` with optional args to set up the test environment, secrets, etc.
- Run `just run-tests` to run the tests in an appropriate Python environment.
- When done, run `just teardown-tests` to clean up and `just stop-server` to stop the server.
## Encryption tests
- Run `just run-server` to start the server.
- Run `just setup-tests encryption`.
- Run the tests with `just run-tests`.
- When done, run `just teardown-tests` to clean up.
### Load balancer tests
- Install `haproxy` (available as `brew install haproxy` on macOS).
- Start the server with `just run-server load_balancer`.
- Set up the test with `just setup-tests load_balancer`.
- Run the tests with `just run-tests`.
## AWS tests
- Run `just run-server auth_aws` to start the server.
- Run `just setup-tests auth_aws <aws-test-type>` to set up the AWS test.
- Run the tests with `just run-tests`.
## KMS tests
For KMS tests that are run locally, and expected to fail, in this case using `azure`:
- Run `just run-server`.
- Run `just setup-tests kms azure-fail`.
- Run `just run-tests`.
For KMS tests that run remotely and are expected to pass, in this case using `gcp`:
- Run `just setup-tests kms gcp`.
- Run `just run-tests`.
## Enable Debug Logs
- Use `-o log_cli_level="DEBUG" -o log_cli=1` with `just test` or `pytest`.

View File

@ -71,3 +71,11 @@ setup-tests *args="":
[group('test')]
teardown-tests:
bash .evergreen/scripts/teardown-tests.sh
[group('server')]
run-server *args="":
bash .evergreen/scripts/run-server.sh {{args}}
[group('server')]
stop-server:
bash .evergreen/scripts/stop-server.sh

View File

@ -57,19 +57,6 @@
"tests": [
{
"description": "operations against non-load balanced clusters fail if URI contains loadBalanced=true",
"runOnRequirements": [
{
"maxServerVersion": "8.0.99",
"topologies": [
"single"
]
},
{
"topologies": [
"sharded"
]
}
],
"operations": [
{
"name": "runCommand",