Changed copyMininetFile of onosdriver to scp function in clidriver

Change-Id: I52a11e7f97e727777e3ea891b453d4741fc32d1e
diff --git a/TestON/tests/SAMPscaleTopo/SAMPscaleTopo.py b/TestON/tests/SAMPscaleTopo/SAMPscaleTopo.py
index 9a77f64..5801fcd 100644
--- a/TestON/tests/SAMPscaleTopo/SAMPscaleTopo.py
+++ b/TestON/tests/SAMPscaleTopo/SAMPscaleTopo.py
@@ -27,52 +27,76 @@
         main.step( "Constructing test variables" )
         stepResult = main.FALSE
 
-        # Test variables
-        main.testOnDirectory = re.sub( "(/tests)$", "", main.testDir )
-        main.apps = main.params[ 'ENV' ][ 'cellApps' ]
-        gitBranch = main.params[ 'GIT' ][ 'branch' ]
-        main.dependencyPath = main.testOnDirectory + \
-                              main.params[ 'DEPENDENCY' ][ 'path' ]
-        main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ]
-        main.scale = ( main.params[ 'SCALE' ][ 'size' ] ).split( "," )
-        main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] )
-        main.ONOSport = main.params[ 'CTRL' ][ 'port' ]
-        wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
-        wrapperFile2 = main.params[ 'DEPENDENCY' ][ 'wrapper2' ]
-        main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
-        main.fwdSleep = int( main.params[ 'SLEEP' ][ 'fwd' ] )
-        gitPull = main.params[ 'GIT' ][ 'pull' ]
-        main.cellData = {} # for creating cell file
-        main.hostsData = {}
-        main.CLIs = []
-        main.ONOSip = []
+        try:
+            main.testOnDirectory = os.path.dirname( os.getcwd ( ) )
+            main.apps = main.params[ 'ENV' ][ 'cellApps' ]
+            gitBranch = main.params[ 'GIT' ][ 'branch' ]
+            main.dependencyPath = main.testOnDirectory + \
+                                  main.params[ 'DEPENDENCY' ][ 'path' ]
+            main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ]
+            main.multiovs = main.params[ 'DEPENDENCY' ][ 'multiovs' ]
+            main.scale = ( main.params[ 'SCALE' ][ 'size' ] ).split( "," )
+            if main.ONOSbench.maxNodes:
+                main.maxNodes = int( main.ONOSbench.maxNodes )
+            else:
+                main.maxNodes = 0
+            wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
+            wrapperFile2 = main.params[ 'DEPENDENCY' ][ 'wrapper2' ]
+            wrapperFile3 = main.params[ 'DEPENDENCY' ][ 'wrapper3' ]
+            main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
+            main.fwdSleep = int( main.params[ 'SLEEP' ][ 'fwd' ] )
+            gitPull = main.params[ 'GIT' ][ 'pull' ]
+            main.cellData = {} # for creating cell file
+            main.hostsData = {}
+            main.CLIs = []
+            main.ONOSip = []
 
-        main.ONOSip = main.ONOSbench.getOnosIps()
-        print main.ONOSip
+            main.ONOSip = main.ONOSbench.getOnosIps()
+            print main.ONOSip
 
-        # Assigning ONOS cli handles to a list
-        for i in range( 1,  main.maxNodes + 1 ):
-            main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
+            # Assigning ONOS cli handles to a list
+            for i in range( 1,  main.maxNodes + 1 ):
+                main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
 
-        # -- INIT SECTION, ONLY RUNS ONCE -- #
-        main.startUp = imp.load_source( wrapperFile1,
-                                        main.dependencyPath +
-                                        wrapperFile1 +
-                                        ".py" )
-        main.scaleTopoFunction = imp.load_source( wrapperFile2,
-                                                  main.dependencyPath +
-                                                  wrapperFile2 +
-                                                  ".py" )
+            # -- INIT SECTION, ONLY RUNS ONCE -- #
+            main.startUp = imp.load_source( wrapperFile1,
+                                            main.dependencyPath +
+                                            wrapperFile1 +
+                                            ".py" )
 
-        copyResult = main.ONOSbench.copyMininetFile( main.topology,
-                                                     main.dependencyPath,
-                                                     main.Mininet1.user_name,
-                                                     main.Mininet1.ip_address )
-        if main.CLIs:
-            stepResult = main.TRUE
-        else:
-            main.log.error( "Did not properly created list of ONOS CLI handle" )
-            stepResult = main.FALSE
+            main.scaleTopoFunction = imp.load_source( wrapperFile2,
+                                                   main.dependencyPath +
+                                                   wrapperFile2 +
+                                                   ".py" )
+
+            main.topo = imp.load_source( wrapperFile3,
+                                         main.dependencyPath +
+                                         wrapperFile3 +
+                                         ".py" )
+
+            copyResult1 = main.ONOSbench.scp( main.Mininet1,
+                                              main.dependencyPath +
+                                              main.topology,
+                                              main.Mininet1.home,
+                                              direction="to" )
+
+            copyResult2 = main.ONOSbench.scp( main.Mininet1,
+                                              main.dependencyPath +
+                                              main.multiovs,
+                                              main.Mininet1.home,
+                                              direction="to" )
+
+            if main.CLIs:
+                stepResult = main.TRUE
+            else:
+                main.log.error( "Did not properly created list of " +
+                                "ONOS CLI handle" )
+                stepResult = main.FALSE
+
+        except Exception as e:
+            main.log.exception(e)
+            main.cleanup()
+            main.exit()
 
         utilities.assert_equals( expect=main.TRUE,
                                  actual=stepResult,
@@ -93,6 +117,20 @@
         else:
             main.log.warn( "Did not pull new code so skipping mvn " +
                            "clean install" )
+        main.ONOSbench.getVersion( report=True )
+        if gitPull == 'True':
+            main.step( "Building ONOS in " + gitBranch + " branch" )
+            onosBuildResult = main.startUp.onosBuild( main, gitBranch )
+            stepResult = onosBuildResult
+            utilities.assert_equals( expect=main.TRUE,
+                                     actual=stepResult,
+                                     onpass="Successfully compiled " +
+                                            "latest ONOS",
+                                     onfail="Failed to compile " +
+                                            "latest ONOS" )
+        else:
+            main.log.warn( "Did not pull new code so skipping mvn " +
+                           "clean install" )
 
     def CASE2( self, main ):
         """
@@ -153,6 +191,77 @@
         # Remove the first element in main.scale list
         main.scale.remove( main.scale[ 0 ] )
 
+    def CASE8( self, main ):
+        """
+        Compare Topo
+        """
+        import json
+
+        main.case( "Compare ONOS Topology view to Mininet topology" )
+        main.caseExplanation = "Compare topology elements between Mininet" +\
+                                " and ONOS"
+
+        main.step( "Gathering topology information" )
+        # TODO: add a paramaterized sleep here
+        devicesResults = main.TRUE
+        linksResults = main.TRUE
+        hostsResults = main.TRUE
+        devices = main.topo.getAllDevices( main )
+        hosts = main.topo.getAllHosts( main )
+        ports = main.topo.getAllPorts( main )
+        links = main.topo.getAllLinks( main )
+        clusters = main.topo.getAllClusters( main )
+
+        mnSwitches = main.Mininet1.getSwitches()
+        mnLinks = main.Mininet1.getLinks()
+        mnHosts = main.Mininet1.getHosts()
+
+        main.step( "Conmparing MN topology to ONOS topology" )
+        for controller in range( main.numCtrls ):
+            controllerStr = str( controller + 1 )
+            if devices[ controller ] and ports[ controller ] and\
+                "Error" not in devices[ controller ] and\
+                "Error" not in ports[ controller ]:
+
+                currentDevicesResult = main.Mininet1.compareSwitches(
+                        mnSwitches,
+                        json.loads( devices[ controller ] ),
+                        json.loads( ports[ controller ] ) )
+            else:
+                currentDevicesResult = main.FALSE
+            utilities.assert_equals( expect=main.TRUE,
+                                     actual=currentDevicesResult,
+                                     onpass="ONOS" + controllerStr +
+                                     " Switches view is correct",
+                                     onfail="ONOS" + controllerStr +
+                                     " Switches view is incorrect" )
+
+            if links[ controller ] and "Error" not in links[ controller ]:
+                currentLinksResult = main.Mininet1.compareLinks(
+                        mnSwitches, mnLinks,
+                        json.loads( links[ controller ] ) )
+            else:
+                currentLinksResult = main.FALSE
+            utilities.assert_equals( expect=main.TRUE,
+                                     actual=currentLinksResult,
+                                     onpass="ONOS" + controllerStr +
+                                     " links view is correct",
+                                     onfail="ONOS" + controllerStr +
+                                     " links view is incorrect" )
+
+            if hosts[ controller ] or "Error" not in hosts[ controller ]:
+                currentHostsResult = main.Mininet1.compareHosts(
+                        mnHosts,
+                        json.loads( hosts[ controller ] ) )
+            else:
+                currentHostsResult = main.FALSE
+            utilities.assert_equals( expect=main.TRUE,
+                                     actual=currentHostsResult,
+                                     onpass="ONOS" + controllerStr +
+                                     " hosts exist in Mininet",
+                                     onfail="ONOS" + controllerStr +
+                                     " hosts don't match Mininet" )
+
     def CASE9( self, main ):
         '''
             Report errors/warnings/exceptions
@@ -188,30 +297,56 @@
 
     def CASE1001( self, main ):
         """
-            Test topology discovery
+            Topology test
         """
-        main.case( "Topology discovery test" )
+        import time
+        main.topoName = "SPINE"
+        main.case( "Spine topology test" )
+        main.step( main.topoName + " topology" )
+        mnCmd = "sudo mn --custom " + main.dependencyPath +\
+                main.multiovs + " --switch=ovsm --custom " +\
+                main.dependencyPath + main.topology +\
+                " --topo spine,3,6 --controller=remote,ip=" +\
+                main.ONOSip[ 0 ] + " --mac"
 
-
-        main.step( "Torus 5-5 topology" )
-        main.topoName = "TORUS5-5"
-        mnCmd = "mn --topo=torus,5,5 --mac"
         stepResult = main.scaleTopoFunction.testTopology( main,
                                                           mnCmd=mnCmd,
+                                                          timeout=900,
                                                           clean=False )
+
+        main.ONOSbench.scp( main.Mininet1,
+                            "~/mininet/custom/spine.json",
+                            "/tmp/",
+                            direction="to" )
+
+        time.sleep(10)
+
+        main.ONOSbench.onosTopoCfg( main.ONOSip[ 0 ],
+                                    main.dependencyPath + 'spine.json' )
+
         utilities.assert_equals( expect=main.TRUE,
                                  actual=stepResult,
-                                 onpass="Torus 5-5 topology successful",
-                                 onfail="Torus 5-5 topology failed" )
+                                 onpass=main.topoName + " topology successful",
+                                 onfail=main.topoName +
+                                 "Torus 5-5 topology failed" )
+        time.sleep(60)
 
-        main.topoName = "TREE3-3"
+    def CASE1002( self, main ):
+        """
+            Topology test
+        """
+        main.topoName = "TORUS10-10"
+        main.case( "Topology discovery test" )
         stepResult = main.TRUE
-        main.step( "Tree 3-3 topology" )
-        mnCmd = "mn --topo=tree,3,3 --mac"
+        main.step( main.topoName + " topology" )
+        mnCmd = "sudo mn --custom=mininet/examples/multiovs.py " +\
+                "--switch=ovsm --topo=torus,10,10 " +\
+                "--controller=remote,ip=10.128.10.21 --mac"
         stepResult = main.scaleTopoFunction.testTopology( main,
                                                           mnCmd=mnCmd,
+                                                          timeout=900,
                                                           clean=True )
         utilities.assert_equals( expect=main.TRUE,
                                  actual=stepResult,
-                                 onpass="Tree 3-3 topology successful",
-                                 onfail="Tree 3-3 topology failed" )
+                                 onpass=main.topoName + " topology successful",
+                                 onfail=main.topoName + "Torus 5-5 topology failed" )