From 74b755eb3aa5016a6a63a4020b6061c5a7423b86 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jan 20 2020 16:54:27 +0000 Subject: Add a runner script to run all the tests sequentially and in a scheduler This basically allows to keep running the tests in a loop, while waiting some time between two runs in a single process, making it easier to deploy this project in openshift. Signed-off-by: Pierre-Yves Chibon --- diff --git a/runner.cfg b/runner.cfg new file mode 100644 index 0000000..36c2f1d --- /dev/null +++ b/runner.cfg @@ -0,0 +1,5 @@ +# Time between two runs in second +delay = 3600 + +# CLI arguments to give to the script testing the single package gating workflow +workflow_single_gating_args = "--conf monitor_gating_stg.cfg --auto-update --no-pr" diff --git a/runner.py b/runner.py new file mode 100644 index 0000000..820e2f8 --- /dev/null +++ b/runner.py @@ -0,0 +1,64 @@ +""" +This script is meant to run the different tests that we have sequentially, with +a scheduler, ie: after running all the tests, it will wait for a specified +amount of time and then run them again, until it's stopped. +""" + +import argparse +import datetime +import sched +import sys +import time +import utils + +import toml + +import monitor_gating + +s = sched.scheduler(time.time, time.sleep) +conf = toml.load + + +def get_arguments(args): + """ Load and parse the CLI arguments.""" + parser = argparse.ArgumentParser( + description="Runner for the CI canary tests." + ) + parser.add_argument( + "conf", + help="Configuration file for the different tests", + ) + + return parser.parse_args(args) + + +def schedule(conf): + """ Run the test and schedules the next one. """ + delay = conf["delay"] + print("Tests started:", datetime.datetime.utcnow()) + #TEST HERE + single_args = conf["workflow_single_gating_args"].split() + monitor_gating.main(single_args) + print("Tests finished:", datetime.datetime.utcnow()) + print(f"Next run in: {delay} seconds") + s.enter(delay, 1, schedule, argument=(conf,)) + + +def main(args): + """ Schedule the first test and run the scheduler. """ + args = get_arguments(args) + conf = toml.load(args.conf) + s.enter(0, 1, schedule, argument=(conf,)) + s.run() + + +if __name__ == "__main__": + try: + main(sys.argv[1:]) + except KeyboardInterrupt: + from code import InteractiveConsole + InteractiveConsole( + locals={"s": s}).interact( + "ENTERING THE DEBUG CONSOLE:\n s is the scheduler\n ^d to quit", + "LEAVING THE DEBUG CONSOLE" + )