Merge pull request #140 from opennetworkinglab/OnosCHO

Added new getOnosIPfromCell to onosdriver and updated CHO scripts
diff --git a/TestON/tests/HATestClusterRestart/HATestClusterRestart.py b/TestON/tests/HATestClusterRestart/HATestClusterRestart.py
index c1bd2f0..c08fc96 100644
--- a/TestON/tests/HATestClusterRestart/HATestClusterRestart.py
+++ b/TestON/tests/HATestClusterRestart/HATestClusterRestart.py
@@ -270,19 +270,13 @@
                                 "master of the device."
         main.step( "Assign switches to controllers" )
 
-        # TODO: rewrite this function to take lists of ips and ports?
-        #       or list of tuples?
+        ipList = []
+        for i in range( numControllers ):
+            ipList.append( nodes[ i ].ip_address )
+        swList = []
         for i in range( 1, 29 ):
-            main.Mininet1.assignSwController(
-                sw=str( i ),
-                count=numControllers,
-                ip1=nodes[ 0 ].ip_address, port1=ONOS1Port,
-                ip2=nodes[ 1 ].ip_address, port2=ONOS2Port,
-                ip3=nodes[ 2 ].ip_address, port3=ONOS3Port,
-                ip4=nodes[ 3 ].ip_address, port4=ONOS4Port,
-                ip5=nodes[ 4 ].ip_address, port5=ONOS5Port,
-                ip6=nodes[ 5 ].ip_address, port6=ONOS6Port,
-                ip7=nodes[ 6 ].ip_address, port7=ONOS7Port )
+            swList.append( "s" + str( i ) )
+        main.Mininet1.assignSwController( sw=swList, ip=ipList )
 
         mastershipCheck = main.TRUE
         for i in range( 1, 29 ):
@@ -479,12 +473,13 @@
         for i in range(2):  # Retry if pingall fails first time
             time1 = time.time()
             pingResult = main.Mininet1.pingall()
-            utilities.assert_equals(
-                expect=main.TRUE,
-                actual=pingResult,
-                onpass="Reactive Pingall test passed",
-                onfail="Reactive Pingall failed, " +
-                       "one or more ping pairs failed" )
+            if i == 0:
+                utilities.assert_equals(
+                    expect=main.TRUE,
+                    actual=pingResult,
+                    onpass="Reactive Pingall test passed",
+                    onfail="Reactive Pingall failed, " +
+                           "one or more ping pairs failed" )
             time2 = time.time()
             main.log.info( "Time for pingall: %2f seconds" %
                            ( time2 - time1 ) )
@@ -2268,7 +2263,7 @@
                                          " hosts don't match Mininet" )
                 # CHECKING HOST ATTACHMENT POINTS
                 hostAttachment = True
-                zeroHosts = False
+                noHosts = False
                 # FIXME: topo-HA/obelisk specific mappings:
                 # key is mac and value is dpid
                 mappings = {}
@@ -2301,7 +2296,7 @@
                 if hosts[ controller ] or "Error" not in hosts[ controller ]:
                     if hosts[ controller ] == []:
                         main.log.warn( "There are no hosts discovered" )
-                        zeroHosts = True
+                        noHosts = True
                     else:
                         for host in hosts[ controller ]:
                             mac = None
@@ -2345,7 +2340,7 @@
                     main.log.error( "No hosts json output or \"Error\"" +
                                     " in output. hosts = " +
                                     repr( hosts[ controller ] ) )
-                if zeroHosts:
+                if noHosts is False:
                     # TODO: Find a way to know if there should be hosts in a
                     #       given point of the test
                     hostAttachment = True
@@ -2641,22 +2636,10 @@
         main.Mininet1.addSwitch( switch, dpid=switchDPID )
         for peer in links:
             main.Mininet1.addLink( switch, peer )
-        main.Mininet1.assignSwController( sw=switch.split( 's' )[ 1 ],
-                                          count=numControllers,
-                                          ip1=nodes[ 0 ].ip_address,
-                                          port1=ONOS1Port,
-                                          ip2=nodes[ 1 ].ip_address,
-                                          port2=ONOS2Port,
-                                          ip3=nodes[ 2 ].ip_address,
-                                          port3=ONOS3Port,
-                                          ip4=nodes[ 3 ].ip_address,
-                                          port4=ONOS4Port,
-                                          ip5=nodes[ 4 ].ip_address,
-                                          port5=ONOS5Port,
-                                          ip6=nodes[ 5 ].ip_address,
-                                          port6=ONOS6Port,
-                                          ip7=nodes[ 6 ].ip_address,
-                                          port7=ONOS7Port )
+        ipList = []
+        for i in range( numControllers ):
+            ipList.append( nodes[ i ].ip_address )
+        main.Mininet1.assignSwController( sw=switch, ip=ipList )
         main.log.info( "Waiting " + str( switchSleep ) +
                        " seconds for switch up to be discovered" )
         time.sleep( switchSleep )
diff --git a/TestON/tests/HATestMinorityRestart/HATestMinorityRestart.py b/TestON/tests/HATestMinorityRestart/HATestMinorityRestart.py
index 08d81c2..7a21c01 100644
--- a/TestON/tests/HATestMinorityRestart/HATestMinorityRestart.py
+++ b/TestON/tests/HATestMinorityRestart/HATestMinorityRestart.py
@@ -265,19 +265,13 @@
                                 "master of the device."
         main.step( "Assign switches to controllers" )
 
-        # TODO: rewrite this function to take lists of ips and ports?
-        #       or list of tuples?
+        ipList = []
+        for i in range( numControllers ):
+            ipList.append( nodes[ i ].ip_address )
+        swList = []
         for i in range( 1, 29 ):
-            main.Mininet1.assignSwController(
-                sw=str( i ),
-                count=numControllers,
-                ip1=nodes[ 0 ].ip_address, port1=ONOS1Port,
-                ip2=nodes[ 1 ].ip_address, port2=ONOS2Port,
-                ip3=nodes[ 2 ].ip_address, port3=ONOS3Port,
-                ip4=nodes[ 3 ].ip_address, port4=ONOS4Port,
-                ip5=nodes[ 4 ].ip_address, port5=ONOS5Port,
-                ip6=nodes[ 5 ].ip_address, port6=ONOS6Port,
-                ip7=nodes[ 6 ].ip_address, port7=ONOS7Port )
+            swList.append( "s" + str( i ) )
+        main.Mininet1.assignSwController( sw=swList, ip=ipList )
 
         mastershipCheck = main.TRUE
         for i in range( 1, 29 ):
@@ -462,12 +456,13 @@
         for i in range(2):  # Retry if pingall fails first time
             time1 = time.time()
             pingResult = main.Mininet1.pingall()
-            utilities.assert_equals(
-                expect=main.TRUE,
-                actual=pingResult,
-                onpass="Reactive Pingall test passed",
-                onfail="Reactive Pingall failed, " +
-                       "one or more ping pairs failed" )
+            if i == 0:
+                utilities.assert_equals(
+                    expect=main.TRUE,
+                    actual=pingResult,
+                    onpass="Reactive Pingall test passed",
+                    onfail="Reactive Pingall failed, " +
+                           "one or more ping pairs failed" )
             time2 = time.time()
             main.log.info( "Time for pingall: %2f seconds" %
                            ( time2 - time1 ) )
@@ -2587,22 +2582,10 @@
         main.Mininet1.addSwitch( switch, dpid=switchDPID )
         for peer in links:
             main.Mininet1.addLink( switch, peer )
-        main.Mininet1.assignSwController( sw=switch.split( 's' )[ 1 ],
-                                          count=numControllers,
-                                          ip1=nodes[ 0 ].ip_address,
-                                          port1=ONOS1Port,
-                                          ip2=nodes[ 1 ].ip_address,
-                                          port2=ONOS2Port,
-                                          ip3=nodes[ 2 ].ip_address,
-                                          port3=ONOS3Port,
-                                          ip4=nodes[ 3 ].ip_address,
-                                          port4=ONOS4Port,
-                                          ip5=nodes[ 4 ].ip_address,
-                                          port5=ONOS5Port,
-                                          ip6=nodes[ 5 ].ip_address,
-                                          port6=ONOS6Port,
-                                          ip7=nodes[ 6 ].ip_address,
-                                          port7=ONOS7Port )
+        ipList = []
+        for i in range( numControllers ):
+            ipList.append( nodes[ i ].ip_address )
+        main.Mininet1.assignSwController( sw=switch, ip=ipList )
         main.log.info( "Waiting " + str( switchSleep ) +
                        " seconds for switch up to be discovered" )
         time.sleep( switchSleep )
diff --git a/TestON/tests/HATestSanity/HATestSanity.py b/TestON/tests/HATestSanity/HATestSanity.py
index 306e547..83b4e51 100644
--- a/TestON/tests/HATestSanity/HATestSanity.py
+++ b/TestON/tests/HATestSanity/HATestSanity.py
@@ -265,19 +265,13 @@
                                 "master of the device."
         main.step( "Assign switches to controllers" )
 
-        # TODO: rewrite this function to take lists of ips and ports?
-        #       or list of tuples?
+        ipList = []
+        for i in range( numControllers ):
+            ipList.append( nodes[ i ].ip_address )
+        swList = []
         for i in range( 1, 29 ):
-            main.Mininet1.assignSwController(
-                sw=str( i ),
-                count=numControllers,
-                ip1=nodes[ 0 ].ip_address, port1=ONOS1Port,
-                ip2=nodes[ 1 ].ip_address, port2=ONOS2Port,
-                ip3=nodes[ 2 ].ip_address, port3=ONOS3Port,
-                ip4=nodes[ 3 ].ip_address, port4=ONOS4Port,
-                ip5=nodes[ 4 ].ip_address, port5=ONOS5Port,
-                ip6=nodes[ 5 ].ip_address, port6=ONOS6Port,
-                ip7=nodes[ 6 ].ip_address, port7=ONOS7Port )
+            swList.append( "s" + str( i ) )
+        main.Mininet1.assignSwController( sw=swList, ip=ipList )
 
         mastershipCheck = main.TRUE
         for i in range( 1, 29 ):
@@ -462,12 +456,13 @@
         for i in range(2):  # Retry if pingall fails first time
             time1 = time.time()
             pingResult = main.Mininet1.pingall()
-            utilities.assert_equals(
-                expect=main.TRUE,
-                actual=pingResult,
-                onpass="Reactive Pingall test passed",
-                onfail="Reactive Pingall failed, " +
-                       "one or more ping pairs failed" )
+            if i == 0:
+                utilities.assert_equals(
+                    expect=main.TRUE,
+                    actual=pingResult,
+                    onpass="Reactive Pingall test passed",
+                    onfail="Reactive Pingall failed, " +
+                           "one or more ping pairs failed" )
             time2 = time.time()
             main.log.info( "Time for pingall: %2f seconds" %
                            ( time2 - time1 ) )
@@ -854,6 +849,7 @@
             intents = main.ONOScli1.intents()
             intentStates = []
             main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
+            count = 0
             # Iter through intents of a node
             try:
                 for intent in json.loads( intents ):
@@ -2538,22 +2534,10 @@
         main.Mininet1.addSwitch( switch, dpid=switchDPID )
         for peer in links:
             main.Mininet1.addLink( switch, peer )
-        main.Mininet1.assignSwController( sw=switch.split( 's' )[ 1 ],
-                                          count=numControllers,
-                                          ip1=nodes[ 0 ].ip_address,
-                                          port1=ONOS1Port,
-                                          ip2=nodes[ 1 ].ip_address,
-                                          port2=ONOS2Port,
-                                          ip3=nodes[ 2 ].ip_address,
-                                          port3=ONOS3Port,
-                                          ip4=nodes[ 3 ].ip_address,
-                                          port4=ONOS4Port,
-                                          ip5=nodes[ 4 ].ip_address,
-                                          port5=ONOS5Port,
-                                          ip6=nodes[ 5 ].ip_address,
-                                          port6=ONOS6Port,
-                                          ip7=nodes[ 6 ].ip_address,
-                                          port7=ONOS7Port )
+        ipList = []
+        for i in range( numControllers ):
+            ipList.append( nodes[ i ].ip_address )
+        main.Mininet1.assignSwController( sw=switch, ip=ipList )
         main.log.info( "Waiting " + str( switchSleep ) +
                        " seconds for switch up to be discovered" )
         time.sleep( switchSleep )
diff --git a/TestON/tests/HATestSingleInstanceRestart/HATestSingleInstanceRestart.py b/TestON/tests/HATestSingleInstanceRestart/HATestSingleInstanceRestart.py
index f77ca3d..a3a8a66 100644
--- a/TestON/tests/HATestSingleInstanceRestart/HATestSingleInstanceRestart.py
+++ b/TestON/tests/HATestSingleInstanceRestart/HATestSingleInstanceRestart.py
@@ -233,10 +233,13 @@
                                 "master of the device."
         main.step( "Assign switches to controllers" )
 
+        ipList = []
+        for i in range( numControllers ):
+            ipList.append( nodes[ i ].ip_address )
+        swList = []
         for i in range( 1, 29 ):
-            main.Mininet1.assignSwController(
-                sw=str( i ),
-                ip1=ONOS1Ip, port1=ONOS1Port )
+            swList.append( "s" + str( i ) )
+        main.Mininet1.assignSwController( sw=swList, ip=ipList )
 
         mastershipCheck = main.TRUE
         for i in range( 1, 29 ):
@@ -386,12 +389,13 @@
         for i in range(2):  # Retry if pingall fails first time
             time1 = time.time()
             pingResult = main.Mininet1.pingall()
-            utilities.assert_equals(
-                expect=main.TRUE,
-                actual=pingResult,
-                onpass="Reactive Pingall test passed",
-                onfail="Reactive Pingall failed, " +
-                       "one or more ping pairs failed" )
+            if i == 0:
+                utilities.assert_equals(
+                    expect=main.TRUE,
+                    actual=pingResult,
+                    onpass="Reactive Pingall test passed",
+                    onfail="Reactive Pingall failed, " +
+                           "one or more ping pairs failed" )
             time2 = time.time()
             main.log.info( "Time for pingall: %2f seconds" %
                            ( time2 - time1 ) )
@@ -1646,9 +1650,10 @@
         main.Mininet1.addSwitch( switch, dpid=switchDPID )
         for peer in links:
             main.Mininet1.addLink( switch, peer )
-        main.Mininet1.assignSwController( sw=switch.split( 's' )[ 1 ],
-                                          ip1=ONOS1Ip,
-                                          port1=ONOS1Port )
+        ipList = []
+        for i in range( numControllers ):
+            ipList.append( nodes[ i ].ip_address )
+        main.Mininet1.assignSwController( sw=switch, ip=ipList )
         main.log.info( "Waiting " + str( switchSleep ) +
                        " seconds for switch up to be discovered" )
         time.sleep( switchSleep )