Skip to content

Commit 2ea3ed4

Browse files
committed
Merge branch 'master' of github.com:mongodb/mongo-python-driver into setup-test-cli
2 parents 901f888 + 4e672bd commit 2ea3ed4

File tree

6 files changed

+84
-66
lines changed

6 files changed

+84
-66
lines changed

.evergreen/run-azurekms-fail-test.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
set -o errexit # Exit the script with error if any of the commands fail
33
HERE=$(dirname ${BASH_SOURCE:-$0})
44
. $DRIVERS_TOOLS/.evergreen/csfle/azurekms/setup-secrets.sh
5-
export LIBMONGOCRYPT_URL=https://s3.amazonaws.com/mciuploads/libmongocrypt/debian11/master/latest/libmongocrypt.tar.gz
65
bash $HERE/just.sh setup-test kms azure-fail
7-
PYTHON_BINARY=/opt/mongodbtoolchain/v4/bin/python3 \
8-
KEY_NAME="${AZUREKMS_KEYNAME}" \
6+
KEY_NAME="${AZUREKMS_KEYNAME}" \
97
KEY_VAULT_ENDPOINT="${AZUREKMS_KEYVAULTENDPOINT}" \
108
$HERE/just.sh test-eg
119
bash $HERE/scripts/teardown-tests.sh

.evergreen/run-azurekms-test.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ echo "Copying files ... begin"
66
export AZUREKMS_RESOURCEGROUP=${AZUREKMS_RESOURCEGROUP}
77
export AZUREKMS_VMNAME=${AZUREKMS_VMNAME}
88
export AZUREKMS_PRIVATEKEYPATH=/tmp/testazurekms_privatekey
9-
LIBMONGOCRYPT_URL=https://s3.amazonaws.com/mciuploads/libmongocrypt/debian11/master/latest/libmongocrypt.tar.gz
109
# Set up the remote files to test.
1110
git add .
1211
git commit -m "add files" || true
@@ -20,7 +19,7 @@ AZUREKMS_CMD="tar xf mongo-python-driver.tgz" \
2019
$DRIVERS_TOOLS/.evergreen/csfle/azurekms/run-command.sh
2120
echo "Untarring file ... end"
2221
echo "Running test ... begin"
23-
AZUREKMS_CMD="LIBMONGOCRYPT_URL=$LIBMONGOCRYPT_URL bash .evergreen/just.sh setup-test kms azure" \
22+
AZUREKMS_CMD="bash .evergreen/just.sh setup-test kms azure" \
2423
$DRIVERS_TOOLS/.evergreen/csfle/azurekms/run-command.sh
2524
AZUREKMS_CMD="KEY_NAME=\"$AZUREKMS_KEYNAME\" KEY_VAULT_ENDPOINT=\"$AZUREKMS_KEYVAULTENDPOINT\" bash ./.evergreen/just.sh test-eg" \
2625
$DRIVERS_TOOLS/.evergreen/csfle/azurekms/run-command.sh

.evergreen/run-gcpkms-test.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export GCPKMS_GCLOUD=${GCPKMS_GCLOUD}
88
export GCPKMS_PROJECT=${GCPKMS_PROJECT}
99
export GCPKMS_ZONE=${GCPKMS_ZONE}
1010
export GCPKMS_INSTANCENAME=${GCPKMS_INSTANCENAME}
11-
LIBMONGOCRYPT_URL=https://s3.amazonaws.com/mciuploads/libmongocrypt/debian11/master/latest/libmongocrypt.tar.gz
1211
# Set up the remote files to test.
1312
git add .
1413
git commit -m "add files" || true
@@ -19,7 +18,7 @@ echo "Untarring file ... begin"
1918
GCPKMS_CMD="tar xf mongo-python-driver.tgz" $DRIVERS_TOOLS/.evergreen/csfle/gcpkms/run-command.sh
2019
echo "Untarring file ... end"
2120
echo "Running test ... begin"
22-
GCPKMS_CMD="LIBMONGOCRYPT_URL=$LIBMONGOCRYPT_URL bash ./.evergreen/just.sh setup-test kms gcp" $DRIVERS_TOOLS/.evergreen/csfle/gcpkms/run-command.sh
21+
GCPKMS_CMD="bash ./.evergreen/just.sh setup-test kms gcp" $DRIVERS_TOOLS/.evergreen/csfle/gcpkms/run-command.sh
2322
GCPKMS_CMD="./.evergreen/just.sh test-eg" $DRIVERS_TOOLS/.evergreen/csfle/gcpkms/run-command.sh
2423
echo "Running test ... end"
2524
bash $HERE/scripts/teardown-tests.sh

.evergreen/scripts/run-gcpkms-fail-test.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,5 @@
22
set -eu
33
HERE=$(dirname ${BASH_SOURCE:-$0})
44
. $HERE/env.sh
5-
export PYTHON_BINARY=/opt/mongodbtoolchain/v4/bin/python3
6-
export LIBMONGOCRYPT_URL=https://s3.amazonaws.com/mciuploads/libmongocrypt/debian11/master/latest/libmongocrypt.tar.gz
75
./.evergreen/just.sh setup-test kms gcp-fail
86
bash ./.evergreen/just.sh test-eg

.evergreen/scripts/setup-libmongocrypt.sh

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

.evergreen/scripts/setup-tests.py renamed to .evergreen/scripts/setup_tests.py

Lines changed: 81 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,26 @@
22

33
import argparse
44
import base64
5+
import dataclasses
6+
import io
57
import logging
68
import os
79
import platform
810
import shlex
11+
import shutil
912
import stat
1013
import subprocess
1114
import sys
15+
import tarfile
1216
from pathlib import Path
1317
from typing import Any
18+
from urllib import request
1419

1520
HERE = Path(__file__).absolute().parent
1621
ROOT = HERE.parent.parent
1722
ENV_FILE = HERE / "test-env.sh"
1823
DRIVERS_TOOLS = os.environ.get("DRIVERS_TOOLS", "").replace(os.sep, "/")
24+
PLATFORM = "windows" if os.name == "nt" else sys.platform
1925

2026
LOGGER = logging.getLogger(__name__)
2127
logging.basicConfig(level=logging.INFO, format="%(levelname)-8s %(message)s")
@@ -63,6 +69,13 @@
6369
GROUP_MAP = dict(mockupdb="mockupdb", perf="perf")
6470

6571

72+
@dataclasses.dataclass
73+
class Distro:
74+
name: str
75+
version_id: str
76+
arch: str
77+
78+
6679
def write_env(name: str, value: Any = "1") -> None:
6780
with ENV_FILE.open("a", newline="\n") as fid:
6881
# Remove any existing quote chars.
@@ -118,6 +131,69 @@ def get_options():
118131
return opts
119132

120133

134+
def get_distro() -> Distro:
135+
name = ""
136+
version_id = ""
137+
arch = platform.machine()
138+
with open("/etc/os-release") as fid:
139+
for line in fid.readlines():
140+
line = line.replace('"', "") # noqa: PLW2901
141+
if line.startswith("NAME="):
142+
_, _, name = line.strip().partition("=")
143+
if line.startswith("VERSION_ID="):
144+
_, _, version_id = line.strip().partition("=")
145+
return Distro(name=name, version_id=version_id, arch=arch)
146+
147+
148+
def setup_libmongocrypt():
149+
target = ""
150+
if PLATFORM == "windows":
151+
# PYTHON-2808 Ensure this machine has the CA cert for google KMS.
152+
if is_set("TEST_FLE_GCP_AUTO"):
153+
run_command('powershell.exe "Invoke-WebRequest -URI https://oauth2.googleapis.com/"')
154+
target = "windows-test"
155+
156+
elif PLATFORM == "darwin":
157+
target = "macos"
158+
159+
else:
160+
distro = get_distro()
161+
if distro.name.startswith("Debian"):
162+
target = f"debian{distro.version_id}"
163+
elif distro.name.startswith("Red Hat"):
164+
if distro.version_id.startswith("7"):
165+
target = "rhel-70-64-bit"
166+
elif distro.version_id.startswith("8"):
167+
if distro.arch == "aarch64":
168+
target = "rhel-82-arm64"
169+
else:
170+
target = "rhel-80-64-bit"
171+
172+
if not is_set("LIBMONGOCRYPT_URL"):
173+
if not target:
174+
raise ValueError("Cannot find libmongocrypt target for current platform!")
175+
url = f"https://s3.amazonaws.com/mciuploads/libmongocrypt/{target}/master/latest/libmongocrypt.tar.gz"
176+
else:
177+
url = os.environ["LIBMONGOCRYPT_URL"]
178+
179+
shutil.rmtree(HERE / "libmongocrypt", ignore_errors=True)
180+
181+
LOGGER.info(f"Fetching {url}...")
182+
with request.urlopen(request.Request(url), timeout=15.0) as response: # noqa: S310
183+
if response.status == 200:
184+
fileobj = io.BytesIO(response.read())
185+
with tarfile.open("libmongocrypt.tar.gz", fileobj=fileobj) as fid:
186+
fid.extractall(Path.cwd() / "libmongocrypt")
187+
LOGGER.info(f"Fetching {url}... done.")
188+
189+
run_command("ls -la libmongocrypt")
190+
run_command("ls -la libmongocrypt/nocrypto")
191+
192+
if PLATFORM == "windows":
193+
# libmongocrypt's windows dll is not marked executable.
194+
run_command("chmod +x libmongocrypt/nocrypto/bin/mongocrypt.dll")
195+
196+
121197
def handle_test_env() -> None:
122198
opts = get_options()
123199
test_name = opts.test_name
@@ -209,7 +285,7 @@ def handle_test_env() -> None:
209285

210286
if test_name == "enterprise_auth":
211287
config = read_env(f"{ROOT}/secrets-export.sh")
212-
if os.name == "nt":
288+
if PLATFORM == "windows":
213289
LOGGER.info("Setting GSSAPI_PASS")
214290
write_env("GSSAPI_PASS", config["SASL_PASS"])
215291
write_env("GSSAPI_CANONICALIZE", "true")
@@ -266,19 +342,19 @@ def handle_test_env() -> None:
266342
if test_name in ["encryption", "kms"]:
267343
# Check for libmongocrypt download.
268344
if not (ROOT / "libmongocrypt").exists():
269-
run_command(f"bash {HERE.as_posix()}/setup-libmongocrypt.sh")
345+
setup_libmongocrypt()
270346

271347
# TODO: Test with 'pip install pymongocrypt'
272348
UV_ARGS.append("--group pymongocrypt_source")
273349

274350
# Use the nocrypto build to avoid dependency issues with older windows/python versions.
275351
BASE = ROOT / "libmongocrypt/nocrypto"
276-
if sys.platform == "linux":
352+
if PLATFORM == "linux":
277353
if (BASE / "lib/libmongocrypt.so").exists():
278354
PYMONGOCRYPT_LIB = BASE / "lib/libmongocrypt.so"
279355
else:
280356
PYMONGOCRYPT_LIB = BASE / "lib64/libmongocrypt.so"
281-
elif sys.platform == "darwin":
357+
elif PLATFORM == "darwin":
282358
PYMONGOCRYPT_LIB = BASE / "lib/libmongocrypt.dylib"
283359
else:
284360
PYMONGOCRYPT_LIB = BASE / "bin/mongocrypt.dll"
@@ -300,7 +376,7 @@ def handle_test_env() -> None:
300376
config = read_env(f"{DRIVERS_TOOLS}/mo-expansion.sh")
301377
CRYPT_SHARED_DIR = Path(config["CRYPT_SHARED_LIB_PATH"]).parent.as_posix()
302378
LOGGER.info("Using crypt_shared_dir %s", CRYPT_SHARED_DIR)
303-
if os.name == "nt":
379+
if PLATFORM == "windows":
304380
write_env("PATH", f"{CRYPT_SHARED_DIR}:$PATH")
305381
else:
306382
write_env(

0 commit comments

Comments
 (0)