Skip to content

Commit

Permalink
Merge pull request red-hat-storage#9786 from openshift-cherrypick-rob…
Browse files Browse the repository at this point in the history
…ot/cherry-pick-9734-to-release-4.14

[release-4.14] Handle SIGTERM as SIGINT for first attempt
  • Loading branch information
petr-balogh authored May 13, 2024
2 parents dff19aa + fa0d17e commit 29a6539
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 @@ -1724,7 +1724,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']}) "
Expand Down

0 comments on commit 29a6539

Please sign in to comment.