|
6 | 6 | import platform
|
7 | 7 | import shutil
|
8 | 8 | import sys
|
9 |
| -import tarfile |
10 |
| -import tempfile |
11 | 9 | from datetime import datetime
|
| 10 | +from pathlib import Path |
12 | 11 | from shutil import which
|
13 | 12 |
|
14 | 13 | import pytest
|
15 |
| -from utils import DRIVERS_TOOLS, LOGGER, ROOT, create_archive, run_command |
| 14 | +from utils import DRIVERS_TOOLS, LOGGER, ROOT, run_command |
16 | 15 |
|
17 | 16 | AUTH = os.environ.get("AUTH", "noauth")
|
18 | 17 | SSL = os.environ.get("SSL", "nossl")
|
@@ -89,19 +88,33 @@ def handle_aws_lambda() -> None:
|
89 | 88 | env = os.environ.copy()
|
90 | 89 | target_dir = ROOT / "test/lambda"
|
91 | 90 | env["TEST_LAMBDA_DIRECTORY"] = str(target_dir)
|
92 |
| - archive = create_archive() |
93 |
| - with tempfile.TemporaryDirectory() as td: |
94 |
| - # Unpack the archive |
95 |
| - fid = tarfile.open(archive) |
96 |
| - fid.extractall(td) |
97 |
| - fid.close() |
98 |
| - # Build the c extensions. |
99 |
| - docker = which("docker") or which("podman") |
100 |
| - if not docker: |
101 |
| - raise ValueError("Could not find docker!") |
102 |
| - image = "quay.io/pypa/manylinux2014_x86_64:latest" |
103 |
| - run_command(f'{docker} run --rm -v "{td}:/src" {image} /src/test/lambda/build_internal.sh') |
104 |
| - shutil.copytree(td, ROOT / "test/lambda/mongodb") |
| 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() |
105 | 118 |
|
106 | 119 | script_name = "run-deployed-lambda-aws-tests.sh"
|
107 | 120 | run_command(f"bash {DRIVERS_TOOLS}/.evergreen/aws_lambda/{script_name}", env=env)
|
|
0 commit comments