Hello Jenkins Builder,
I'd like you to reexamine a change. Please visit
https://gerrit.osmocom.org/2670
to look at the new patch set (#2).
Handle termination signals to exit gracefully and prevent resource leak
Make sure we free the reserved resources and kill launched subprocesses
before stopping. Before this patch it was not the case for instance if we
received a SIGTREM signal from kill.
Change-Id: I039e4d1908a04bf606b101ddc6a186ba67e6178e
---
M src/osmo-gsm-tester.py
M src/osmo_gsm_tester/suite.py
2 files changed, 32 insertions(+), 15 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-gsm-tester refs/changes/70/2670/2
diff --git a/src/osmo-gsm-tester.py b/src/osmo-gsm-tester.py
index 1473d6d..8a4c67a 100755
--- a/src/osmo-gsm-tester.py
+++ b/src/osmo-gsm-tester.py
@@ -68,10 +68,22 @@
import sys
import argparse
+from signal import *
from osmo_gsm_tester import __version__
from osmo_gsm_tester import trial, suite, log, config
+def sig_handler_cleanup(signum, frame):
+ print("killed by signal %d" % signum)
+ # This sys.exit() will raise a SystemExit base exception at the current
+ # point of execution. Code must be prepared to clean system-wide resources
+ # by using the "finally" section. This allows at the end 'atexit' hooks to
+ # be called before exiting.
+ sys.exit(1)
+
def main():
+
+ for sig in (SIGINT, SIGTERM, SIGQUIT, SIGPIPE, SIGHUP):
+ signal(sig, sig_handler_cleanup)
parser = argparse.ArgumentParser(epilog=__doc__,
formatter_class=argparse.RawTextHelpFormatter)
# Note: since we're using RawTextHelpFormatter to keep nicely separate
@@ -185,7 +197,7 @@
if status == trial.Trial.FAIL:
any_failed = True
trials_run.append(current_trial)
- except:
+ except Exception:
current_trial.log_exn()
sys.stderr.flush()
diff --git a/src/osmo_gsm_tester/suite.py b/src/osmo_gsm_tester/suite.py
index 0d7f931..e9cd8ff 100644
--- a/src/osmo_gsm_tester/suite.py
+++ b/src/osmo_gsm_tester/suite.py
@@ -248,20 +248,25 @@
def run_tests(self, names=None):
self.log('Suite run start')
- self.init_test_vars()
- if not self.reserved_resources:
- self.reserve_resources()
- for test in self.definition.tests:
- if names and not test.name() in names:
- test.set_skip()
- self.test_skipped_ctr += 1
- self.tests.append(test)
- continue
- with self:
- if test.run(self) == Test.FAIL:
- self.test_failed_ctr += 1
- self.tests.append(test)
- self.stop_processes()
+ try:
+ self.init_test_vars()
+ if not self.reserved_resources:
+ self.reserve_resources()
+ for test in self.definition.tests:
+ if names and not test.name() in names:
+ test.set_skip()
+ self.test_skipped_ctr += 1
+ self.tests.append(test)
+ continue
+ with self:
+ if test.run(self) == Test.FAIL:
+ self.test_failed_ctr += 1
+ self.tests.append(test)
+ finally:
+ # if sys.exit() called from signal handler (e.g. SIGINT),
SystemExit
+ # base exception is raised. Make sure to clean resources/processes
+ # in the finally section:
+ self.stop_processes()
self.ts_end = time.time()
self.time = round(self.ts_end - self.ts_start)
if self.test_failed_ctr:
--
To view, visit https://gerrit.osmocom.org/2670
To unsubscribe, visit https://gerrit.osmocom.org/settings
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I039e4d1908a04bf606b101ddc6a186ba67e6178e
Gerrit-PatchSet: 2
Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: report
Gerrit-Owner: Pau Espin Pedrol <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Neels Hofmeyr <[email protected]>
Gerrit-Reviewer: Pau Espin Pedrol <[email protected]>
Gerrit-Reviewer: neels <[email protected]>