Merge pull request #21 from rlane/move-oft2

Move oft script to the top level (v2)
diff --git a/README b/README
index ea5b7a4..fff7c8a 100644
--- a/README
+++ b/README
@@ -64,9 +64,8 @@
     Currently, switches must be running version 1.0 of OpenFlow. 
 
       # git clone git://github.com/floodlight/oftest
-      # cd oftest/tools/munger
-      # make install
-      # cd ../../tests
+      # cd oftest
+      # make -C tools/munger install
          Make sure the switch you want to test is running --
          see (4) below for the reference switch example.
       # ./oft --list
@@ -146,7 +145,7 @@
 
     5.  Run oft
         See Warning above; requires sudo to control the dataplane
-        cd <oftest>/tests
+        cd <oftest>
         sudo ./oft --help
 
 Helpful Note: Rebuilding
@@ -219,12 +218,13 @@
 
      <oftest>
          `
+         |-- oft
          |-- doc
          |-- src
          |   `-- python
          |       `-- oftest
          |-- tests
-         |   `-- oft and files with test cases
+         |   `-- test cases
          `-- tools
              |-- munger
              `-- pylibopenflow
@@ -249,6 +249,7 @@
         netutils.py:     e.g., set promisc on sockets
         ofutils.py:      Utilities related to OpenFlow messages
         oft_assert.py:   Test framework level assertion
+        testutils.py:    Test utilities
 
     Tests are run from the tests directory.  The file oft is the
     top level entry point for tests.  Try ./oft --help for some more.
diff --git a/tests/oft b/oft
similarity index 96%
rename from tests/oft
rename to oft
index 193b7a4..439bae8 100755
--- a/tests/oft
+++ b/oft
@@ -117,12 +117,14 @@
 import imp
 import random
 
-pydir = os.path.join(os.path.dirname(__file__), '..', 'src', 'python')
+root_dir = os.path.dirname(os.path.realpath(__file__))
+
+pydir = os.path.join(root_dir, 'src', 'python')
 if os.path.exists(os.path.join(pydir, 'oftest')):
     # Running from source tree
     sys.path.insert(0, pydir)
 
-import testutils
+import oftest.testutils
 import oftest.ofutils
 
 try:
@@ -151,8 +153,6 @@
 _debug_default = "warning"
 _debug_level_default = DEBUG_LEVELS[_debug_default]
 
-root_dir = os.path.join(os.path.dirname(__file__), "..")
-
 ##@var config_default
 # The default configuration dictionary for OFT
 config_default = {
@@ -163,7 +163,6 @@
     "controller_port"    : 6633,
     "relax"              : False,
     "test_spec"          : "all",
-    "test_dir"           : os.path.dirname(__file__),
     "log_file"           : "oft.log",
     "list"               : False,
     "list_test_names"    : False, 
@@ -177,6 +176,7 @@
     "default_timeout"    : 2,
     "minsize"            : 0,
     "random_seed"        : None,
+    "test_dir"           : os.path.join(root_dir, "tests"),
     "platform_dir"       : os.path.join(root_dir, "platforms"),
     "profile_dir"        : os.path.join(root_dir, "profiles"),
 }
@@ -411,6 +411,9 @@
 logging_setup(config)
 logging.info("++++++++ " + time.asctime() + " ++++++++")
 
+# Allow tests to import each other
+sys.path.append(config["test_dir"])
+
 test_list_generate(config)
 oft_config = config
 
@@ -553,7 +556,7 @@
     _verb = 2
 
 oftest.ofutils.default_timeout = config["default_timeout"]
-testutils.MINSIZE = config['minsize']
+oftest.testutils.MINSIZE = config['minsize']
 
 if os.getuid() != 0 and not config["allow_user"]:
     print "ERROR: Super-user privileges required. Please re-run with " \
@@ -568,14 +571,14 @@
 if __name__ == "__main__":
     logging.info("*** TEST RUN START: " + time.asctime())
     result = unittest.TextTestRunner(verbosity=_verb).run(suite)
-    if testutils.skipped_test_count > 0:
+    if oftest.testutils.skipped_test_count > 0:
         ts = " tests"
-        if testutils.skipped_test_count == 1: ts = " test"
-        logging.info("Skipped " + str(testutils.skipped_test_count) + ts)
-        print("Skipped " + str(testutils.skipped_test_count) + ts)
+        if oftest.testutils.skipped_test_count == 1: ts = " test"
+        logging.info("Skipped " + str(oftest.testutils.skipped_test_count) + ts)
+        print("Skipped " + str(oftest.testutils.skipped_test_count) + ts)
     logging.info("*** TEST RUN END  : " + time.asctime())
     if result.failures or result.errors:
         # exit(1) hangs sometimes
         os._exit(1)
-    if testutils.skipped_test_count > 0 and config["fail_skipped"]:
+    if oftest.testutils.skipped_test_count > 0 and config["fail_skipped"]:
         os._exit(1)
diff --git a/tests/testutils.py b/src/python/oftest/testutils.py
similarity index 100%
rename from tests/testutils.py
rename to src/python/oftest/testutils.py
diff --git a/tests/FuncUtils.py b/tests/FuncUtils.py
index 6951293..d12c388 100644
--- a/tests/FuncUtils.py
+++ b/tests/FuncUtils.py
@@ -13,7 +13,7 @@
 import logging
 import types
 import basic
-from testutils import *
+from oftest.testutils import *
 from time import sleep
 
 #################### Functions for various types of flow_mod  ##########################################################################################
diff --git a/tests/actions.py b/tests/actions.py
index f512a02..6bcfb8c 100644
--- a/tests/actions.py
+++ b/tests/actions.py
@@ -20,7 +20,7 @@
 import basic
 import time
 
-from testutils import *
+from oftest.testutils import *
 from time import sleep
 from FuncUtils import *
 
diff --git a/tests/basic.py b/tests/basic.py
index 721f953..53947b4 100644
--- a/tests/basic.py
+++ b/tests/basic.py
@@ -31,7 +31,7 @@
 
 import oftest.illegal_message as illegal_message
 
-from testutils import *
+from oftest.testutils import *
 
 #@var basic_port_map Local copy of the configuration map from OF port
 # numbers to OS interfaces
diff --git a/tests/bsn_ipmask.py b/tests/bsn_ipmask.py
index cb64cb5..489b980 100644
--- a/tests/bsn_ipmask.py
+++ b/tests/bsn_ipmask.py
@@ -9,7 +9,7 @@
 import oftest.message as message
 import basic
 
-from testutils import *
+from oftest.testutils import *
 
 #@var port_map Local copy of the configuration map from OF port
 # numbers to OS interfaces
diff --git a/tests/caps.py b/tests/caps.py
index a3355f2..93403ea 100644
--- a/tests/caps.py
+++ b/tests/caps.py
@@ -15,7 +15,7 @@
 import oftest.parse as parse
 import basic
 
-from testutils import *
+from oftest.testutils import *
 
 #@var caps_port_map Local copy of the configuration map from OF port
 # numbers to OS interfaces
diff --git a/tests/cxn.py b/tests/cxn.py
index aa2c61b..b658074 100644
--- a/tests/cxn.py
+++ b/tests/cxn.py
@@ -17,7 +17,7 @@
 import oftest.dataplane as dataplane
 import oftest.action as action
 
-from testutils import *
+from oftest.testutils import *
 
 #@var cxn_port_map Local copy of the configuration map from OF port
 # numbers to OS interfaces
diff --git a/tests/detailed_contr_sw_messages.py b/tests/detailed_contr_sw_messages.py
index 158f787..d45935d 100644
--- a/tests/detailed_contr_sw_messages.py
+++ b/tests/detailed_contr_sw_messages.py
@@ -17,7 +17,7 @@
 import oftest.parse as parse
 import basic
 
-from testutils import *
+from oftest.testutils import *
 from time import sleep
 from FuncUtils import *
 
diff --git a/tests/flow_expire.py b/tests/flow_expire.py
index ab5b68a..9be5fdd 100644
--- a/tests/flow_expire.py
+++ b/tests/flow_expire.py
@@ -17,7 +17,7 @@
 import oftest.parse as parse
 import basic
 
-from testutils import *
+from oftest.testutils import *
 from time import sleep
 
 #@var port_map Local copy of the configuration map from OF port
diff --git a/tests/flow_query.py b/tests/flow_query.py
index 63e6cb5..3017eed 100644
--- a/tests/flow_query.py
+++ b/tests/flow_query.py
@@ -74,7 +74,7 @@
 import pktact
 import basic
 
-from testutils import *
+from oftest.testutils import *
 from time import sleep
 
 #@var port_map Local copy of the configuration map from OF port
diff --git a/tests/flow_stats.py b/tests/flow_stats.py
index 9c7170e..8ff8b69 100644
--- a/tests/flow_stats.py
+++ b/tests/flow_stats.py
@@ -17,7 +17,7 @@
 import oftest.parse as parse
 import basic
 
-from testutils import *
+from oftest.testutils import *
 from time import sleep
 
 #@var fs_port_map Local copy of the configuration map from OF port
diff --git a/tests/load.py b/tests/load.py
index 7b18252..d09608e 100644
--- a/tests/load.py
+++ b/tests/load.py
@@ -31,7 +31,7 @@
 import basic
 import time
 
-from testutils import *
+from oftest.testutils import *
 
 #@var load_port_map Local copy of the configuration map from OF port
 # numbers to OS interfaces
diff --git a/tests/oft b/tests/oft
new file mode 120000
index 0000000..0b189a0
--- /dev/null
+++ b/tests/oft
@@ -0,0 +1 @@
+../oft
\ No newline at end of file
diff --git a/tests/openflow_protocol_messages.py b/tests/openflow_protocol_messages.py
index 8f2593f..c8ad1b8 100644
--- a/tests/openflow_protocol_messages.py
+++ b/tests/openflow_protocol_messages.py
@@ -18,7 +18,7 @@
 import oftest.parse as parse
 import basic
 
-from testutils import *
+from oftest.testutils import *
 from time import sleep
 from FuncUtils import *
 
diff --git a/tests/pktact.py b/tests/pktact.py
index 660aa07..fd1b014 100644
--- a/tests/pktact.py
+++ b/tests/pktact.py
@@ -30,7 +30,7 @@
 import basic
 import time
 
-from testutils import *
+from oftest.testutils import *
 
 #@var port_map Local copy of the configuration map from OF port
 # numbers to OS interfaces
diff --git a/tests/port_stats.py b/tests/port_stats.py
index 0964774..96d3cc5 100644
--- a/tests/port_stats.py
+++ b/tests/port_stats.py
@@ -17,7 +17,7 @@
 import oftest.parse as parse
 import basic
 
-from testutils import *
+from oftest.testutils import *
 from time import sleep
 
 #@var fs_port_map Local copy of the configuration map from OF port
diff --git a/tests/serial_failover.py b/tests/serial_failover.py
index d12040e..311dde1 100644
--- a/tests/serial_failover.py
+++ b/tests/serial_failover.py
@@ -17,7 +17,7 @@
 import oftest.dataplane as dataplane
 import oftest.action as action
 
-from testutils import *
+from oftest.testutils import *
 
 #@var serial_failover_port_map Local copy of the configuration map from OF port
 # numbers to OS interfaces