fix SIGINT handling
diff --git a/oft b/oft
index 3e26d52..5d8b20e 100755
--- a/oft
+++ b/oft
@@ -116,6 +116,7 @@
import os
import imp
import random
+import signal
root_dir = os.path.dirname(os.path.realpath(__file__))
@@ -572,6 +573,9 @@
logging.info("Random seed: %d" % config["random_seed"])
random.seed(config["random_seed"])
+# Remove python's signal handler which raises KeyboardError. Exiting from an
+# exception waits for all threads to terminate which might not happen.
+signal.signal(signal.SIGINT, signal.SIG_DFL)
if __name__ == "__main__":
logging.info("*** TEST RUN START: " + time.asctime())
diff --git a/tests/basic.py b/tests/basic.py
index 0112734..65f875a 100644
--- a/tests/basic.py
+++ b/tests/basic.py
@@ -16,7 +16,6 @@
"""
import time
-import signal
import sys
import logging
@@ -61,21 +60,8 @@
Root class for setting up the controller
"""
- def sig_handler(self, v1, v2):
- logging.critical("Received interrupt signal; exiting")
- print "Received interrupt signal; exiting"
- self.clean_shutdown = False
- self.tearDown()
- raise KeyboardInterrupt
-
def setUp(self):
self.config = basic_config
- #@todo Test cases shouldn't monkey with signals; move SIGINT handler
- # to top-level oft
- try:
- signal.signal(signal.SIGINT, self.sig_handler)
- except ValueError, e:
- logging.info("Could not set SIGINT handler: %s" % e)
logging.info("** START TEST CASE " + str(self))
self.controller = controller.Controller(
host=basic_config["controller_host"],
@@ -180,22 +166,9 @@
Root class that sets up only the dataplane
"""
- def sig_handler(self, v1, v2):
- logging.critical("Received interrupt signal; exiting")
- print "Received interrupt signal; exiting"
- self.clean_shutdown = False
- self.tearDown()
- raise KeyboardInterrupt
-
def setUp(self):
self.clean_shutdown = True
self.config = basic_config
- #@todo Test cases shouldn't monkey with signals; move SIGINT handler
- # to top-level oft
- try:
- signal.signal(signal.SIGINT, self.sig_handler)
- except ValueError, e:
- logging.info("Could not set SIGINT handler: %s" % e)
logging.info("** START DataPlaneOnly CASE " + str(self))
self.dataplane = dataplane.DataPlane(self.config)
for of_port, ifname in basic_port_map.items():
diff --git a/tests/cxn.py b/tests/cxn.py
index 2c56692..87f31c9 100644
--- a/tests/cxn.py
+++ b/tests/cxn.py
@@ -4,7 +4,6 @@
"""
import time
-import signal
import sys
import logging
@@ -45,13 +44,6 @@
Base handshake case to set up controller, but do not send hello.
"""
- def sig_handler(self, v1, v2):
- logging.critical("Received interrupt signal; exiting")
- print "Received interrupt signal; exiting"
- self.clean_shutdown = False
- self.tearDown()
- sys.exit(1)
-
def controllerSetup(self, host, port):
self.controller = controller.Controller(host=host,port=port)
@@ -71,12 +63,6 @@
def setUp(self):
self.config = cxn_config
- #@todo Test cases shouldn't monkey with signals; move SIGINT handler
- # to top-level oft
- try:
- signal.signal(signal.SIGINT, self.sig_handler)
- except ValueError, e:
- logging.info("Could not set SIGINT handler: %s" % e)
logging.info("** START TEST CASE " + str(self))
self.test_timeout = test_param_get(cxn_config,
diff --git a/tests/serial_failover.py b/tests/serial_failover.py
index 8ba1766..aebbbd2 100644
--- a/tests/serial_failover.py
+++ b/tests/serial_failover.py
@@ -4,7 +4,6 @@
"""
import time
-import signal
import sys
import logging
@@ -59,13 +58,6 @@
test_timeout = 0
test_iterations = 0
- def sig_handler(self, v1, v2):
- logging.critical("Received interrupt signal; exiting")
- print "Received interrupt signal; exiting"
- self.clean_shutdown = False
- self.tearDown()
- sys.exit(1)
-
def controllerSetup(self, host, port):
self.controller = controller.Controller(host=host,port=port)
@@ -139,12 +131,6 @@
def setUp(self):
self.config = serial_failover_config
- #@todo Test cases shouldn't monkey with signals; move SIGINT handler
- # to top-level oft
- try:
- signal.signal(signal.SIGINT, self.sig_handler)
- except ValueError, e:
- logging.info("Could not set SIGINT handler: %s" % e)
logging.info("** START TEST CASE " + str(self))
self.test_timeout = test_param_get(serial_failover_config,