Skip to content

Commit

Permalink
Handle SIGTERM as SIGINT for first attempt (#9734)
Browse files Browse the repository at this point in the history
* Handle SIGTERM as SIGINT for first attempt

In the Jenkins job, when it's aborted it's trying to SIGTERM with signal
15 which doesn't allow the pytest to finish gracefully.

With changing it to SIGINT, the pytest should attempt to finalize the
fixtures and clean up the resources gracefully.

* Propagate [JOB ABORTED] to mail subject

---------

Signed-off-by: Petr Balogh <[email protected]>
  • Loading branch information
petr-balogh authored Apr 26, 2024
1 parent 0e1402e commit 6de2737
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 @@ -1753,7 +1753,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 6de2737

Please sign in to comment.