diff --git a/test/drtest b/test/drtest new file mode 100755 index 0000000000..51ecfdd85e --- /dev/null +++ b/test/drtest @@ -0,0 +1,79 @@ +#!/usr/bin/env python3 + +# SPDX-FileCopyrightText: The RamenDR authors +# SPDX-License-Identifier: Apache-2.0 + +import argparse +import collections +import concurrent.futures +import logging +import os +import subprocess + +import yaml + + +def main(): + p = argparse.ArgumentParser("drtest") + p.add_argument("-k", "--kubeconfig", help="If set, use speified kubeconfig path") + p.add_argument("-o", "--outdir", default=".", help="Output directory") + p.add_argument("-v", "--verbose", action="store_true", help="Be more verbose") + p.add_argument("suite", help="Test suite file") + p.add_argument("env", help="Environemnt file") + args = p.parse_args() + + logging.basicConfig( + level=logging.DEBUG if args.verbose else logging.INFO, + format="%(asctime)s %(levelname)-7s %(message)s", + ) + + with open(args.suite) as f: + suite = yaml.safe_load(f) + + os.makedirs(args.outdir, exist_ok=True) + + logging.info("Running '%s'", suite["name"]) + logging.info("Storing output to '%s'", args.outdir) + + stats = collections.Counter({"pass": 0, "fail": 0}) + + with concurrent.futures.ThreadPoolExecutor() as e: + futures = {} + + for test in suite["tests"]: + logging.info("Starting test '%s'", test["name"]) + f = e.submit(run_test, test, args) + futures[f] = test["name"] + + for f in concurrent.futures.as_completed(futures): + try: + f.result() + except Exception: + logging.error("Test '%s' FAIL", futures[f]) + stats["fail"] += 1 + else: + logging.info("Test '%s' PASS", futures[f]) + stats["pass"] += 1 + + logging.info( + "%s (%s pass, %s fail)", + "PASS" if stats["fail"] == 0 else "FAIL", + stats["pass"], + stats["fail"], + ) + + +def run_test(test, args): + log = os.path.join(args.outdir, test["name"] + ".log") + cmd = [test["command"], "--config", test["config"], args.env] + if args.kubeconfig: + env = dict(os.environ) + env["KUBECONFIG"] = args.kubeconfig + else: + env = None + with open(log, "w") as f: + subprocess.run(cmd, stderr=f, check=True, env=env) + + +if __name__ == "__main__": + main() diff --git a/test/suites/basic-k8s.yaml b/test/suites/basic-k8s.yaml new file mode 100644 index 0000000000..c62b0e942c --- /dev/null +++ b/test/suites/basic-k8s.yaml @@ -0,0 +1,15 @@ +# SPDX-FileCopyrightText: The RamenDR authors +# SPDX-License-Identifier: Apache-2.0 + +--- +name: Basic Kubernetes Regional DR tests +tests: + - name: deploymnet + command: basic-test/run + config: configs/k8s/busybox-regional-rbd-deploy.yaml + - name: statefulset + command: basic-test/run + config: configs/k8s/busybox-regional-rbd-sts.yaml + - name: daemonset + command: basic-test/run + config: configs/k8s/busybox-regional-rbd-ds.yaml diff --git a/test/suites/basic-odr.yaml b/test/suites/basic-odr.yaml new file mode 100644 index 0000000000..b05d118dc7 --- /dev/null +++ b/test/suites/basic-odr.yaml @@ -0,0 +1,12 @@ +# SPDX-FileCopyrightText: The RamenDR authors +# SPDX-License-Identifier: Apache-2.0 + +--- +name: Basic OpenShift Regional DR tests +tests: + - name: rbd + command: basic-test/run + config: configs/odr/busybox-regional-rbd-deploy.yaml + - name: cephfs + command: basic-test/run + config: configs/odr/busybox-regional-cephfs-deploy.yaml