Skip to content

Commit b3885fa

Browse files
committed
PYTHON-5196 Convert OIDC tests to use new test scripts
1 parent 0749ee9 commit b3885fa

14 files changed

+99
-122
lines changed

.evergreen/generated_configs/tasks.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,8 @@ tasks:
10421042
TEST_NAME: ocsp
10431043
tags: [ocsp, ocsp-rsa]
10441044

1045+
# Oidc tests
1046+
10451047
# Server tests
10461048
- name: test-4.0-standalone-auth-ssl-sync
10471049
commands:

.evergreen/run-mongodb-oidc-remote-test.sh

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

.evergreen/run-mongodb-oidc-test.sh

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,7 @@ set -eu
55

66
echo "Running MONGODB-OIDC authentication tests"
77

8-
OIDC_ENV=${OIDC_ENV:-"test"}
9-
10-
if [ $OIDC_ENV == "test" ]; then
11-
# Make sure DRIVERS_TOOLS is set.
12-
if [ -z "$DRIVERS_TOOLS" ]; then
13-
echo "Must specify DRIVERS_TOOLS"
14-
exit 1
15-
fi
16-
source ${DRIVERS_TOOLS}/.evergreen/auth_oidc/secrets-export.sh
17-
18-
elif [ $OIDC_ENV == "azure" ]; then
8+
if [ $OIDC_ENV == "azure" ]; then
199
source ./env.sh
2010

2111
elif [ $OIDC_ENV == "gcp" ]; then
@@ -29,5 +19,5 @@ else
2919
exit 1
3020
fi
3121

32-
COVERAGE=1 bash ./.evergreen/just.sh setup-tests auth_oidc
22+
bash ./.evergreen/just.sh setup-tests auth_oidc remote
3323
bash ./.evergreen/just.sh run-tests "${@:1}"

.evergreen/scripts/generate_config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,11 @@ def create_aws_tasks():
886886

887887
def create_oidc_tasks():
888888
tasks = []
889+
for sub_test in ["test", "azure", "gcp", "eks", "aks", "gke"]:
890+
vars = dict(TEST_NAME="auth_oidc", SUB_TEST_NAME=sub_test)
891+
test_func = FunctionCall(func="run tests", vars=vars)
892+
task_name = f"test-auth-oidc-{sub_test}"
893+
tasks.append(EvgTask(name=task_name, tags=["oidc"], commands=[test_func]))
889894
tasks.append([])
890895

891896

.evergreen/scripts/kms_tester.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,16 @@
22

33
import os
44

5-
from utils import DRIVERS_TOOLS, LOGGER, ROOT, read_env, run_command, write_env
5+
from utils import (
6+
DRIVERS_TOOLS,
7+
LOGGER,
8+
TMP_DRIVER_FILE,
9+
create_archive,
10+
read_env,
11+
run_command,
12+
write_env,
13+
)
614

7-
TMP_DRIVER_FILE = "/tmp/mongo-python-driver.tgz" # noqa: S108
815
DIRS = dict(
916
gcp=f"{DRIVERS_TOOLS}/.evergreen/csfle/gcpkms",
1017
azure=f"{DRIVERS_TOOLS}/.evergreen/csfle/azurekms",
@@ -45,12 +52,6 @@ def _setup_gcp_vm(base_env: dict[str, str]) -> None:
4552
LOGGER.info("Setting up GCP VM...")
4653

4754

48-
def _create_archive() -> None:
49-
run_command("git add .", cwd=ROOT)
50-
run_command('git commit -m "add files"', check=False, cwd=ROOT)
51-
run_command(f"git archive -o {TMP_DRIVER_FILE} HEAD", cwd=ROOT)
52-
53-
5455
def _load_kms_config(sub_test_target: str) -> dict[str, str]:
5556
target_dir = DIRS[sub_test_target]
5657
config = read_env(f"{target_dir}/secrets-export.sh")
@@ -87,7 +88,7 @@ def setup_kms(sub_test_name: str) -> None:
8788
run_command("./setup-secrets.sh", cwd=kms_dir)
8889

8990
if success:
90-
_create_archive()
91+
create_archive()
9192
if sub_test_target == "azure":
9293
os.environ["AZUREKMS_VMNAME_PREFIX"] = "PYTHON_DRIVER"
9394

.evergreen/scripts/oidc_tester.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
from __future__ import annotations
2+
3+
import os
4+
5+
from utils import (
6+
DRIVERS_TOOLS,
7+
TMP_DRIVER_FILE,
8+
run_command,
9+
)
10+
11+
K8S_NAMES = ["aks", "gke", "eks"]
12+
13+
14+
def _get_target_dir(sub_test_name: str) -> str:
15+
if sub_test_name == "test":
16+
target_dir = "auth_oidc"
17+
elif sub_test_name == "azure":
18+
target_dir = "auth_oidc/azure"
19+
elif sub_test_name == "gcp":
20+
target_dir = "auth_oidc/gcp"
21+
elif sub_test_name in K8S_NAMES:
22+
target_dir = "auth_oidc/k8s"
23+
else:
24+
raise ValueError(f"Invalid sub test name '{sub_test_name}'")
25+
return f"{DRIVERS_TOOLS}/.evergreen/{target_dir}"
26+
27+
28+
def setup_oidc(sub_test_name: str) -> None:
29+
target_dir = _get_target_dir(sub_test_name)
30+
env = os.environ.copy()
31+
if sub_test_name == "azure":
32+
env["AZUREOIDC_VMNAME_PREFIX"] = "PYTHON_DRIVER"
33+
run_command(f"bash {target_dir}/setup.sh", env=env)
34+
if sub_test_name in K8S_NAMES:
35+
run_command(f"bash {target_dir}/setup-pod.sh")
36+
run_command(f"bash {target_dir}/run-self-test.sh")
37+
38+
39+
def test_oidc_remote(sub_test_name: str) -> None:
40+
env = os.environ.copy()
41+
target_dir = _get_target_dir(sub_test_name)
42+
if sub_test_name in ["azure", "gcp"]:
43+
upper_name = sub_test_name.upper()
44+
env[f"{upper_name}OIDC_DRIVERS_TAR_FILE"] = TMP_DRIVER_FILE
45+
env[
46+
f"{upper_name}OIDC_TEST_CMD"
47+
] = f"OIDC_ENV={sub_test_name} ./.evergreen/run-mongodb-oidc-test.sh"
48+
elif sub_test_name in K8S_NAMES:
49+
env["K8S_DRIVERS_TAR_FILE"] = TMP_DRIVER_FILE
50+
env["K8S_TEST_CMD"] = "OIDC_ENV=k8s ./.evergreen/run-mongodb-oidc-test.sh"
51+
52+
run_command(f"bash {target_dir}/run-driver-test.sh")
53+
54+
55+
def teardown_oidc(sub_test_name: str) -> None:
56+
target_dir = _get_target_dir(sub_test_name)
57+
if sub_test_name in K8S_NAMES:
58+
run_command(f"bash {target_dir}/teardown-pod.sh")
59+
run_command(f"bash {target_dir}/teardown.sh")

.evergreen/scripts/run-atlas-server.sh

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

.evergreen/scripts/run_server.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ def start_server():
3333
set_env("LOAD_BALANCER")
3434

3535
elif test_name == "auth_oidc":
36-
cmd = ["bash", f"{DRIVERS_TOOLS}/.evergreen/auth_oidc/start-local-server.sh"]
37-
run_command(cmd, cwd=DRIVERS_TOOLS)
38-
return
36+
raise ValueError(
37+
"OIDC auth does not use run-orchestration directly, do not use run-server!"
38+
)
3939

4040
elif test_name == "ocsp":
4141
opts.ssl = True

.evergreen/scripts/run_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def run() -> None:
113113
return
114114

115115
# Run remote oidc tests.
116-
if TEST_NAME == "auth_oidc" and SUB_TEST_NAME in [""]:
116+
if TEST_NAME == "auth_oidc" and SUB_TEST_NAME not in ["test", "test-remote"]:
117117
from oidc_tester import test_oidc_remote
118118

119119
test_oidc_remote(SUB_TEST_NAME)

.evergreen/scripts/setup_tests.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,10 @@ def handle_test_env() -> None:
239239
cmd = f'bash "{DRIVERS_TOOLS}/.evergreen/run-load-balancer.sh" start'
240240
run_command(cmd)
241241

242-
if test_name == "oidc":
243-
pass
242+
if test_name == "auth_oidc":
243+
from oidc_helper import setup_oidc
244+
245+
setup_oidc(sub_test_name)
244246

245247
if test_name == "ocsp":
246248
if sub_test_name:

0 commit comments

Comments
 (0)