Revert some accidental reverts

    Also fix some style errors
    Changed argument name in FlowAddedCount for clarity and avoid
        python buitin name conflict
    delete swap file
diff --git a/TestON/core/teston.py b/TestON/core/teston.py
index 27ddea7..f48d3dd 100644
--- a/TestON/core/teston.py
+++ b/TestON/core/teston.py
@@ -31,6 +31,7 @@
 import __builtin__
 import new
 import xmldict
+import importlib
 module = new.module("test")
 import openspeak
 global path, drivers_path, core_path, tests_path,logs_path
@@ -159,7 +160,7 @@
         driver_options ['type'] = driverName
         
         classPath = self.getDriverPath(driverName.lower())
-        driverModule = __import__(classPath, globals(), locals(), [driverName.lower()], -1)
+        driverModule = importlib.import_module(classPath)
         driverClass = getattr(driverModule, driverName)
         driverObject = driverClass()
          
@@ -242,8 +243,10 @@
                 exec code[testCaseNumber][step] in module.__dict__
                 self.stepCount = self.stepCount + 1
             except TypeError,e:
+                print "Exception in the following section of code:"
+                print code[testCaseNumber][step]
                 self.stepCount = self.stepCount + 1
-                self.log.error(e)
+                self.log.exception(e)
             return main.TRUE
         
         if cli.stop:
@@ -444,8 +447,8 @@
             try :
                 import json
                 response_dict = json.loads(response)
-            except Exception , e :
-                print e
+            except Exception, e:
+                main.log.exception( e )
                 main.log.error("Json Parser is unable to parse the string")
             return response_dict
         
@@ -463,7 +466,7 @@
             try :
                 response_dict = xmldict.xml_to_dict("<response> "+str(response)+" </response>")
             except Exception, e:
-                main.log.error(e)
+                main.log.exception( e )
             return response_dict
         
     def dict_to_return_format(self,response,return_format,response_dict):
diff --git a/TestON/drivers/common/cli/.onosclidriver.py.swo b/TestON/drivers/common/cli/.onosclidriver.py.swo
deleted file mode 100644
index 87ea889..0000000
--- a/TestON/drivers/common/cli/.onosclidriver.py.swo
+++ /dev/null
Binary files differ
diff --git a/TestON/drivers/common/cli/onosclidriver.py b/TestON/drivers/common/cli/onosclidriver.py
index 14a1f17..5d547fa 100644
--- a/TestON/drivers/common/cli/onosclidriver.py
+++ b/TestON/drivers/common/cli/onosclidriver.py
@@ -19,6 +19,8 @@
 import sys
 import pexpect
 import re
+import json
+import types
 sys.path.append( "../" )
 from drivers.common.clidriver import CLI
 
@@ -472,9 +474,14 @@
         by issuing command: 'onos> feature:uninstall <feature_str>'
         """
         try:
-            cmdStr = "feature:uninstall " + str( featureStr )
-            self.sendline( cmdStr )
-            # TODO: Check for possible error responses from karaf
+            cmdStr = 'feature:list -i | grep "' + featureStr + '"'
+            handle = self.sendline( cmdStr )
+            if handle != '':
+                cmdStr = "feature:uninstall " + str( featureStr )
+                self.sendline( cmdStr )
+                # TODO: Check for possible error responses from karaf
+            else:
+                main.log.info( "Feature needs to be installed before uninstalling it" )
             return main.TRUE
         except TypeError:
             main.log.exception( self.name + ": Object not as expected" )
@@ -701,7 +708,6 @@
         None if no match
         """
         try:
-            import json
             if deviceId is None:
                 return None
             else:
@@ -733,7 +739,6 @@
                  main.FALSE any device has no master
         """
         try:
-            import json
             rawRoles = self.roles()
             rolesJson = json.loads( rawRoles )
             # search json for the device with id then return the device
@@ -837,7 +842,6 @@
 
         Return None if there is no match
         """
-        import json
         try:
             if mac is None:
                 return None
@@ -1286,7 +1290,6 @@
             main.cleanup()
             main.exit()
 
-
     def removeIntent( self, intentId, app = 'org.onosproject.cli',
         purge = False, sync = False ):
         """
@@ -1405,8 +1408,6 @@
             stateDict = Dictionary of intent's state. intent ID as the keys and
             state as the values.
         """
-        import json
-        import types
         try:
             state = "State is Undefined"
             if not intentsJson:
@@ -1450,7 +1451,7 @@
             main.log.exception( self.name + ": Uncaught exception!" )
             main.cleanup()
             main.exit()
-    
+
     def flows( self, jsonFormat=True ):
         """
         Optional:
@@ -1642,6 +1643,26 @@
             main.cleanup()
             main.exit()
 
+    def FlowAddedCount( self, deviceId ):
+        """
+        Determine the number of flow rules for the given device id that are
+        in the added state
+        """
+        try:
+            cmdStr = "flows any " + str( deviceId ) + " | " +\
+                     "grep 'state=ADDED' | wc -l"
+            handle = self.sendline( cmdStr )
+            return handle
+        except pexpect.EOF:
+            main.log.error( self.name + ": EOF exception found" )
+            main.log.error( self.name + ":    " + self.handle.before )
+            main.cleanup()
+            main.exit()
+        except:
+            main.log.exception( self.name + ": Uncaught exception!" )
+            main.cleanup()
+            main.exit()
+
     def getAllDevicesId( self ):
         """
         Use 'devices' function to obtain list of all devices
@@ -1733,7 +1754,6 @@
         Return the first device from the devices api whose 'id' contains 'dpid'
         Return None if there is no match
         """
-        import json
         try:
             if dpid is None:
                 return None
@@ -2123,23 +2143,3 @@
             main.cleanup()
             main.exit()
 
-    def testExceptions( self, obj ):
-        """
-        Test exception logging
-        """
-        # FIXME: Remove this before you commit
-
-        try:
-            return obj[ 'dedf' ]
-        except TypeError:
-            main.log.exception( self.name + ": Object not as expected" )
-            return None
-        except pexpect.EOF:
-            main.log.error( self.name + ": EOF exception found" )
-            main.log.error( self.name + ":    " + self.handle.before )
-            main.cleanup()
-            main.exit()
-        except:
-            main.log.exception( self.name + ": Uncaught exception!" )
-            main.cleanup()
-            main.exit()