[ONOS-3367] Updated HA test to use the new mininet functions for getting flow tables and comparing them

Change-Id: I6808c69f446819a85b59c8801b4b61819dc3d232
diff --git a/TestON/drivers/common/cli/emulator/mininetclidriver.py b/TestON/drivers/common/cli/emulator/mininetclidriver.py
index 4d1262e..07acc01 100644
--- a/TestON/drivers/common/cli/emulator/mininetclidriver.py
+++ b/TestON/drivers/common/cli/emulator/mininetclidriver.py
@@ -1900,16 +1900,30 @@
         else:
             main.log.error( "Connection failed to the Mininet host" )
 
-    def flowComp( self, flow1, flow2 ):
-        if flow1 == flow2:
+    def flowTableComp( self, flowTable1, flowTable2 ):
+        # This function compares the selctors and treatments of each flow
+        try:
+            if len(flowTable1) != len(flowTable2):
+                main.log.warn( "Flow table lengths do not match" )
+                return main.FALSE
+
+            for i in range( len(flowTable1) ):
+                flow1 = str(flowTable1[i].get( "selector" )) + str(flowTable1[i].get( "treatment" ))
+                flow2 = str(flowTable2[i].get( "selector" )) + str(flowTable2[i].get( "treatment" ))
+                if flow1 != flow2:
+                    main.log.info( "Flow tables do not match, printing tables:" )
+                    main.log.info( "Before:" )
+                    main.log.info( flow1 )
+                    main.log.info( "After:" )
+                    main.log.info( flow2 )
+                    return main.FALSE
+
             return main.TRUE
-        else:
-            main.log.info( "Flow tables do not match, printing tables:" )
-            main.log.info( "Flow Table 1:" )
-            main.log.info( flow1 )
-            main.log.info( "Flow Table 2:" )
-            main.log.info( flow2 )
-            return main.FALSE
+
+        except Exception:
+            main.log.exception( "Uncaught exception!" )
+            main.cleanup()
+            main.exit()
 
     def parseFlowTable( self, flowTable, version="", debug=True ):
         '''
@@ -1961,7 +1975,7 @@
                 else:
                     field = item.split("=")
                     criteria.append( {field[0]:field[1]} )
-            selector = {"selector": {"criteria":criteria} }
+            selector = {"selector": {"criteria":sorted(criteria)} }
             treat = temp[index]
             # get rid of the action part e.g. "action=output:2"
             # we will add it back later
@@ -1973,7 +1987,7 @@
                 field = item.split(":")
                 action.append( {field[0]:field[1]} )
             # create the treatment field and add the actions
-            treatment = {"treatment": {"action":action} }
+            treatment = {"treatment": {"action":sorted(action)} }
             # parse the rest of the flow
             for item in parsedFlow:
                 field = item.split("=")
diff --git a/TestON/tests/HAclusterRestart/HAclusterRestart.py b/TestON/tests/HAclusterRestart/HAclusterRestart.py
index 2dc2b8f..79d575b 100644
--- a/TestON/tests/HAclusterRestart/HAclusterRestart.py
+++ b/TestON/tests/HAclusterRestart/HAclusterRestart.py
@@ -2060,18 +2060,13 @@
         main.step( "Get the OF Table entries and compare to before " +
                    "component failure" )
         FlowTables = main.TRUE
-        flows2 = []
         for i in range( 28 ):
             main.log.info( "Checking flow table on s" + str( i + 1 ) )
-            tmpFlows = main.Mininet1.getFlowTable( "s" + str( i + 1 ), version="1.3" )
-            flows2.append( tmpFlows )
-            tempResult = main.Mininet1.flowComp(
-                flow1=flows[ i ],
-                flow2=tmpFlows )
-            FlowTables = FlowTables and tempResult
+            tmpFlows = main.Mininet1.getFlowTable( "s" + str( i + 1 ), version="1.3", debug=False )
+            FlowTables = FlowTables and main.Mininet1.flowTableComp( flows[i], tmpFlows )
             if FlowTables == main.FALSE:
-                main.log.info( "Differences in flow table for switch: s" +
-                               str( i + 1 ) )
+                main.log.warn( "Differences in flow table for switch: s{}".format( i + 1 ) )
+
         utilities.assert_equals(
             expect=main.TRUE,
             actual=FlowTables,
diff --git a/TestON/tests/HAkillNodes/HAkillNodes.py b/TestON/tests/HAkillNodes/HAkillNodes.py
index 5002305..d26df2f 100644
--- a/TestON/tests/HAkillNodes/HAkillNodes.py
+++ b/TestON/tests/HAkillNodes/HAkillNodes.py
@@ -1437,7 +1437,7 @@
         global flows
         flows = []
         for i in range( 1, 29 ):
-            flows.append( main.Mininet1.getFlowTable( "s" + str( i ), version="1.3" ) )
+            flows.append( main.Mininet1.getFlowTable( "s" + str( i ), version="1.3", debug=False ) )
         if flowCheck == main.FALSE:
             for table in flows:
                 main.log.warn( table )
@@ -2049,18 +2049,13 @@
         main.step( "Get the OF Table entries and compare to before " +
                    "component failure" )
         FlowTables = main.TRUE
-        flows2 = []
         for i in range( 28 ):
             main.log.info( "Checking flow table on s" + str( i + 1 ) )
-            tmpFlows = main.Mininet1.getFlowTable( "s" + str( i + 1 ), version="1.3" )
-            flows2.append( tmpFlows )
-            tempResult = main.Mininet1.flowComp(
-                flow1=flows[ i ],
-                flow2=tmpFlows )
-            FlowTables = FlowTables and tempResult
+            tmpFlows = main.Mininet1.getFlowTable( "s" + str( i + 1 ), version="1.3", debug=False )
+            FlowTables = FlowTables and main.Mininet1.flowTableComp( flows[i], tmpFlows )
             if FlowTables == main.FALSE:
-                main.log.info( "Differences in flow table for switch: s" +
-                               str( i + 1 ) )
+                main.log.warn( "Differences in flow table for switch: s{}".format( i + 1 ) )
+
         utilities.assert_equals(
             expect=main.TRUE,
             actual=FlowTables,
diff --git a/TestON/tests/HAsanity/HAsanity.py b/TestON/tests/HAsanity/HAsanity.py
index 8202609..7de57b5 100644
--- a/TestON/tests/HAsanity/HAsanity.py
+++ b/TestON/tests/HAsanity/HAsanity.py
@@ -1392,10 +1392,11 @@
         global flows
         flows = []
         for i in range( 1, 29 ):
-            flows.append( main.Mininet1.getFlowTable( "s" + str( i ), version="1.3" ) )
+            flows.append( main.Mininet1.getFlowTable( "s" + str( i ), version="1.3", debug=False ) )
         if flowCheck == main.FALSE:
             for table in flows:
                 main.log.warn( table )
+
         # TODO: Compare switch flow tables with ONOS flow tables
 
         main.step( "Start continuous pings" )
@@ -1953,18 +1954,13 @@
         main.step( "Get the OF Table entries and compare to before " +
                    "component failure" )
         FlowTables = main.TRUE
-        flows2 = []
         for i in range( 28 ):
             main.log.info( "Checking flow table on s" + str( i + 1 ) )
-            tmpFlows = main.Mininet1.getFlowTable( "s" + str( i + 1 ), version="1.3" )
-            flows2.append( tmpFlows )
-            tempResult = main.Mininet1.flowComp(
-                flow1=flows[ i ],
-                flow2=tmpFlows )
-            FlowTables = FlowTables and tempResult
+            tmpFlows = main.Mininet1.getFlowTable( "s" + str( i + 1 ), version="1.3", debug=False )
+            FlowTables = FlowTables and main.Mininet1.flowTableComp( flows[i], tmpFlows )
             if FlowTables == main.FALSE:
-                main.log.info( "Differences in flow table for switch: s" +
-                               str( i + 1 ) )
+                main.log.warn( "Differences in flow table for switch: s{}".format( i + 1 ) )
+
         utilities.assert_equals(
             expect=main.TRUE,
             actual=FlowTables,
diff --git a/TestON/tests/HAsingleInstanceRestart/HAsingleInstanceRestart.py b/TestON/tests/HAsingleInstanceRestart/HAsingleInstanceRestart.py
index c376340..52bf2f9 100644
--- a/TestON/tests/HAsingleInstanceRestart/HAsingleInstanceRestart.py
+++ b/TestON/tests/HAsingleInstanceRestart/HAsingleInstanceRestart.py
@@ -1044,7 +1044,7 @@
         global flows
         flows = []
         for i in range( 1, 29 ):
-            flows.append( main.Mininet1.getFlowTable( "s" + str( i ), version="1.3" ) )
+            flows.append( main.Mininet1.getFlowTable( "s" + str( i ), version="1.3", debug=False ) )
         if flowCheck == main.FALSE:
             for table in flows:
                 main.log.warn( table )
@@ -1368,18 +1368,13 @@
         main.step( "Get the OF Table entries and compare to before " +
                    "component failure" )
         FlowTables = main.TRUE
-        flows2 = []
         for i in range( 28 ):
             main.log.info( "Checking flow table on s" + str( i + 1 ) )
-            tmpFlows = main.Mininet1.getFlowTable( "s" + str( i + 1 ), version="1.3" )
-            flows2.append( tmpFlows )
-            tempResult = main.Mininet1.flowComp(
-                flow1=flows[ i ],
-                flow2=tmpFlows )
-            FlowTables = FlowTables and tempResult
+            tmpFlows = main.Mininet1.getFlowTable( "s" + str( i + 1 ), version="1.3", debug=False )
+            FlowTables = FlowTables and main.Mininet1.flowTableComp( flows[i], tmpFlows )
             if FlowTables == main.FALSE:
-                main.log.info( "Differences in flow table for switch: s" +
-                               str( i + 1 ) )
+                main.log.warn( "Differences in flow table for switch: s{}".format( i + 1 ) )
+
         utilities.assert_equals(
             expect=main.TRUE,
             actual=FlowTables,
diff --git a/TestON/tests/HAstopNodes/HAstopNodes.py b/TestON/tests/HAstopNodes/HAstopNodes.py
index 3de6064..ce3bb6c 100644
--- a/TestON/tests/HAstopNodes/HAstopNodes.py
+++ b/TestON/tests/HAstopNodes/HAstopNodes.py
@@ -1426,7 +1426,7 @@
         global flows
         flows = []
         for i in range( 1, 29 ):
-            flows.append( main.Mininet1.getFlowTable( "s" + str( i ), version="1.3" ) )
+            flows.append( main.Mininet1.getFlowTable( "s" + str( i ), version="1.3", debug=False ) )
         if flowCheck == main.FALSE:
             for table in flows:
                 main.log.warn( table )
@@ -2038,18 +2038,13 @@
         main.step( "Get the OF Table entries and compare to before " +
                    "component failure" )
         FlowTables = main.TRUE
-        flows2 = []
         for i in range( 28 ):
             main.log.info( "Checking flow table on s" + str( i + 1 ) )
-            tmpFlows = main.Mininet1.getFlowTable( "s" + str( i + 1 ), version="1.3" )
-            flows2.append( tmpFlows )
-            tempResult = main.Mininet1.flowComp(
-                flow1=flows[ i ],
-                flow2=tmpFlows )
-            FlowTables = FlowTables and tempResult
+            tmpFlows = main.Mininet1.getFlowTable( "s" + str( i + 1 ), version="1.3", debug=False )
+            FlowTables = FlowTables and main.Mininet1.flowTableComp( flows[i], tmpFlows )
             if FlowTables == main.FALSE:
-                main.log.info( "Differences in flow table for switch: s" +
-                               str( i + 1 ) )
+                main.log.warn( "Differences in flow table for switch: s{}".format( i + 1 ) )
+
         utilities.assert_equals(
             expect=main.TRUE,
             actual=FlowTables,