Skip to content

Commit

Permalink
TIG-3350 Python conveniences (mongodb#571)
Browse files Browse the repository at this point in the history
  • Loading branch information
Raiden Worley authored Nov 10, 2021
1 parent 385bc04 commit 90718d3
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ tags
build
dist
expansions.yml
**.plist

# python
__pycache__
Expand Down
38 changes: 34 additions & 4 deletions src/lamplib/src/genny/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,27 @@ def clean(ctx: click.Context) -> None:


@cli.command(name="cmake-test", help="Run genny's C++ unit tests.")
@click.option(
"-g", "--regex", required=False, default=None, help=("Regex to match against tests."),
)
@click.option(
"-r",
"--repeat-until-fail",
required=False,
default=1,
help=(
"Repeat this many times, unless a test fails. Default is 1. This is useful for flaky tests."
),
)
@click.pass_context
def cmake_test(ctx: click.Context) -> None:
def cmake_test(ctx: click.Context, regex: str, repeat_until_fail: int) -> None:
from genny.tasks import run_tests

run_tests.cmake_test(
genny_repo_root=ctx.obj["GENNY_REPO_ROOT"], workspace_root=ctx.obj["WORKSPACE_ROOT"]
genny_repo_root=ctx.obj["GENNY_REPO_ROOT"],
workspace_root=ctx.obj["WORKSPACE_ROOT"],
regex=regex,
repeat_until_fail=repeat_until_fail,
)


Expand Down Expand Up @@ -292,12 +307,17 @@ def run_debug(ctx: click.Context, genny_args: List[str]):
"constructor validates configuration at constructor time."
),
)
@click.option(
"-w", "--workload", required=False, default=None, help=("Workload to dry-run."),
)
@click.pass_context
def dry_run_workloads(ctx: click.Context):
def dry_run_workloads(ctx: click.Context, workload: str):
from genny.tasks import dry_run

dry_run.dry_run_workloads(
genny_repo_root=ctx.obj["GENNY_REPO_ROOT"], workspace_root=ctx.obj["WORKSPACE_ROOT"]
genny_repo_root=ctx.obj["GENNY_REPO_ROOT"],
workspace_root=ctx.obj["WORKSPACE_ROOT"],
given_workload=workload,
)


Expand Down Expand Up @@ -397,6 +417,16 @@ def create_new_actor(ctx: click.Context, actor_name: str):
)


@cli.command(
"generate-uuid-tag", help=("Generate a random UUID tag for headers."),
)
@click.pass_context
def generate_uuid_tag(ctx: click.Context):
from genny.tasks import generate_uuid_tag

generate_uuid_tag.run_generate_uuid_tag(genny_repo_root=ctx.obj["GENNY_REPO_ROOT"])


@cli.command(
name="lint-python",
help="Run the 'black' python format checker to ensure genny's internal python is 💅.",
Expand Down
9 changes: 6 additions & 3 deletions src/lamplib/src/genny/tasks/dry_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,14 @@ def dry_run_workload(
)


def dry_run_workloads(genny_repo_root: str, workspace_root: str):
def dry_run_workloads(genny_repo_root: str, workspace_root: str, given_workload: str = None):
info = toolchain_info(genny_repo_root=genny_repo_root, workspace_root=workspace_root)

glob_pattern = os.path.join(genny_repo_root, "src", "workloads", "*", "*.yml")
workloads = glob.glob(glob_pattern)
if given_workload is not None:
workloads = [given_workload]
else:
glob_pattern = os.path.join(genny_repo_root, "src", "workloads", "*", "*.yml")
workloads = glob.glob(glob_pattern)
curr = 0
for workload in workloads:
SLOG.info("Checking workload", workload=workload, index=curr, of_how_many=len(workloads))
Expand Down
12 changes: 12 additions & 0 deletions src/lamplib/src/genny/tasks/generate_uuid_tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import os

from genny import cmd_runner


def run_generate_uuid_tag(genny_repo_root: str):
path = os.path.join(
genny_repo_root, "src", "lamplib", "src", "genny", "tasks", "generate-uuid-tag.sh"
)
cmd_runner.run_command(
cmd=[path], cwd=genny_repo_root, capture=False, check=True,
)
26 changes: 21 additions & 5 deletions src/lamplib/src/genny/tasks/run_tests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import structlog
import os
import sys
import shutil
import subprocess

from typing import Callable, TypeVar, Tuple, Optional

Expand Down Expand Up @@ -69,7 +71,9 @@ def _run_command_with_sentinel_report(
)


def cmake_test(genny_repo_root: str, workspace_root: str):
def cmake_test(
genny_repo_root: str, workspace_root: str, regex: str = None, repeat_until_fail: int = 1
):
info = toolchain.toolchain_info(genny_repo_root=genny_repo_root, workspace_root=workspace_root)
workdir = os.path.join(genny_repo_root, "build")

Expand All @@ -78,20 +82,32 @@ def cmake_test(genny_repo_root: str, workspace_root: str):

ctest_cmd = [
"ctest",
"--verbose",
"--schedule-random",
"--output-on-failure",
"--parallel",
"4",
"--repeat-until-fail",
str(repeat_until_fail),
"--label-exclude",
"(standalone|sharded|single_node_replset|three_node_replset|benchmark)",
]

if regex is not None:
ctest_cmd += ["--tests-regex", regex]

def cmd_func() -> bool:
output: cmd_runner.RunCommandOutput = cmd_runner.run_command(
cmd=ctest_cmd, cwd=workdir, env=info.toolchain_env, capture=False, check=True
)
return output.returncode == 0

_run_command_with_sentinel_report(
cmd_func=cmd_func, workspace_root=workspace_root, genny_repo_root=genny_repo_root
)
try:
_run_command_with_sentinel_report(
cmd_func=cmd_func, workspace_root=workspace_root, genny_repo_root=genny_repo_root
)

except subprocess.CalledProcessError:
sys.exit(1)


def benchmark_test(genny_repo_root: str, workspace_root: str):
Expand Down

0 comments on commit 90718d3

Please sign in to comment.