Skip to content

Commit 96ed88f

Browse files
committed
Merge branch 'master' of github.com:mongodb/mongo-python-driver into doctests-mockupdb
2 parents 4bf8d98 + 134f52f commit 96ed88f

File tree

16 files changed

+164
-137
lines changed

16 files changed

+164
-137
lines changed

.evergreen/config.yml

Lines changed: 1 addition & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -265,27 +265,7 @@ functions:
265265
- command: ec2.assume_role
266266
params:
267267
role_arn: ${aws_test_secrets_role}
268-
269-
"setup atlas":
270-
- command: subprocess.exec
271-
params:
272-
binary: bash
273-
include_expansions_in_env: ["task_id", "execution"]
274-
env:
275-
MONGODB_VERSION: "7.0"
276-
LAMBDA_STACK_NAME: dbx-python-lambda
277-
args:
278-
- ${DRIVERS_TOOLS}/.evergreen/atlas/setup-atlas-cluster.sh
279-
- command: expansions.update
280-
params:
281-
file: atlas-expansion.yml
282-
283-
"teardown atlas":
284-
- command: subprocess.exec
285-
params:
286-
binary: bash
287-
args:
288-
- ${DRIVERS_TOOLS}/.evergreen/atlas/teardown-atlas-cluster.sh
268+
duration_seconds: 3600
289269

290270
"attach benchmark test results":
291271
- command: attach.results
@@ -311,31 +291,6 @@ post:
311291
- func: "upload test results"
312292
- func: "cleanup"
313293

314-
task_groups:
315-
- name: test_aws_lambda_task_group
316-
setup_group:
317-
- func: fetch source
318-
- func: setup system
319-
- func: setup atlas
320-
teardown_task:
321-
- func: teardown atlas
322-
setup_group_can_fail_task: true
323-
setup_group_timeout_secs: 1800
324-
tasks:
325-
- test-aws-lambda-deployed
326-
327-
- name: test_atlas_task_group_search_indexes
328-
setup_group:
329-
- func: fetch source
330-
- func: setup system
331-
- func: setup atlas
332-
teardown_task:
333-
- func: teardown atlas
334-
setup_group_can_fail_task: true
335-
setup_group_timeout_secs: 1800
336-
tasks:
337-
- test-search-index-helpers
338-
339294
tasks:
340295
# Wildcard task. Do you need to find out what tools are available and where?
341296
# Throw it here, and execute this task on all buildvariants
@@ -347,36 +302,7 @@ tasks:
347302
params:
348303
args:
349304
- src/.evergreen/scripts/run-getdata.sh
350-
# Standard test tasks {{{
351305

352-
- name: "test-search-index-helpers"
353-
commands:
354-
- func: "run server"
355-
vars:
356-
VERSION: "6.0"
357-
TOPOLOGY: "replica_set"
358-
- func: "run tests"
359-
vars:
360-
TEST_NAME: index_management
361-
AUTH: "auth"
362-
363-
- name: "test-aws-lambda-deployed"
364-
commands:
365-
- command: ec2.assume_role
366-
params:
367-
role_arn: ${LAMBDA_AWS_ROLE_ARN}
368-
duration_seconds: 3600
369-
- command: subprocess.exec
370-
params:
371-
working_dir: src
372-
binary: bash
373-
add_expansions_to_env: true
374-
args:
375-
- .evergreen/run-deployed-lambda-aws-tests.sh
376-
env:
377-
TEST_LAMBDA_DIRECTORY: ${PROJECT_DIRECTORY}/test/lambda
378-
379-
# }}}
380306
- name: "coverage-report"
381307
tags: ["coverage"]
382308
depends_on:
@@ -446,12 +372,6 @@ buildvariants:
446372
batchtime: 10080 # 7 days
447373
- name: test-azurekms-fail
448374

449-
- name: rhel8-test-lambda
450-
display_name: FaaS Lambda
451-
run_on: rhel87-small
452-
tasks:
453-
- name: test_aws_lambda_task_group
454-
455375
- name: rhel8-import-time
456376
display_name: Import Time
457377
run_on: rhel87-small

.evergreen/generated_configs/tasks.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ tasks:
2323
TEST_NAME: data_lake
2424
tags: [atlas_data_lake]
2525

26+
# Aws lambda tests
27+
- name: test-aws-lambda-deployed
28+
commands:
29+
- func: assume ec2 role
30+
- func: run tests
31+
vars:
32+
TEST_NAME: aws_lambda
33+
tags: [aws_lambda]
34+
2635
# Aws tests
2736
- name: test-auth-aws-4.4-regular
2837
commands:
@@ -1253,6 +1262,18 @@ tasks:
12531262
- func: send dashboard data
12541263
tags: [perf]
12551264

1265+
# Search index tests
1266+
- name: test-search-index-helpers
1267+
commands:
1268+
- func: assume ec2 role
1269+
- func: run server
1270+
vars:
1271+
TEST_NAME: search_index
1272+
- func: run tests
1273+
vars:
1274+
TEST_NAME: search_index
1275+
tags: [search_index]
1276+
12561277
# Server tests
12571278
- name: test-4.0-standalone-auth-ssl-sync
12581279
commands:

.evergreen/generated_configs/variants.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,14 @@ buildvariants:
132132
expansions:
133133
PYTHON_BINARY: /Library/Frameworks/Python.Framework/Versions/3.13/bin/python3
134134

135+
# Aws lambda tests
136+
- name: faas-lambda
137+
tasks:
138+
- name: .aws_lambda
139+
display_name: FaaS Lambda
140+
run_on:
141+
- rhel87-small
142+
135143
# Compression tests
136144
- name: compression-snappy-rhel8-python3.9-no-c
137145
tasks:
@@ -994,7 +1002,7 @@ buildvariants:
9941002
# Search index tests
9951003
- name: search-index-helpers-rhel8-python3.9
9961004
tasks:
997-
- name: test_atlas_task_group_search_indexes
1005+
- name: .search_index
9981006
display_name: Search Index Helpers RHEL8 Python3.9
9991007
run_on:
10001008
- rhel87-small

.evergreen/run-deployed-lambda-aws-tests.sh

Lines changed: 0 additions & 10 deletions
This file was deleted.

.evergreen/scripts/generate_config.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ def create_search_index_variants():
672672
python = CPYTHONS[0]
673673
return [
674674
create_variant(
675-
["test_atlas_task_group_search_indexes"],
675+
[".search_index"],
676676
get_display_name("Search Index Helpers", host, python=python),
677677
python=python,
678678
host=host,
@@ -784,6 +784,11 @@ def create_alternative_hosts_variants():
784784
return variants
785785

786786

787+
def create_aws_lambda_variants():
788+
host = HOSTS["rhel8"]
789+
return [create_variant([".aws_lambda"], display_name="FaaS Lambda", host=host)]
790+
791+
787792
##############
788793
# Tasks
789794
##############
@@ -932,6 +937,27 @@ def _create_ocsp_task(algo, variant, server_type, base_task_name):
932937
return EvgTask(name=task_name, tags=tags, commands=commands)
933938

934939

940+
def create_aws_lambda_tasks():
941+
assume_func = FunctionCall(func="assume ec2 role")
942+
vars = dict(TEST_NAME="aws_lambda")
943+
test_func = FunctionCall(func="run tests", vars=vars)
944+
task_name = "test-aws-lambda-deployed"
945+
tags = ["aws_lambda"]
946+
commands = [assume_func, test_func]
947+
return [EvgTask(name=task_name, tags=tags, commands=commands)]
948+
949+
950+
def create_search_index_tasks():
951+
assume_func = FunctionCall(func="assume ec2 role")
952+
server_func = FunctionCall(func="run server", vars=dict(TEST_NAME="search_index"))
953+
vars = dict(TEST_NAME="search_index")
954+
test_func = FunctionCall(func="run tests", vars=vars)
955+
task_name = "test-search-index-helpers"
956+
tags = ["search_index"]
957+
commands = [assume_func, server_func, test_func]
958+
return [EvgTask(name=task_name, tags=tags, commands=commands)]
959+
960+
935961
def create_atlas_connect_tasks():
936962
vars = dict(TEST_NAME="atlas_connect")
937963
assume_func = FunctionCall(func="assume ec2 role")

.evergreen/scripts/run_server.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,6 @@ def start_server():
2222
if "VERSION" in os.environ:
2323
os.environ["MONGODB_VERSION"] = os.environ["VERSION"]
2424

25-
if opts.auth:
26-
extra_opts.append("--auth")
27-
28-
if opts.verbose:
29-
extra_opts.append("-v")
30-
elif opts.quiet:
31-
extra_opts.append("-q")
32-
3325
if test_name == "auth_aws":
3426
set_env("AUTH_AWS")
3527

@@ -51,6 +43,10 @@ def start_server():
5143
if not found:
5244
raise ValueError("Please provide an orchestration file")
5345

46+
elif test_name == "search_index":
47+
os.environ["TOPOLOGY"] = "replica_set"
48+
os.environ["MONGODB_VERSION"] = "7.0"
49+
5450
if not os.environ.get("TEST_CRYPT_SHARED"):
5551
set_env("SKIP_CRYPT_SHARED")
5652

@@ -62,6 +58,14 @@ def start_server():
6258
set_env("TLS_PEM_KEY_FILE", certs / "server.pem")
6359
set_env("TLS_CA_FILE", certs / "ca.pem")
6460

61+
if opts.auth:
62+
extra_opts.append("--auth")
63+
64+
if opts.verbose:
65+
extra_opts.append("-v")
66+
elif opts.quiet:
67+
extra_opts.append("-q")
68+
6569
cmd = ["bash", f"{DRIVERS_TOOLS}/.evergreen/run-orchestration.sh", *extra_opts]
6670
run_command(cmd, cwd=DRIVERS_TOOLS)
6771

.evergreen/scripts/run_tests.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
import logging
55
import os
66
import platform
7+
import shutil
78
import sys
89
from datetime import datetime
10+
from pathlib import Path
11+
from shutil import which
912

1013
import pytest
1114
from utils import DRIVERS_TOOLS, LOGGER, ROOT, run_command
@@ -81,6 +84,42 @@ def handle_pymongocrypt() -> None:
8184
LOGGER.info(f"libmongocrypt version: {pymongocrypt.libmongocrypt_version()})")
8285

8386

87+
def handle_aws_lambda() -> None:
88+
env = os.environ.copy()
89+
target_dir = ROOT / "test/lambda"
90+
env["TEST_LAMBDA_DIRECTORY"] = str(target_dir)
91+
env.setdefault("AWS_REGION", "us-east-1")
92+
dirs = ["pymongo", "gridfs", "bson"]
93+
# Store the original .so files.
94+
before_sos = []
95+
for dname in dirs:
96+
before_sos.extend(f"{f.parent.name}/{f.name}" for f in (ROOT / dname).glob("*.so"))
97+
# Build the c extensions.
98+
docker = which("docker") or which("podman")
99+
if not docker:
100+
raise ValueError("Could not find docker!")
101+
image = "quay.io/pypa/manylinux2014_x86_64:latest"
102+
run_command(
103+
f'{docker} run --rm -v "{ROOT}:/src" --platform linux/amd64 {image} /src/test/lambda/build_internal.sh'
104+
)
105+
for dname in dirs:
106+
target = ROOT / "test/lambda/mongodb" / dname
107+
shutil.rmtree(target, ignore_errors=True)
108+
shutil.copytree(ROOT / dname, target)
109+
# Remove the original so files from the lambda directory.
110+
for so_path in before_sos:
111+
(ROOT / "test/lambda/mongodb" / so_path).unlink()
112+
# Remove the new so files from the ROOT directory.
113+
for dname in dirs:
114+
so_paths = [f"{f.parent.name}/{f.name}" for f in (ROOT / dname).glob("*.so")]
115+
for so_path in list(so_paths):
116+
if so_path not in before_sos:
117+
Path(so_path).unlink()
118+
119+
script_name = "run-deployed-lambda-aws-tests.sh"
120+
run_command(f"bash {DRIVERS_TOOLS}/.evergreen/aws_lambda/{script_name}", env=env)
121+
122+
84123
def run() -> None:
85124
# Handle green framework first so they can patch modules.
86125
if GREEN_FRAMEWORK:
@@ -129,6 +168,11 @@ def run() -> None:
129168
test_oidc_send_to_remote(SUB_TEST_NAME)
130169
return
131170

171+
# Run deployed aws lambda tests.
172+
if TEST_NAME == "aws_lambda":
173+
handle_aws_lambda()
174+
return
175+
132176
if os.environ.get("DEBUG_LOG"):
133177
TEST_ARGS.extend(f"-o log_cli_level={logging.DEBUG} -o log_cli=1".split())
134178

.evergreen/scripts/setup_tests.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,28 @@ def handle_test_env() -> None:
174174
if not config:
175175
AUTH = "noauth"
176176

177+
if test_name in ["aws_lambda", "search_index"]:
178+
env = os.environ.copy()
179+
env["MONGODB_VERSION"] = "7.0"
180+
env["LAMBDA_STACK_NAME"] = "dbx-python-lambda"
181+
write_env("LAMBDA_STACK_NAME", env["LAMBDA_STACK_NAME"])
182+
run_command(
183+
f"bash {DRIVERS_TOOLS}/.evergreen/atlas/setup-atlas-cluster.sh",
184+
env=env,
185+
cwd=DRIVERS_TOOLS,
186+
)
187+
188+
if test_name == "search_index":
189+
AUTH = "auth"
190+
191+
if test_name == "aws_lambda":
192+
UV_ARGS.append("--with pip")
193+
# Store AWS creds if they were given.
194+
if "AWS_ACCESS_KEY_ID" in os.environ:
195+
for key in ["AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_SESSION_TOKEN"]:
196+
if key in os.environ:
197+
write_env(key, os.environ[key])
198+
177199
if test_name == "data_lake":
178200
# Stop any running mongo-orchestration which might be using the port.
179201
run_command(f"bash {DRIVERS_TOOLS}/.evergreen/stop-orchestration.sh")
@@ -196,7 +218,7 @@ def handle_test_env() -> None:
196218
elif test_name == "auth_oidc":
197219
DB_USER = config["OIDC_ADMIN_USER"]
198220
DB_PASSWORD = config["OIDC_ADMIN_PWD"]
199-
elif test_name == "index_management":
221+
elif test_name == "search_index":
200222
config = read_env(f"{DRIVERS_TOOLS}/.evergreen/atlas/secrets-export.sh")
201223
DB_USER = config["DRIVERS_ATLAS_LAMBDA_USER"]
202224
DB_PASSWORD = config["DRIVERS_ATLAS_LAMBDA_PASSWORD"]

.evergreen/scripts/teardown_tests.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
elif TEST_NAME == "serverless":
4141
run_command(f"bash {DRIVERS_TOOLS}/.evergreen/serverless/teardown.sh")
4242

43+
# Tear down atlas cluster if applicable.
44+
if TEST_NAME in ["aws_lambda", "search_index"]:
45+
run_command(f"bash {DRIVERS_TOOLS}/.evergreen/atlas/teardown-atlas-cluster.sh")
46+
4347
# Tear down auth_aws if applicable.
4448
# We do not run web-identity hosts on macos, because the hosts lack permissions,
4549
# so there is no reason to run the teardown, which would error with a 401.

0 commit comments

Comments
 (0)