Skip to content

Commit e66dc00

Browse files
committed
Adding signal handler module
Signal handler function is added for graceful exiting of the test framework. Fixes: #208 Signed-off-by: Nishith Vihar Sakinala <nsakinal@redhat.com>
1 parent ca587b0 commit e66dc00

File tree

9 files changed

+64
-3
lines changed

9 files changed

+64
-3
lines changed

core/environ.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import sys
22
sys.path.insert(1, ".")
33
from common.mixin import RedantMixin
4+
from signal_handler import signal_handler
5+
import signal
46

57
class environ:
68
"""

core/parsing/params_handler.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@
33
which contains APIs for configuration parameter
44
parsing.
55
"""
6+
import sys
67
from parsing.test_parser import Parser
8+
from core.signal_handler import signal_handler
9+
import signal
710

811

912
class ParamsHandler:
1013
"""
1114
This class contains all the APIs required for fetching
1215
the values of all the configuration parameters.
1316
"""
14-
17+
1518
@classmethod
1619
def set_config_hashmap(cls, filepath: str):
1720
"""

core/parsing/test_parser.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
This module consists a single class - Parser,which
33
parses the configuration file given the filepath.
44
"""
5+
import sys
56
import yaml
7+
sys.path.insert(1,".")
8+
from core.signal_handler import signal_handler
9+
import signal
610

711

812
class Parser():

core/redant_main.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
from test_runner import TestRunner
1515
from result_handler import ResultHandler
1616
from environ import environ
17+
from signal_handler import signal_handler
18+
import signal
1719

1820
def pars_args():
1921
"""
@@ -58,7 +60,7 @@ def main():
5860

5961
start = time.time()
6062
args = pars_args()
61-
63+
6264
ParamsHandler.set_config_hashmap(args.config_file)
6365

6466
# Obtain the client and server dict.
@@ -97,4 +99,8 @@ def main():
9799

98100

99101
if __name__ == '__main__':
102+
103+
signal.signal(signal.SIGINT, signal_handler)
104+
signal.signal(signal.SIGTSTP, signal_handler)
105+
100106
main()

core/result_handler.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
"""
88
from prettytable import PrettyTable
99
from colorama import Fore, Style
10+
from signal_handler import signal_handler
11+
import signal
1012

1113

1214
class ResultHandler:

core/signal_handler.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""
2+
This file consists of functions for handling
3+
signals. Signal handling is required for the
4+
graceful exit of the test framework
5+
"""
6+
7+
import signal
8+
9+
def signal_handler(signalNumber, frame):
10+
"""
11+
Function for handling signal and raising the
12+
SystemExit call for graceful exit of the test
13+
framework
14+
Args:
15+
signalNumber (int): The signal number of the signal caught
16+
frame: current stack frame, None or stack frame object.
17+
"""
18+
print("Signal Received",signalNumber)
19+
raise SystemExit('Exiting...')
20+
return

core/test_list_builder.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import copy
1414
import sys
1515
from comment_parser.comment_parser import extract_comments
16+
from signal_handler import signal_handler
17+
import signal
1618

1719

1820
class TestListBuilder:

core/test_runner.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
from threading import Thread, Semaphore
99
from colorama import Fore, Style
1010
from runner_thread import RunnerThread
11-
11+
from signal_handler import signal_handler
12+
import signal
1213

1314
class TestRunner:
1415
"""

tools/signal_handler.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
This file contains a class named SignalHandler
3+
which contains different signal handler methods
4+
for different signals. Signal Handling is required
5+
for the graceful exiting of the test framework.
6+
"""
7+
8+
import signal
9+
10+
def signal_handler(signalNumber, frame):
11+
"""
12+
Function catches the signal given and raises SystemExit
13+
call to exit the framework gracefully
14+
Args:
15+
signalNumber: The signal number of the signal caught according
16+
to POSIX standard
17+
frame: current stack frame, either None or frame object
18+
"""
19+
print("Signal Received",signalNumber)
20+
raise SystemExit('Exiting...')
21+
return

0 commit comments

Comments
 (0)