diff --git a/ocs_ci/framework/main.py b/ocs_ci/framework/main.py index adea295e91b..122fbba3838 100644 --- a/ocs_ci/framework/main.py +++ b/ocs_ci/framework/main.py @@ -1,6 +1,7 @@ import argparse import os import re +import signal import sys import time @@ -13,6 +14,27 @@ from ocs_ci.utility import utils +kill_counter = 0 + + +def signal_term_handler(sig, frame): + print(f"Got SIGTERM: {sig}") + if hasattr(framework.config, "RUN"): + framework.config.RUN["aborted"] = True + global kill_counter + if kill_counter: + print("Second attempt to SIGTERM, exiting process with RC: 143") + sys.exit(143) + else: + pid = os.getpid() + print(f"Killing run-ci process {pid} with SIGINT to allow fixtures finalize!") + kill_counter += 1 + os.kill(pid, signal.SIGINT) + + +signal.signal(signal.SIGTERM, signal_term_handler) + + def check_config_requirements(): """ Checking if all required parameters were passed diff --git a/ocs_ci/utility/utils.py b/ocs_ci/utility/utils.py index e8e485900b8..e46dca38232 100644 --- a/ocs_ci/utility/utils.py +++ b/ocs_ci/utility/utils.py @@ -1753,7 +1753,11 @@ def email_reports(session): [recipients.append(mailid) for mailid in mailids.split(",")] sender = "ocs-ci@redhat.com" msg = MIMEMultipart("alternative") + aborted_message = "" + if config.RUN.get("aborted"): + aborted_message = "[JOB ABORTED] " msg["Subject"] = ( + f"{aborted_message}" f"ocs-ci results for {get_testrun_name()} " f"({build_str}" f"RUN ID: {config.RUN['run_id']}) "