Skip to content

Commit

Permalink
Adding signal handler module
Browse files Browse the repository at this point in the history
Signal handler function is added for graceful exiting of
the test framework.

Fixes: #208
Signed-off-by: Nishith Vihar Sakinala <nsakinal@redhat.com>
  • Loading branch information
nishith-vihar committed Apr 27, 2021
1 parent ca587b0 commit e66dc00
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 3 deletions.
2 changes: 2 additions & 0 deletions core/environ.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import sys
sys.path.insert(1, ".")
from common.mixin import RedantMixin
from signal_handler import signal_handler
import signal

class environ:
"""
Expand Down
5 changes: 4 additions & 1 deletion core/parsing/params_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
which contains APIs for configuration parameter
parsing.
"""
import sys
from parsing.test_parser import Parser
from core.signal_handler import signal_handler
import signal


class ParamsHandler:
"""
This class contains all the APIs required for fetching
the values of all the configuration parameters.
"""

@classmethod
def set_config_hashmap(cls, filepath: str):
"""
Expand Down
4 changes: 4 additions & 0 deletions core/parsing/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
This module consists a single class - Parser,which
parses the configuration file given the filepath.
"""
import sys
import yaml
sys.path.insert(1,".")
from core.signal_handler import signal_handler
import signal


class Parser():
Expand Down
8 changes: 7 additions & 1 deletion core/redant_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from test_runner import TestRunner
from result_handler import ResultHandler
from environ import environ
from signal_handler import signal_handler
import signal

def pars_args():
"""
Expand Down Expand Up @@ -58,7 +60,7 @@ def main():

start = time.time()
args = pars_args()

ParamsHandler.set_config_hashmap(args.config_file)

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


if __name__ == '__main__':

signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTSTP, signal_handler)

main()
2 changes: 2 additions & 0 deletions core/result_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"""
from prettytable import PrettyTable
from colorama import Fore, Style
from signal_handler import signal_handler
import signal


class ResultHandler:
Expand Down
20 changes: 20 additions & 0 deletions core/signal_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""
This file consists of functions for handling
signals. Signal handling is required for the
graceful exit of the test framework
"""

import signal

def signal_handler(signalNumber, frame):
"""
Function for handling signal and raising the
SystemExit call for graceful exit of the test
framework
Args:
signalNumber (int): The signal number of the signal caught
frame: current stack frame, None or stack frame object.
"""
print("Signal Received",signalNumber)
raise SystemExit('Exiting...')
return
2 changes: 2 additions & 0 deletions core/test_list_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import copy
import sys
from comment_parser.comment_parser import extract_comments
from signal_handler import signal_handler
import signal


class TestListBuilder:
Expand Down
3 changes: 2 additions & 1 deletion core/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
from threading import Thread, Semaphore
from colorama import Fore, Style
from runner_thread import RunnerThread

from signal_handler import signal_handler
import signal

class TestRunner:
"""
Expand Down
21 changes: 21 additions & 0 deletions tools/signal_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""
This file contains a class named SignalHandler
which contains different signal handler methods
for different signals. Signal Handling is required
for the graceful exiting of the test framework.
"""

import signal

def signal_handler(signalNumber, frame):
"""
Function catches the signal given and raises SystemExit
call to exit the framework gracefully
Args:
signalNumber: The signal number of the signal caught according
to POSIX standard
frame: current stack frame, either None or frame object
"""
print("Signal Received",signalNumber)
raise SystemExit('Exiting...')
return

0 comments on commit e66dc00

Please sign in to comment.