Skip to content

Commit 708f06c

Browse files
committed
improve usability
1 parent a6aa7f2 commit 708f06c

File tree

4 files changed

+51
-19
lines changed

4 files changed

+51
-19
lines changed

.evergreen/scripts/run_server.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,21 @@ def set_env(name: str, value: Any = "1") -> None:
1111

1212

1313
def start_server():
14-
opts = get_test_options(require_sub_test_name=False)
14+
opts, extra_opts = get_test_options(
15+
"Run a MongoDB server. All given flags will be passed to run-orchestration.sh in DRIVERS_TOOLS.",
16+
require_sub_test_name=False,
17+
allow_extra_opts=True,
18+
)
1519
test_name = opts.test_name
1620

21+
if opts.auth:
22+
extra_opts.append("--auth")
23+
24+
if opts.verbose:
25+
extra_opts.append("-v")
26+
elif opts.quiet:
27+
extra_opts.append("-q")
28+
1729
if test_name == "auth_aws":
1830
set_env("AUTH_AWS")
1931

@@ -24,12 +36,13 @@ def start_server():
2436
set_env("SKIP_CRYPT_SHARED")
2537

2638
if opts.ssl:
39+
extra_opts.append("--ssl")
2740
certs = ROOT / "test/certificates"
2841
set_env("TLS_CERT_KEY_FILE", certs / "client.pem")
2942
set_env("TLS_PEM_KEY_FILE", certs / "server.pem")
3043
set_env("TLS_CA_FILE", certs / "ca.pem")
3144

32-
cmd = f"bash {DRIVERS_TOOLS}/.evergreen/run-orchestration.sh"
45+
cmd = ["bash", f"{DRIVERS_TOOLS}/.evergreen/run-orchestration.sh", *extra_opts]
3346
run_command(cmd, cwd=DRIVERS_TOOLS)
3447

3548

.evergreen/scripts/setup_tests.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def setup_libmongocrypt():
113113

114114

115115
def handle_test_env() -> None:
116-
opts = get_test_options()
116+
opts, _ = get_test_options("Set up the test environment and services.")
117117
test_name = opts.test_name
118118
sub_test_name = opts.sub_test_name
119119
AUTH = "auth" if opts.auth else "noauth"

.evergreen/scripts/utils.py

+34-16
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,31 @@ class Distro:
5252
SUB_TEST_REQUIRED = ["auth_aws", "kms"]
5353

5454

55-
def get_test_options(require_sub_test_name=True):
55+
def get_test_options(
56+
description, require_sub_test_name=True, allow_extra_opts=False
57+
) -> tuple[argparse.Namespace, list[str]]:
5658
parser = argparse.ArgumentParser(
57-
description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
59+
description=description, formatter_class=argparse.RawDescriptionHelpFormatter
5860
)
59-
parser.add_argument(
60-
"test_name",
61-
choices=sorted(TEST_SUITE_MAP),
62-
nargs="?",
63-
default="default",
64-
help="The name of the test suite to set up, typically the same name as a pytest marker.",
65-
)
66-
parser.add_argument("sub_test_name", nargs="?", help="The sub test name, for example 'azure'")
61+
if require_sub_test_name:
62+
parser.add_argument(
63+
"test_name",
64+
choices=sorted(TEST_SUITE_MAP),
65+
nargs="?",
66+
default="default",
67+
help="The optional name of the test suite to set up, typically the same name as a pytest marker.",
68+
)
69+
parser.add_argument(
70+
"sub_test_name", nargs="?", help="The optional sub test name, for example 'azure'."
71+
)
72+
else:
73+
parser.add_argument(
74+
"test_name",
75+
choices=sorted(TEST_SUITE_MAP),
76+
nargs="?",
77+
default="default",
78+
help="The optional name of the test suite to be run, which informs the server configuration.",
79+
)
6780
parser.add_argument(
6881
"--verbose", "-v", action="store_true", help="Whether to log at the DEBUG level"
6982
)
@@ -73,15 +86,18 @@ def get_test_options(require_sub_test_name=True):
7386
parser.add_argument("--auth", action="store_true", help="Whether to add authentication")
7487
parser.add_argument("--ssl", action="store_true", help="Whether to add TLS configuration")
7588
# Get the options.
76-
opts = parser.parse_args()
89+
if not allow_extra_opts:
90+
opts, extra_opts = parser.parse_args(), []
91+
else:
92+
opts, extra_opts = parser.parse_known_args()
7793
if opts.verbose:
7894
LOGGER.setLevel(logging.DEBUG)
7995
elif opts.quiet:
8096
LOGGER.setLevel(logging.WARNING)
8197

8298
# Handle validation and environment variable overrides.
8399
test_name = opts.test_name
84-
sub_test_name = opts.sub_test_name
100+
sub_test_name = opts.sub_test_name if require_sub_test_name else ""
85101
if require_sub_test_name and test_name in SUB_TEST_REQUIRED and not sub_test_name:
86102
raise ValueError(f"Test '{test_name}' requires a sub_test_name")
87103
if "auth" in test_name or os.environ.get("AUTH") == "auth":
@@ -91,7 +107,7 @@ def get_test_options(require_sub_test_name=True):
91107
opts.auth = False
92108
if os.environ.get("SSL") == "ssl":
93109
opts.ssl = True
94-
return opts
110+
return opts, extra_opts
95111

96112

97113
def read_env(path: Path | str) -> dict[str, Any]:
@@ -115,8 +131,10 @@ def write_env(name: str, value: Any = "1") -> None:
115131
fid.write(f'export {name}="{value}"\n')
116132

117133

118-
def run_command(cmd: str, **kwargs: Any) -> None:
119-
LOGGER.info("Running command %s...", cmd)
134+
def run_command(cmd: str | list[str], **kwargs: Any) -> None:
135+
if isinstance(cmd, list):
136+
cmd = " ".join(cmd)
137+
LOGGER.info("Running command '%s'...", cmd)
120138
kwargs.setdefault("check", True)
121139
subprocess.run(shlex.split(cmd), **kwargs) # noqa: PLW1510, S603
122-
LOGGER.info("Running command %s... done.", cmd)
140+
LOGGER.info("Running command '%s'... done.", cmd)

CONTRIBUTING.md

+1
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ the pages will re-render and the browser will automatically refresh.
218218
### Usage
219219

220220
- Run `just run-server` with optional args to set up the server.
221+
All given flags will be passed to `run-orchestration.sh` in `DRIVERS_TOOLS`.
221222
- Run `just setup-tests` with optional args to set up the test environment, secrets, etc.
222223
- Run `just run-tests` to run the tests in an appropriate Python environment.
223224
- When done, run `just teardown-tests` to clean up and `just stop-server` to stop the server.

0 commit comments

Comments
 (0)