From f8d2d2db729be9e3c3d8d4a6573da00c0169b278 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Apr 15 2020 08:00:22 +0000 Subject: Clean up the side-tag in the runner rather than the test This way if an exception occurs before we get to the check if the tests passed or failed, we will still clean the side-tag. Signed-off-by: Pierre-Yves Chibon --- diff --git a/monitor_gating_multi_builds.py b/monitor_gating_multi_builds.py index c4b88ae..441b015 100644 --- a/monitor_gating_multi_builds.py +++ b/monitor_gating_multi_builds.py @@ -66,14 +66,15 @@ def get_arguments(args): return parser.parse_args(args) -def main(args): +def main(args, utils=None): """ Main method used by this script. """ start = datetime.datetime.utcnow() args = get_arguments(args) conf = toml.load(args.conf) - utils = MonitoringUtils() + if utils is None: + utils = MonitoringUtils() with tempfile.TemporaryDirectory(prefix="ci-test-") as folder: print(f"Working in {folder}\n") @@ -83,6 +84,9 @@ def main(args): nevrs, side_tag_name = utils.clone_and_bump( folder, nevrs, conf, conf["name_multi_1"], new_side_tag=True ) + # Store the side_tag_name so we can use it in the runner + utils.side_tag_name = side_tag_name + nevrs, _ = utils.clone_and_bump( folder, nevrs, conf, conf["name_multi_2"], target=side_tag_name ) @@ -218,15 +222,6 @@ def main(args): conf.get("koji_hub"), nevr, expected_ends=conf["koji_end_tag"], ) - try: - print(" Removing side-tag: %s" % side_tag_name) - cmd = [ - conf["fedpkg"], "remove-side-tag", side_tag_name - ] - output = run_command(cmd) - except Exception: - pass - utils.finalize(start) return utils.logs diff --git a/runner.py b/runner.py index 81ea2c3..f6032a0 100644 --- a/runner.py +++ b/runner.py @@ -18,7 +18,7 @@ import toml import monitor_gating_single_build import monitor_gating_multi_builds -from utils import run_command +from utils import MonitoringUtils, run_command s = sched.scheduler(time.time, time.sleep) conf = toml.load @@ -48,6 +48,17 @@ def notify(topic, message): print(f"Error sending fedora-messaging message: {err}") +def _clean_up_side_tags(utils): + try: + print(" Removing side-tag: %s" % utils.side_tag_name) + cmd = [ + conf["fedpkg"], "remove-side-tag", utils.side_tag_name + ] + output = run_command(cmd) + except Exception: + pass + + def schedule(conf): """ Run the test and schedules the next one. """ @@ -86,11 +97,16 @@ def schedule(conf): # Multi Build Gating multi_args = conf["workflow_multi_gating_args"].split() + utils = MonitoringUtils() notify( topic=f"multi-build.start", message={"arguments": multi_args, "runid": runid,}, ) - output = monitor_gating_multi_builds.main(multi_args) + try: + output = monitor_gating_multi_builds.main(multi_args, utils=utils) + finally: + _clean_up_side_tags(utils) + output_text = "\n".join(output) if "[FAILED]" not in output_text: result = "succeeded"