NSBperf: fix bad sigint handler 03/37303/2
authorRoss Brattain <ross.b.brattain@intel.com>
Thu, 13 Jul 2017 01:04:03 +0000 (18:04 -0700)
committerRoss Brattain <ross.b.brattain@intel.com>
Thu, 13 Jul 2017 01:10:26 +0000 (18:10 -0700)
This is why we don't do things at module
import time.

when we import this module it makes a bad
sigint handler.  Only load signal handlers
at runtime.

Also fix handler to take *args, **kwargs.

Unittest failures:

>     time.sleep(0.01)
E     TypeError: handler() takes 0 positional arguments but 2 were given

Change-Id: I4296a4bdef0e5f4d58b0503dcbc834f3bef0feeb
Signed-off-by: Ross Brattain <ross.b.brattain@intel.com>
tests/unit/cmd/test_NSBperf.py
yardstick/cmd/NSBperf.py

index 5bd248a..e1b4da7 100644 (file)
@@ -29,7 +29,7 @@ from yardstick.cmd import NSBperf
 class TestHandler(unittest.TestCase):
     def test_handler(self, test):
         subprocess.call = mock.Mock(return_value=0)
-        self.assertRaises(SystemExit, NSBperf.handler)
+        self.assertRaises(SystemExit, NSBperf.sigint_handler)
 
 
 class TestYardstickNSCli(unittest.TestCase):
index f158d57..011990a 100755 (executable)
@@ -39,13 +39,11 @@ if not PYTHONPATH or not VIRTUAL_ENV:
     raise SystemExit(1)
 
 
-def handler():
+def sigint_handler(*args, **kwargs):
     """ Capture ctrl+c and exit cli """
     subprocess.call(["pkill", "-9", "yardstick"])
     raise SystemExit(1)
 
-signal.signal(signal.SIGINT, handler)
-
 
 class YardstickNSCli(object):
     """ This class handles yardstick network serivce testing """
@@ -214,5 +212,6 @@ class YardstickNSCli(object):
         self.run_test(args, test_path)
 
 if __name__ == "__main__":
+    signal.signal(signal.SIGINT, sigint_handler)
     NS_CLI = YardstickNSCli()
     NS_CLI.main()