Merge "Fix the issue with the HA tests on using Rest instead of CLI"
diff --git a/TestON/tests/HA/dependencies/HA.py b/TestON/tests/HA/dependencies/HA.py
index 4a22dc4..d44f636 100644
--- a/TestON/tests/HA/dependencies/HA.py
+++ b/TestON/tests/HA/dependencies/HA.py
@@ -604,7 +604,7 @@
         # install onos-app-fwd
         main.step( "Install reactive forwarding app" )
         onosCli = main.Cluster.next()
-        installResults = onosCli.activateApp( "org.onosproject.fwd" )
+        installResults = onosCli.CLI.activateApp( "org.onosproject.fwd" )
         utilities.assert_equals( expect=main.TRUE, actual=installResults,
                                  onpass="Install fwd successful",
                                  onfail="Install fwd failed" )
@@ -641,7 +641,7 @@
         time.sleep( 11 )
         # uninstall onos-app-fwd
         main.step( "Uninstall reactive forwarding app" )
-        uninstallResult = onosCli.deactivateApp( "org.onosproject.fwd" )
+        uninstallResult = onosCli.CLI.deactivateApp( "org.onosproject.fwd" )
         utilities.assert_equals( expect=main.TRUE, actual=uninstallResult,
                                  onpass="Uninstall fwd successful",
                                  onfail="Uninstall fwd failed" )
@@ -686,7 +686,7 @@
             else:
                 main.log.error( "Error, getHost() failed for h" + str( i ) +
                                 " and/or h" + str( i + 10 ) )
-                hosts = main.Cluster.next().hosts()
+                hosts = main.Cluster.next().CLI.hosts()
                 try:
                     output = json.dumps( json.loads( hosts ),
                                          sort_keys=True,
@@ -714,7 +714,7 @@
         else:
             intentStop = None
         # Print the intent states
-        intents = onosCli.intents()
+        intents = onosCli.CLI.intents()
         intentStates = []
         installedCheck = True
         main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
@@ -762,7 +762,7 @@
                     correct = False
                     break
                 else:
-                    intents = json.loads( ctrl.intents() )
+                    intents = json.loads( ctrl.CLI.intents() )
                     for intent in intents:
                         if intent[ 'state' ] != "INSTALLED":
                             main.log.warn( "Intent " + intent[ 'id' ] +
@@ -812,7 +812,7 @@
             main.log.info( "Submitted intents: " + str( intentIds ) )
             main.log.info( "Intents in ONOS: " + str( onosIds ) )
             # Print the intent states
-            intents = onosCli.intents()
+            intents = onosCli.CLI.intents()
             intentStates = []
             main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
             count = 0
@@ -860,7 +860,7 @@
         while not installedCheck and loopCount < 40:
             installedCheck = True
             # Print the intent states
-            intents = onosCli.intents()
+            intents = onosCli.CLI.intents()
             intentStates = []
             main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
             count = 0
@@ -905,7 +905,7 @@
                 "Intents have not been installed correctly, pings failed." )
             # TODO: pretty print
             try:
-                tmpIntents = onosCli.intents()
+                tmpIntents = onosCli.CLI.intents()
                 output = json.dumps( json.loads( tmpIntents ),
                                      sort_keys=True,
                                      indent=4,
@@ -932,7 +932,7 @@
                            "intents change" )
             time.sleep( 60 )
             # Print the intent states
-            intents = onosCli.intents()
+            intents = onosCli.CLI.intents()
             intentStates = []
             main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
             count = 0
@@ -954,7 +954,7 @@
         self.commonChecks()
 
         # Print flowrules
-        main.log.debug( onosCli.flows() )
+        main.log.debug( onosCli.CLI.flows() )
         main.step( "Wait a minute then ping again" )
         # the wait is above
         PingResult = main.TRUE
@@ -974,7 +974,7 @@
             # TODO: pretty print
             main.log.warn( str( onosCli.name ) + " intents: " )
             try:
-                tmpIntents = onosCli.intents()
+                tmpIntents = onosCli.CLI.intents()
                 main.log.warn( json.dumps( json.loads( tmpIntents ),
                                            sort_keys=True,
                                            indent=4,
@@ -3510,7 +3510,7 @@
         main.case( "Start Leadership Election app" )
         main.step( "Install leadership election app" )
         onosCli = main.Cluster.next()
-        appResult = onosCli.activateApp( "org.onosproject.election" )
+        appResult = onosCli.CLI.activateApp( "org.onosproject.election" )
         utilities.assert_equals(
             expect=main.TRUE,
             actual=appResult,
@@ -3727,7 +3727,7 @@
         main.case( description )
         main.step( "Install Primitives app" )
         appName = "org.onosproject.distributedprimitives"
-        appResults = main.Cluster.next().activateApp( appName )
+        appResults = main.Cluster.next().CLI.activateApp( appName )
         utilities.assert_equals( expect=main.TRUE,
                                  actual=appResults,
                                  onpass="Primitives app activated",
diff --git a/TestON/tests/dependencies/Cluster.py b/TestON/tests/dependencies/Cluster.py
index 36811ba..825f368 100644
--- a/TestON/tests/dependencies/Cluster.py
+++ b/TestON/tests/dependencies/Cluster.py
@@ -151,7 +151,7 @@
         """
         self.iterator = iter( self.active() )
 
-    def createCell( self, cellName, Mininet, useSSH, ips ):
+    def createCell( self, cellName, Mininet, useSSH, ips, installMax=False ):
         """
         Description:
             create a new cell
@@ -162,15 +162,17 @@
             * ips - ip(s) of the node(s).
         Returns:
         """
-        main.ONOSbench.createCellFile( main.ONOSbench.ip_address,
-                                       cellName,
-                                       Mininet if isinstance( Mininet, str ) else
-                                       Mininet.ip_address,
-                                       main.apps,
-                                       ips,
-                                       main.ONOScell.karafUser,
-                                       useSSH=useSSH )
-
+        self.command( "createCellFile",
+                      args=[ main.ONOSbench.ip_address,
+                            cellName,
+                            Mininet if isinstance(Mininet, str) else
+                            Mininet.ip_address,
+                            main.apps,
+                            ips,
+                            main.ONOScell.karafUser,
+                            useSSH ],
+                      specificDriver=1,
+                      getFrom=0 if installMax else 1 )
     def uninstall( self, uninstallMax ):
         """
         Description:
@@ -187,7 +189,7 @@
                                   main.ONOSbench.onosUninstall( nodeIp=ctrl.ipAddress )
         return onosUninstallResult
 
-    def applyCell( self, cellName ):
+    def applyCell( self, cellName, installMax=False ):
         """
         Description:
             apply the cell with cellName. It will also verify the
@@ -197,9 +199,18 @@
         Returns:
             Returns main.TRUE if it successfully set and verify cell.
         """
-        cellResult = main.ONOSbench.setCell( cellName )
-        verifyResult = main.ONOSbench.verifyCell()
-        return cellResult and verifyResult
+
+        setCellResult = self.command( "setCell",
+                      args=[ cellName ],
+                      specificDriver=1,
+                      getFrom=0 if installMax else 1 )
+        verifyResult = self.command( "verifyCell",
+                      specificDriver=1,
+                      getFrom=0 if installMax else 1 )
+        result = main.TRUE
+        for i in range( len( setCellResult ) ):
+            result = result and setCellResult[ i ] and verifyResult[ i ]
+        return result
 
     def checkService( self ):
         """
@@ -263,7 +274,7 @@
             secureSshResult = secureSshResult and main.ONOSbench.onosSecureSSH( node=ctrl.ipAddress )
         return secureSshResult
 
-    def install( self, installMax=True ):
+    def install( self, installMax=True, installParallel=True ):
         """
         Description:
             Installing onos.
@@ -280,9 +291,20 @@
             options = "-f"
             if installMax and i >= self.numCtrls:
                 options = "-nf"
-            result = result and \
+            if installParallel:
+                t= main.Thread( target=ctrl.Bench.onosInstall,
+                                 name="install-" + ctrl.name,
+                                 kwargs={ "node" : ctrl.ipAddress,
+                                          "options" : options } )
+                threads.append( t )
+                t.start()
+            else:
+                result = result and \
                             main.ONOSbench.onosInstall( node=ctrl.ipAddress, options=options )
-
+        if installParallel:
+            for t in threads:
+                t.join()
+                result = result and t.result
         return result
 
     def startCLIs( self ):
@@ -365,7 +387,8 @@
         resultOne = results[ 0 ]
         return all( resultOne == result for result in results )
 
-    def command( self, function, args=(), kwargs={}, returnBool=False, specificDriver=0, contentCheck=False ):
+    def command( self, function, args=(), kwargs={}, returnBool=False,
+                 specificDriver=0, contentCheck=False, getFrom=2 ):
         """
         Description:
             execute some function of the active nodes.
@@ -383,23 +406,20 @@
                 3 - from rest
             * contentCheck - If this is True, it will check if the result has some
             contents.
+            * getFrom - from which nodes
+                2 - active nodes
+                1 - current running nodes
+                0 - all nodes
         Returns:
             Returns results if not returnBool and not contentCheck
             Returns checkTruthValue of the result if returnBool
             Returns resultContent of the result if contentCheck
         """
-        """
-        Send a command to all ONOS nodes and return the results as a list
-        specificDriver:
-            0 - any type of driver
-            1 - from bench
-            2 - from cli
-            3 - from rest
-        """
         threads = []
         drivers = [ None, "Bench", "CLI", "REST" ]
+        fromNode = [ self.controllers, self.runningNodes, self.active() ]
         results = []
-        for ctrl in self.active():
+        for ctrl in fromNode[ getFrom ]:
             try:
                 f = getattr( ( ctrl if not specificDriver else
                              getattr( ctrl, drivers[ specificDriver ] ) ), function )
@@ -418,7 +438,7 @@
             t.join()
             results.append( t.result )
         if returnBool:
-            return self.allTrueResultCheck( results, self.active() )
+            return self.allTrueResultCheck( results, fromNode[ getFrom ] )
         elif contentCheck:
-            return self.notEmptyResultCheck( results, self.active() )
+            return self.notEmptyResultCheck( results, fromNode[ getFrom ] )
         return results
\ No newline at end of file
diff --git a/TestON/tests/dependencies/ONOSSetup.py b/TestON/tests/dependencies/ONOSSetup.py
index 81a1b25..4cfd694 100644
--- a/TestON/tests/dependencies/ONOSSetup.py
+++ b/TestON/tests/dependencies/ONOSSetup.py
@@ -159,7 +159,8 @@
 
         return cluster.kill( killRemoveMax, stopOnos )
 
-    def createApplyCell( self, cluster, newCell, cellName, Mininet, useSSH, ips ):
+    def createApplyCell( self, cluster, newCell, cellName,
+                         Mininet, useSSH, ips, installMax=False ):
         """
         Description:
             create new cell ( optional ) and apply it. It will also verify the
@@ -221,7 +222,7 @@
                                  onfail="Failed to create ONOS package" )
         return packageResult
 
-    def installOnos( self, cluster, installMax ):
+    def installOnos( self, cluster, installMax, parallel=True ):
         """
         Description:
             Installing onos and verify the result
@@ -235,7 +236,7 @@
         main.step( "Installing ONOS package" )
         onosInstallResult = main.TRUE
 
-        cluster.install( installMax )
+        cluster.install( installMax, parallel )
         utilities.assert_equals( expect=main.TRUE,
                                  actual=onosInstallResult,
                                  onpass="Successfully installed ONOS package",
@@ -305,7 +306,7 @@
     def ONOSSetUp( self, Mininet, cluster, hasMultiNodeRounds=False, startOnos=True, newCell=True,
                    cellName="temp", removeLog=False, extraApply=None, arg=None, extraClean=None,
                    skipPack=False, installMax=False, useSSH=True, killRemoveMax=True,
-                   stopOnos=False ):
+                   stopOnos=False, installParallel=True ):
         """
         Description:
             Initial ONOS setting up of the tests. It will also verify the result of each steps.
@@ -361,7 +362,8 @@
                 tempOnosIp.append( ctrl.ipAddress )
             cellResult = self.createApplyCell( cluster, newCell,
                                                cellName, Mininet,
-                                               useSSH, tempOnosIp )
+                                               useSSH, tempOnosIp,
+                                               installMax )
             if removeLog:
                 main.log.info("Removing raft logs")
                 main.ONOSbench.onosRemoveRaftLogs()
@@ -381,7 +383,7 @@
 
             packageResult = self.buildOnos( cluster )
 
-        onosInstallResult = self.installOnos( cluster, installMax )
+        onosInstallResult = self.installOnos( cluster, installMax, installParallel )
 
         if extraClean is not None:
             extraClean()
@@ -393,4 +395,4 @@
             onosCliResult = self.startOnosClis( cluster )
 
         return killResult and cellResult and packageResult and onosUninstallResult and \
-               onosInstallResult and secureSshResult and onosServiceResult and onosCliResult
+               onosInstallResult and secureSshResult and onosServiceResult and onosCliResult
\ No newline at end of file