Skip to content

Commit 138573a

Browse files
committed
PYTHON-4540 Convert libmongocrypt download to python
1 parent 3e29671 commit 138573a

File tree

6 files changed

+63
-62
lines changed

6 files changed

+63
-62
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
SUCCESS=false TEST_FLE_AZURE_AUTO=1 bash $HERE/scripts/setup-tests.sh
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="SUCCESS=true TEST_FLE_AZURE_AUTO=1 LIBMONGOCRYPT_URL=$LIBMONGOCRYPT_URL bash .evergreen/just.sh setup-test" \
22+
AZUREKMS_CMD="SUCCESS=true TEST_FLE_AZURE_AUTO=1 bash .evergreen/just.sh setup-test" \
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="SUCCESS=true TEST_FLE_GCP_AUTO=1 LIBMONGOCRYPT_URL=$LIBMONGOCRYPT_URL bash ./.evergreen/just.sh setup-test" $DRIVERS_TOOLS/.evergreen/csfle/gcpkms/run-command.sh
21+
GCPKMS_CMD="SUCCESS=true TEST_FLE_GCP_AUTO=1 bash ./.evergreen/just.sh setup-test" $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
SUCCESS=false TEST_FLE_GCP_AUTO=1 bash $HERE/setup-tests.sh
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: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
import os
66
import platform
77
import shlex
8+
import shutil
89
import stat
910
import subprocess
1011
import sys
12+
import tarfile
1113
from pathlib import Path
1214
from typing import Any
15+
from urllib import request
1316

1417
HERE = Path(__file__).absolute().parent
1518
ROOT = HERE.parent.parent
@@ -92,6 +95,62 @@ def run_command(cmd: str) -> None:
9295
LOGGER.info("Running command %s... done.", cmd)
9396

9497

98+
def setup_libmongocrypt():
99+
target = ""
100+
if os.name == "nt":
101+
# PYTHON-2808 Ensure this machine has the CA cert for google KMS.
102+
if is_set("TEST_FLE_GCP_AUTO"):
103+
run_command('powershell.exe "Invoke-WebRequest -URI https://oauth2.googleapis.com/"')
104+
target = "windows-test"
105+
106+
elif sys.platform == "darwin":
107+
target = "macos"
108+
109+
else:
110+
name = ""
111+
version_id = ""
112+
arch = platform.machine()
113+
with open("etc/os-release") as fid:
114+
for line in fid:
115+
if line.startswith("NAME="):
116+
_, _, name = line.strip().split("=")
117+
if line.startswith("VERSION_ID="):
118+
_, _, version = line.strip().split("=")
119+
if name.startswith("Debian"):
120+
target = f"debian{version_id}"
121+
elif name.startswith("Red Hat"):
122+
if version_id.startswith("7"):
123+
target = "rhel-70-64-bit"
124+
elif version_id.startswith("8"):
125+
if arch == "aarch64":
126+
target = "rhel-82-arm64"
127+
else:
128+
target = "rhel-80-64-bit"
129+
130+
if not is_set("LIBMONGOCRYPT_URL"):
131+
if not target:
132+
raise ValueError("Cannot find libmongocrypt target for current platform!")
133+
url = f"https://s3.amazonaws.com/mciuploads/libmongocrypt/{target}/master/latest/libmongocrypt.tar.gz"
134+
else:
135+
url = os.environ["LIBMONGOCRYPT_URL"]
136+
137+
shutil.rmtree(HERE / "libmongocrypt", ignore_errors=True)
138+
139+
LOGGER.info(f"Fetching {url}...")
140+
with request.urlopen(request.Request(url), timeout=15.0) as response: # noqa: S310
141+
if response.status == 200:
142+
with tarfile.open("libmongocrypt.tar.gz", fileobj=response) as fid:
143+
fid.extractall(HERE / "libmongocrypt")
144+
LOGGER.info(f"Fetching {url}... done.")
145+
146+
run_command("ls -la libmongocrypt")
147+
run_command("ls -la libmongocrypt/nocrypto")
148+
149+
if os.name == "nt":
150+
# libmongocrypt's windows dll is not marked executable.
151+
run_command("chmod +x libmongocrypt/nocrypto/bin/mongocrypt.dll")
152+
153+
95154
def handle_test_env() -> None:
96155
AUTH = os.environ.get("AUTH", "noauth")
97156
SSL = os.environ.get("SSL", "nossl")
@@ -214,7 +273,7 @@ def handle_test_env() -> None:
214273
if is_set("TEST_ENCRYPTION") or is_set("TEST_FLE_AZURE_AUTO") or is_set("TEST_FLE_GCP_AUTO"):
215274
# Check for libmongocrypt download.
216275
if not (ROOT / "libmongocrypt").exists():
217-
run_command(f"bash {HERE.as_posix()}/setup-libmongocrypt.sh")
276+
setup_libmongocrypt()
218277

219278
# TODO: Test with 'pip install pymongocrypt'
220279
UV_ARGS.append("--group pymongocrypt_source")

0 commit comments

Comments
 (0)