Skip to content

Commit 80601f1

Browse files
committed
PYTHON-5151 Convert kms tests to use python scripts
1 parent f27e8e1 commit 80601f1

12 files changed

+169
-231
lines changed

.evergreen/config.yml

Lines changed: 4 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -562,51 +562,6 @@ task_groups:
562562
tasks:
563563
- ".serverless"
564564

565-
- name: testgcpkms_task_group
566-
setup_group_can_fail_task: true
567-
setup_group_timeout_secs: 1800 # 30 minutes
568-
setup_group:
569-
- func: fetch source
570-
- func: setup system
571-
- command: subprocess.exec
572-
params:
573-
binary: bash
574-
args:
575-
- ${DRIVERS_TOOLS}/.evergreen/csfle/gcpkms/create-and-setup-instance.sh
576-
teardown_task:
577-
- command: subprocess.exec
578-
params:
579-
binary: bash
580-
args:
581-
- ${DRIVERS_TOOLS}/.evergreen/csfle/gcpkms/delete-instance.sh
582-
- func: "upload test results"
583-
tasks:
584-
- testgcpkms-task
585-
586-
- name: testazurekms_task_group
587-
setup_group:
588-
- func: fetch source
589-
- func: setup system
590-
- command: subprocess.exec
591-
params:
592-
binary: bash
593-
env:
594-
AZUREKMS_VMNAME_PREFIX: "PYTHON_DRIVER"
595-
args:
596-
- ${DRIVERS_TOOLS}/.evergreen/csfle/azurekms/create-and-setup-vm.sh
597-
teardown_group:
598-
- command: subprocess.exec
599-
params:
600-
binary: bash
601-
args:
602-
- ${DRIVERS_TOOLS}/.evergreen/csfle/azurekms/delete-vm.sh
603-
- func: "upload test results"
604-
setup_group_can_fail_task: true
605-
teardown_task_can_fail_task: true
606-
setup_group_timeout_secs: 1800
607-
tasks:
608-
- testazurekms-task
609-
610565
- name: testazureoidc_task_group
611566
setup_group:
612567
- func: fetch source
@@ -1395,60 +1350,6 @@ tasks:
13951350
commands:
13961351
- func: "download and merge coverage"
13971352

1398-
- name: "testgcpkms-task"
1399-
commands:
1400-
- command: subprocess.exec
1401-
type: test
1402-
params:
1403-
working_dir: "src"
1404-
binary: bash
1405-
include_expansions_in_env: ["DRIVERS_TOOLS"]
1406-
args:
1407-
- .evergreen/run-gcpkms-test.sh
1408-
1409-
- name: "testgcpkms-fail-task"
1410-
# testgcpkms-fail-task runs in a non-GCE environment.
1411-
# It is expected to fail to obtain GCE credentials.
1412-
commands:
1413-
- func: "bootstrap mongo-orchestration"
1414-
vars:
1415-
VERSION: "latest"
1416-
TOPOLOGY: "server"
1417-
- command: subprocess.exec
1418-
type: test
1419-
params:
1420-
include_expansions_in_env: ["PYTHON_BINARY"]
1421-
working_dir: "src"
1422-
binary: "bash"
1423-
args:
1424-
- .evergreen/scripts/run-gcpkms-fail-test.sh
1425-
1426-
- name: testazurekms-task
1427-
commands:
1428-
- command: subprocess.exec
1429-
type: test
1430-
params:
1431-
binary: bash
1432-
working_dir: src
1433-
include_expansions_in_env: ["DRIVERS_TOOLS"]
1434-
args:
1435-
- .evergreen/run-azurekms-test.sh
1436-
1437-
- name: testazurekms-fail-task
1438-
commands:
1439-
- func: "bootstrap mongo-orchestration"
1440-
vars:
1441-
VERSION: "latest"
1442-
TOPOLOGY: "server"
1443-
- command: subprocess.exec
1444-
type: test
1445-
params:
1446-
binary: bash
1447-
working_dir: src
1448-
include_expansions_in_env: ["DRIVERS_TOOLS"]
1449-
args:
1450-
- .evergreen/run-azurekms-fail-test.sh
1451-
14521353
- name: "perf-6.0-standalone"
14531354
tags: ["perf"]
14541355
commands:
@@ -1529,12 +1430,12 @@ buildvariants:
15291430
run_on:
15301431
- debian11-small
15311432
tasks:
1532-
- name: testgcpkms_task_group
1433+
- name: test-gcpkms
15331434
batchtime: 20160 # Use a batchtime of 14 days as suggested by the CSFLE test README
1534-
- testgcpkms-fail-task
1535-
- name: testazurekms_task_group
1435+
- name: test-gcpkms-fail
1436+
- name: test-azurekms
15361437
batchtime: 20160 # Use a batchtime of 14 days as suggested by the CSFLE test README
1537-
- testazurekms-fail-task
1438+
- name: test-azurekms-fail
15381439

15391440
- name: rhel8-test-lambda
15401441
display_name: FaaS Lambda

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

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

.evergreen/run-azurekms-test.sh

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

.evergreen/run-gcpkms-test.sh

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

.evergreen/scripts/__init__.py

Whitespace-only changes.

.evergreen/scripts/generate_config.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,24 @@ def create_load_balancer_tasks():
835835
return tasks
836836

837837

838+
def create_kms_tests():
839+
tasks = []
840+
for kms_type in ["gcp", "azure"]:
841+
for success in [True, False]:
842+
name = f"test-{kms_type}"
843+
sub_test_name = kms_type
844+
if not success:
845+
name += "-fail"
846+
sub_test_name += " fail"
847+
commands = []
848+
if not success:
849+
commands.append(FunctionCall(func="bootstrap mongo-orchestration"))
850+
test_vars = dict(TEST_NAME="kms", SUB_TEST_NAME=sub_test_name)
851+
test_func = FunctionCall(func="run tests", vars=test_vars)
852+
commands.append(test_func)
853+
tasks.append(EvgTask(name=name, commands=commands))
854+
855+
838856
##################
839857
# Generate Config
840858
##################

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

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

.evergreen/scripts/run_tests.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,22 @@
11
from __future__ import annotations
22

33
import json
4-
import logging
54
import os
65
import platform
76
import shutil
87
import sys
98
from datetime import datetime
10-
from pathlib import Path
119

1210
import pytest
11+
from utils import LOGGER, ROOT
1312

14-
HERE = Path(__file__).absolute().parent
15-
ROOT = HERE.parent.parent
1613
AUTH = os.environ.get("AUTH", "noauth")
1714
SSL = os.environ.get("SSL", "nossl")
1815
UV_ARGS = os.environ.get("UV_ARGS", "")
1916
TEST_PERF = os.environ.get("TEST_PERF")
2017
GREEN_FRAMEWORK = os.environ.get("GREEN_FRAMEWORK")
2118
TEST_ARGS = os.environ.get("TEST_ARGS", "").split()
2219

23-
LOGGER = logging.getLogger(__name__)
24-
logging.basicConfig(level=logging.INFO, format="%(levelname)-8s %(message)s")
25-
2620

2721
def handle_perf(start_time: datetime):
2822
end_time = datetime.now()

.evergreen/scripts/setup_kms.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
from __future__ import annotations
2+
3+
import os
4+
5+
from utils import DRIVERS_TOOLS, LOGGER, ROOT, read_env, run_command, write_env
6+
7+
TMP_DRIVER_FILE = "/tmp/mongo-python-driver.tgz" # noqa: S108
8+
9+
10+
def setup_azurekms() -> None:
11+
LOGGER.info("Copying files to Azure VM...")
12+
cmd = f"""AZUREKMS_SRC="{TMP_DRIVER_FILE}" AZUREKMS_DST="~/" \
13+
{DRIVERS_TOOLS}/.evergreen/csfle/azurekms/copy-file.sh"""
14+
run_command(cmd)
15+
cmd = """AZUREKMS_CMD="tar xf mongo-python-driver.tgz" \
16+
{DRIVERS_TOOLS}/.evergreen/csfle/azurekms/run-command.sh"""
17+
run_command(cmd)
18+
LOGGER.info("Copying files to Azure VM... done.")
19+
20+
21+
def setup_gcpkms() -> None:
22+
LOGGER.info("Copying files to GCP VM...")
23+
cmd = f"GCPKMS_SRC={TMP_DRIVER_FILE} GCPKMS_DST=$GCPKMS_INSTANCENAME: {DRIVERS_TOOLS}/.evergreen/csfle/gcpkms/copy-file.sh"
24+
run_command(cmd)
25+
cmd = f'GCPKMS_CMD="tar xf mongo-python-driver.tgz" {DRIVERS_TOOLS}/.evergreen/csfle/gcpkms/run-command.sh'
26+
run_command(cmd)
27+
LOGGER.info("Copying files to GCP VM...")
28+
29+
30+
def create_archive():
31+
run_command("git add .", cwd=ROOT)
32+
run_command('git commit -m "add files"', check=False, cwd=ROOT)
33+
run_command(f"git archive -o {TMP_DRIVER_FILE} HEAD", cwd=ROOT)
34+
35+
36+
def setup_kms(sub_test_name: str, success: bool) -> None:
37+
success = "fail" not in sub_test_name
38+
sub_test_type = sub_test_name.split()[0]
39+
if sub_test_name.startswith("azure"):
40+
write_env("TEST_FLE_AZURE_AUTO")
41+
else:
42+
write_env("TEST_FLE_GCP_AUTO")
43+
44+
write_env("SUCCESS", success)
45+
46+
if sub_test_type == "azure":
47+
os.environ["AZUREKMS_VMNAME_PREFIX"] = "PYTHON_DRIVER"
48+
49+
run_command(f"{DRIVERS_TOOLS}/.evergreen/csfle/{sub_test_type}kms/setup-secrets.sh")
50+
config = read_env(f"{DRIVERS_TOOLS}/csfle/a{sub_test_type}kms/secrets-export.sh")
51+
if success:
52+
run_command(f"{DRIVERS_TOOLS}/.evergreen/csfle/{sub_test_type}kms/setup.sh")
53+
create_archive()
54+
55+
if sub_test_name == "azure":
56+
mongodb_uri = setup_azurekms(config)
57+
else:
58+
mongodb_uri = setup_gcpkms(config)
59+
60+
elif sub_test_type == "azure":
61+
write_env("KEY_NAME", config["AZUREKMS_KEYNAME"])
62+
write_env("KEY_VAULT_ENDPOINT", config["AZUREKMS_KEYVAULTENDPOINT"])
63+
64+
if "@" in mongodb_uri:
65+
raise RuntimeError("MONGODB_URI unexpectedly contains user credentials in FLE test!")
66+
67+
write_env("MONGODB_URI", mongodb_uri)
68+
69+
70+
if __name__ == "__main__":
71+
setup_kms()

0 commit comments

Comments
 (0)