Skip to content

Commit 134f52f

Browse files
authored
PYTHON-5213 Convert AWS Lambda and Search Index tests to use new test scripts (#2205)
1 parent dc44b49 commit 134f52f

16 files changed

+164
-135
lines changed

.evergreen/config.yml

+1-79
Original file line numberDiff line numberDiff line change
@@ -268,27 +268,7 @@ functions:
268268
- command: ec2.assume_role
269269
params:
270270
role_arn: ${aws_test_secrets_role}
271-
272-
"setup atlas":
273-
- command: subprocess.exec
274-
params:
275-
binary: bash
276-
include_expansions_in_env: ["task_id", "execution"]
277-
env:
278-
MONGODB_VERSION: "7.0"
279-
LAMBDA_STACK_NAME: dbx-python-lambda
280-
args:
281-
- ${DRIVERS_TOOLS}/.evergreen/atlas/setup-atlas-cluster.sh
282-
- command: expansions.update
283-
params:
284-
file: atlas-expansion.yml
285-
286-
"teardown atlas":
287-
- command: subprocess.exec
288-
params:
289-
binary: bash
290-
args:
291-
- ${DRIVERS_TOOLS}/.evergreen/atlas/teardown-atlas-cluster.sh
271+
duration_seconds: 3600
292272

293273
"attach benchmark test results":
294274
- command: attach.results
@@ -314,31 +294,6 @@ post:
314294
- func: "upload test results"
315295
- func: "cleanup"
316296

317-
task_groups:
318-
- name: test_aws_lambda_task_group
319-
setup_group:
320-
- func: fetch source
321-
- func: setup system
322-
- func: setup atlas
323-
teardown_task:
324-
- func: teardown atlas
325-
setup_group_can_fail_task: true
326-
setup_group_timeout_secs: 1800
327-
tasks:
328-
- test-aws-lambda-deployed
329-
330-
- name: test_atlas_task_group_search_indexes
331-
setup_group:
332-
- func: fetch source
333-
- func: setup system
334-
- func: setup atlas
335-
teardown_task:
336-
- func: teardown atlas
337-
setup_group_can_fail_task: true
338-
setup_group_timeout_secs: 1800
339-
tasks:
340-
- test-search-index-helpers
341-
342297
tasks:
343298
# Wildcard task. Do you need to find out what tools are available and where?
344299
# Throw it here, and execute this task on all buildvariants
@@ -365,17 +320,6 @@ tasks:
365320
- func: "run server"
366321
- func: "run doctests"
367322

368-
- name: "test-search-index-helpers"
369-
commands:
370-
- func: "run server"
371-
vars:
372-
VERSION: "6.0"
373-
TOPOLOGY: "replica_set"
374-
- func: "run tests"
375-
vars:
376-
TEST_NAME: index_management
377-
AUTH: "auth"
378-
379323
- name: "no-server"
380324
tags: ["no-server"]
381325
commands:
@@ -390,22 +334,6 @@ tasks:
390334
TOPOLOGY: "replica_set"
391335
- func: "run tests"
392336

393-
- name: "test-aws-lambda-deployed"
394-
commands:
395-
- command: ec2.assume_role
396-
params:
397-
role_arn: ${LAMBDA_AWS_ROLE_ARN}
398-
duration_seconds: 3600
399-
- command: subprocess.exec
400-
params:
401-
working_dir: src
402-
binary: bash
403-
add_expansions_to_env: true
404-
args:
405-
- .evergreen/run-deployed-lambda-aws-tests.sh
406-
env:
407-
TEST_LAMBDA_DIRECTORY: ${PROJECT_DIRECTORY}/test/lambda
408-
409337
# }}}
410338
- name: "coverage-report"
411339
tags: ["coverage"]
@@ -482,12 +410,6 @@ buildvariants:
482410
batchtime: 10080 # 7 days
483411
- name: test-azurekms-fail
484412

485-
- name: rhel8-test-lambda
486-
display_name: FaaS Lambda
487-
run_on: rhel87-small
488-
tasks:
489-
- name: test_aws_lambda_task_group
490-
491413
- name: rhel8-import-time
492414
display_name: Import Time
493415
run_on: rhel87-small

.evergreen/generated_configs/tasks.yml

+21
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:
@@ -1220,6 +1229,18 @@ tasks:
12201229
- func: send dashboard data
12211230
tags: [perf]
12221231

1232+
# Search index tests
1233+
- name: test-search-index-helpers
1234+
commands:
1235+
- func: assume ec2 role
1236+
- func: run server
1237+
vars:
1238+
TEST_NAME: search_index
1239+
- func: run tests
1240+
vars:
1241+
TEST_NAME: search_index
1242+
tags: [search_index]
1243+
12231244
# Server tests
12241245
- name: test-4.0-standalone-auth-ssl-sync
12251246
commands:

.evergreen/generated_configs/variants.yml

+9-1
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:
@@ -986,7 +994,7 @@ buildvariants:
986994
# Search index tests
987995
- name: search-index-helpers-rhel8-python3.9
988996
tasks:
989-
- name: test_atlas_task_group_search_indexes
997+
- name: .search_index
990998
display_name: Search Index Helpers RHEL8 Python3.9
991999
run_on:
9921000
- rhel87-small

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

-10
This file was deleted.

.evergreen/scripts/generate_config.py

+27-1
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,
@@ -779,6 +779,11 @@ def create_alternative_hosts_variants():
779779
return variants
780780

781781

782+
def create_aws_lambda_variants():
783+
host = HOSTS["rhel8"]
784+
return [create_variant([".aws_lambda"], display_name="FaaS Lambda", host=host)]
785+
786+
782787
##############
783788
# Tasks
784789
##############
@@ -927,6 +932,27 @@ def _create_ocsp_task(algo, variant, server_type, base_task_name):
927932
return EvgTask(name=task_name, tags=tags, commands=commands)
928933

929934

935+
def create_aws_lambda_tasks():
936+
assume_func = FunctionCall(func="assume ec2 role")
937+
vars = dict(TEST_NAME="aws_lambda")
938+
test_func = FunctionCall(func="run tests", vars=vars)
939+
task_name = "test-aws-lambda-deployed"
940+
tags = ["aws_lambda"]
941+
commands = [assume_func, test_func]
942+
return [EvgTask(name=task_name, tags=tags, commands=commands)]
943+
944+
945+
def create_search_index_tasks():
946+
assume_func = FunctionCall(func="assume ec2 role")
947+
server_func = FunctionCall(func="run server", vars=dict(TEST_NAME="search_index"))
948+
vars = dict(TEST_NAME="search_index")
949+
test_func = FunctionCall(func="run tests", vars=vars)
950+
task_name = "test-search-index-helpers"
951+
tags = ["search_index"]
952+
commands = [assume_func, server_func, test_func]
953+
return [EvgTask(name=task_name, tags=tags, commands=commands)]
954+
955+
930956
def create_atlas_connect_tasks():
931957
vars = dict(TEST_NAME="atlas_connect")
932958
assume_func = FunctionCall(func="assume ec2 role")

.evergreen/scripts/run_server.py

+12-8
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

+44
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

+23-1
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,28 @@ def handle_test_env() -> None:
175175
if not config:
176176
AUTH = "noauth"
177177

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

.evergreen/scripts/teardown_tests.py

+4
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)