Merge branch 'master' into kenc

Conflicts:
	tests/cxn.py - manually resolved
diff --git a/tests/cxn.py b/tests/cxn.py
index a4b3d8a..d311391 100644
--- a/tests/cxn.py
+++ b/tests/cxn.py
@@ -4,13 +4,13 @@
 """
 
 import time
-import signal
 import sys
 import logging
 
 import unittest
 import random
 
+from oftest import config
 import oftest.controller as controller
 import oftest.cstruct as ofp
 import oftest.message as message
@@ -19,47 +19,15 @@
 
 from oftest.testutils import *
 
-#@var cxn_port_map Local copy of the configuration map from OF port
-# numbers to OS interfaces
-cxn_port_map = None
-#@var cxn_logger Local logger object
-cxn_logger = None
-#@var cxn_config Local copy of global configuration data
-cxn_config = None
-
-test_prio = {}
-
-def test_set_init(config):
-    """
-    Set up function for connection test classes
-
-    @param config The configuration dictionary; see oft
-    """
-
-    global cxn_port_map
-    global cxn_logger
-    global cxn_config
-
-    cxn_logger = logging.getLogger("cxn")
-    cxn_logger.info("Initializing test set")
-    cxn_port_map = config["port_map"]
-    cxn_config = config
-
 class BaseHandshake(unittest.TestCase):
     """
     Base handshake case to set up controller, but do not send hello.
     """
 
+    priority = -1
     controllers = []
     default_timeout = 2
 
-    def sig_handler(self, v1, v2):
-        cxn_logger.critical("Received interrupt signal; exiting")
-        print "Received interrupt signal; exiting"
-        self.clean_shutdown = False
-        self.tearDown()
-        sys.exit(1)
-
     def controllerSetup(self, host, port):
         con = controller.Controller(host=host,port=port)
 
@@ -72,21 +40,13 @@
         self.controllers.append(con)
 
     def setUp(self):
-        self.logger = cxn_logger
-        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:
-           cxn_logger.info("Could not set SIGINT handler: %s" % e)
-        cxn_logger.info("** START TEST CASE " + str(self))
+        logging.info("** START TEST CASE " + str(self))
 
-        self.default_timeout = test_param_get(cxn_config,
-                                              'default_timeout') or 2
+        self.default_timeout = test_param_get('default_timeout',
+                                              default=2)
 
     def tearDown(self):
-        cxn_logger.info("** END TEST CASE " + str(self))
+        logging.info("** END TEST CASE " + str(self))
         for con in self.controllers:
             con.shutdown()
             if self.clean_shutdown:
@@ -98,23 +58,22 @@
 
     def assertTrue(self, cond, msg):
         if not cond:
-            cxn_logger.error("** FAILED ASSERTION: " + msg)
+            logging.error("** FAILED ASSERTION: " + msg)
         unittest.TestCase.assertTrue(self, cond, msg)
 
-test_prio["BaseHandshake"] = -1
-
 class HandshakeNoHello(BaseHandshake):
     """
     TCP connect to switch, but do not sent hello,
     and wait for disconnect.
     """
     def runTest(self):
-        self.controllerSetup(cxn_config["controller_host"],
-                             cxn_config["controller_port"])
+        self.controllerSetup(config["controller_host"],
+                             config["controller_port"])
         self.controllers[0].connect(self.default_timeout)
-        cxn_logger.info("TCP Connected " + 
-                        str(self.controllers[0].switch_addr))
-        cxn_logger.info("Hello not sent, waiting for timeout")
+
+        logging.info("TCP Connected " + 
+                     str(self.controllers[0].switch_addr))
+        logging.info("Hello not sent, waiting for timeout")
 
         # wait for controller to die
         count = 0
@@ -127,15 +86,16 @@
     and wait for disconnect.
     """
     def runTest(self):
-        self.controllerSetup(cxn_config["controller_host"],
-                             cxn_config["controller_port"])
+        self.controllerSetup(config["controller_host"],
+                             config["controller_port"])
         self.controllers[0].connect(self.default_timeout)
-        cxn_logger.info("TCP Connected " + 
-                                    str(self.controllers[0].switch_addr))
-        cxn_logger.info("Sending hello")
+
+        logging.info("TCP Connected " + 
+                     str(self.controllers[0].switch_addr))
+        logging.info("Sending hello")
         self.controllers[0].message_send(message.hello())
 
-        cxn_logger.info("Features request not sent, waiting for timeout")
+        logging.info("Features request not sent, waiting for timeout")
 
         # wait for controller to die
         count = 0
@@ -147,13 +107,15 @@
     Complete handshake and respond to echo request, but otherwise do nothing.
     Good for manual testing.
     """
+
+    priority = -1
+
     def runTest(self):
-        self.num_controllers = test_param_get(cxn_config, 
-                                              'num_controllers') or 1
+        self.num_controllers = test_param_get('num_controllers', default=1)
 
         for i in range(self.num_controllers):
-            self.controllerSetup(cxn_config["controller_host"],
-                                 cxn_config["controller_port"]+i)
+            self.controllerSetup(config["controller_host"],
+                                 config["controller_port"]+i)
         for i in range(self.num_controllers):
             self.controllers[i].handshake_done = False
 
@@ -163,14 +125,14 @@
             for con in self.controllers:
                 if con.switch_socket and con.handshake_done:
                     if count < 7:
-                        cxn_logger.info(con.host + ":" + str(con.port) + 
-                                        ": maintaining connection to " +
-                                        str(con.switch_addr))
+                        logging.info(con.host + ":" + str(con.port) + 
+                                     ": maintaining connection to " +
+                                     str(con.switch_addr))
                         count = count + 1
                     else:
-                        cxn_logger.info(con.host + ":" + str(con.port) + 
-                                        ": disconnecting from " +
-                                        str(con.switch_addr))
+                        logging.info(con.host + ":" + str(con.port) + 
+                                     ": disconnecting from " +
+                                     str(con.switch_addr))
                         con.disconnect()
                         con.handshake_done = False
                         count = 0
@@ -180,23 +142,22 @@
                     # ensure version compatibilty?
                     con.connect(self.default_timeout)
                     if not con.switch_socket:
-                        cxn_logger.info("Did not connect to switch")
+                        logging.info("Did not connect to switch")
                         continue
-                    cxn_logger.info("TCP Connected " + str(con.switch_addr))
-                    cxn_logger.info("Sending hello")
+                    logging.info("TCP Connected " + str(con.switch_addr))
+                    logging.info("Sending hello")
                     con.message_send(message.hello())
                     request = message.features_request()
                     reply, pkt = con.transact(request, 
                                               timeout=self.default_timeout)
                     if reply:
-                        cxn_logger.info("Handshake complete with " + 
-                                        str(con.switch_addr))
+                        logging.info("Handshake complete with " + 
+                                    str(con.switch_addr))
                         con.handshake_done = True
                         con.keep_alive = True
                     else:
-                        cxn_logger.info("Did not complete features_request for handshake")
+                        logging.info("Did not complete features_request " +
+                                     "for handshake")
                         con.disconnect()
                         con.handshake_done = False
 
-test_prio["HandshakeAndKeepalive"] = -1
-