Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions test/drtest
Original file line number Diff line number Diff line change
@@ -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()
15 changes: 15 additions & 0 deletions test/suites/basic-k8s.yaml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions test/suites/basic-odr.yaml
Original file line number Diff line number Diff line change
@@ -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