Skip to content

Commit

Permalink
Merge pull request #9785 from openshift-cherrypick-robot/cherry-pick-…
Browse files Browse the repository at this point in the history
…9734-to-release-4.13

[release-4.13] Handle SIGTERM as SIGINT for first attempt
  • Loading branch information
petr-balogh authored May 13, 2024
2 parents ed0cb13 + e210638 commit 6456b9b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
22 changes: 22 additions & 0 deletions ocs_ci/framework/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import argparse
import os
import re
import signal
import sys
import time

Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions ocs_ci/utility/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1719,7 +1719,11 @@ def email_reports(session):
[recipients.append(mailid) for mailid in mailids.split(",")]
sender = "[email protected]"
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']}) "
Expand Down

0 comments on commit 6456b9b

Please sign in to comment.