From a6d24b3af7d461703f48f1dfef3303f0cece9545 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Sun, 10 Dec 2023 12:10:36 +0100 Subject: [PATCH] introduce "cmdeploy bench" --- .../src/deploy_chatmail/cmdeploy.py | 27 ++++++++++++++----- scripts/bench.sh | 4 --- 2 files changed, 20 insertions(+), 11 deletions(-) delete mode 100755 scripts/bench.sh diff --git a/deploy-chatmail/src/deploy_chatmail/cmdeploy.py b/deploy-chatmail/src/deploy_chatmail/cmdeploy.py index 5095f69c..c0fd98f0 100644 --- a/deploy-chatmail/src/deploy_chatmail/cmdeploy.py +++ b/deploy-chatmail/src/deploy_chatmail/cmdeploy.py @@ -72,8 +72,8 @@ def get_parser(): help="fully qualified DNS domain name for your chatmail instance", ) - install_parser = add_subcommand(subparsers, run_cmd) - install_parser.add_argument( + run_parser = add_subcommand(subparsers, run_cmd) + run_parser.add_argument( "--dry-run", dest="dry_run", action="store_true", @@ -84,6 +84,8 @@ def get_parser(): add_subcommand(subparsers, test_cmd) + add_subcommand(subparsers, bench_cmd) + add_subcommand(subparsers, dns_cmd) return parser @@ -133,6 +135,13 @@ def test_cmd(args, out, config): ) +def bench_cmd(args, out, config): + """Run benchmarks against an online chatmail instance.""" + pytest_path = shutil.which("pytest") + benchmark = "tests/online/benchmark.py" + subprocess.check_call([pytest_path, benchmark, "-vrx"]) + + def read_dkim_entries(entry): lines = [] for line in entry.split("\n"): @@ -179,18 +188,22 @@ def main(args=None): if not hasattr(args, "func"): return parser.parse_args(["-h"]) out = Out() + kwargs = {} if args.func.__name__ != "init_cmd": if not args.inipath.exists(): out.red(f"expecting {args.inipath} to exist, run init first?") raise SystemExit(1) try: - config = read_config(args.inipath) + kwargs["config"] = read_config(args.inipath) except Exception as ex: out.red(ex) - raise SystemExit(2) - args.func(args, out, config) - else: - args.func(args, out) + raise SystemExit(1) + + try: + args.func(args, out, **kwargs) + except KeyboardInterrupt: + out.red("KeyboardInterrupt") + sys.exit(130) if __name__ == "__main__": diff --git a/scripts/bench.sh b/scripts/bench.sh deleted file mode 100755 index 37f6f261..00000000 --- a/scripts/bench.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -set -e - -venv/bin/pytest tests/online/benchmark.py -vrx