Refactored SAMPstartTemplate initial commit

Change-Id: I399aa1077d47b1f73c33624c88ecd36419060eb4

Changed connect function in the driver

Change-Id: If222a66b4ef403a5bc7690ab60994709e4e8c123
diff --git a/TestON/core/teston.py b/TestON/core/teston.py
index 7e99ffd..aeb944c 100644
--- a/TestON/core/teston.py
+++ b/TestON/core/teston.py
@@ -165,21 +165,6 @@
         driverClass = getattr(driverModule, driverName)
         driverObject = driverClass()
 
-        if "OC" in self.componentDictionary[component]['host']:
-            try:
-                self.componentDictionary[component]['host'] = os.environ[str( self.componentDictionary[component]['host'])]
-            except KeyError:
-                self.log.info("Missing OC environment variable! Using stored IPs")
-                f = open("myIps","r")
-                ips = f.readlines()
-                for line in ips: 
-                    if self.componentDictionary[component]['host'] in line: 
-                        line = line.split("=")
-                        myIp = line[1]
-                self.componentDictionary[component]['host'] = myIp
-            except Exception as inst:
-                self.log.error("Uncaught exception: " + str(inst))
-
         connect_result = driverObject.connect(user_name = self.componentDictionary[component]['user'] if ('user' in self.componentDictionary[component].keys()) else getpass.getuser(),
                                               ip_address= self.componentDictionary[component]['host'] if ('host' in self.componentDictionary[component].keys()) else 'localhost',
                                               pwd = self.componentDictionary[component]['password'] if ('password' in self.componentDictionary[component].keys()) else 'changeme',
diff --git a/TestON/drivers/common/cli/emulator/mininetclidriver.py b/TestON/drivers/common/cli/emulator/mininetclidriver.py
index bdc9307..b877d93 100644
--- a/TestON/drivers/common/cli/emulator/mininetclidriver.py
+++ b/TestON/drivers/common/cli/emulator/mininetclidriver.py
@@ -35,6 +35,7 @@
 import re
 import sys
 import types
+import os
 sys.path.append( "../" )
 from math import pow
 from drivers.common.cli.emulatordriver import Emulator
@@ -61,6 +62,22 @@
                 vars( self )[ key ] = connectargs[ key ]
 
             self.name = self.options[ 'name' ]
+
+            try:
+                if os.getenv( str( self.ip_address ) ) != None:
+                    self.ip_address = os.getenv( str( self.ip_address ) )
+                else:
+                    main.log.info( self.name +
+                                   ": Trying to connect to " +
+                                   self.ip_address )
+
+            except KeyError:
+                main.log.info( "Invalid host name," +
+                               " connecting to local host instead" )
+                self.ip_address = 'localhost'
+            except Exception as inst:
+                main.log.error( "Uncaught exception: " + str( inst ) )
+
             self.handle = super(
                 MininetCliDriver,
                 self ).connect(
diff --git a/TestON/drivers/common/cli/emulator/remotemininetdriver.py b/TestON/drivers/common/cli/emulator/remotemininetdriver.py
index c2c011a..cea3eab 100644
--- a/TestON/drivers/common/cli/emulator/remotemininetdriver.py
+++ b/TestON/drivers/common/cli/emulator/remotemininetdriver.py
@@ -24,6 +24,7 @@
 import pexpect
 import re
 import sys
+import os
 sys.path.append( "../" )
 from drivers.common.cli.emulatordriver import Emulator
 
@@ -51,6 +52,22 @@
             vars( self )[ key ] = connectargs[ key ]
 
         self.name = self.options[ 'name' ]
+
+        try:
+            if os.getenv( str( self.ip_address ) ) != None:
+                self.ip_address = os.getenv( str( self.ip_address ) )
+            else:
+                main.log.info( self.name +
+                               ": Trying to connect to " +
+                               self.ip_address )
+
+        except KeyError:
+            main.log.info( "Invalid host name," +
+                           " connecting to local host instead" )
+            self.ip_address = 'localhost'
+        except Exception as inst:
+            main.log.error( "Uncaught exception: " + str( inst ) )
+
         self.handle = super(
             RemoteMininetDriver,
             self ).connect(
diff --git a/TestON/drivers/common/cli/onosclidriver.py b/TestON/drivers/common/cli/onosclidriver.py
index fca8f22..870293d 100644
--- a/TestON/drivers/common/cli/onosclidriver.py
+++ b/TestON/drivers/common/cli/onosclidriver.py
@@ -22,6 +22,7 @@
 import json
 import types
 import time
+import os
 sys.path.append( "../" )
 from drivers.common.clidriver import CLI
 
@@ -52,7 +53,28 @@
             if self.home is None or self.home == "":
                 self.home = "~/onos"
 
+            for key in self.options:
+                if key == 'onosIp':
+                    self.onosIp = self.options[ 'onosIp' ]
+                    break
+
             self.name = self.options[ 'name' ]
+
+            try:
+                if os.getenv( str( self.ip_address ) ) != None:
+                    self.ip_address = os.getenv( str( self.ip_address ) )
+                else:
+                    main.log.info( self.name +
+                                   ": Trying to connect to " +
+                                   self.ip_address )
+
+            except KeyError:
+                main.log.info( "Invalid host name," +
+                               " connecting to local host instead" )
+                self.ip_address = 'localhost'
+            except Exception as inst:
+                main.log.error( "Uncaught exception: " + str( inst ) )
+
             self.handle = super( OnosCliDriver, self ).connect(
                 user_name=self.user_name,
                 ip_address=self.ip_address,
diff --git a/TestON/drivers/common/cli/onosdriver.py b/TestON/drivers/common/cli/onosdriver.py
index 4c786a3..cbe291b 100644
--- a/TestON/drivers/common/cli/onosdriver.py
+++ b/TestON/drivers/common/cli/onosdriver.py
@@ -19,6 +19,7 @@
 import sys
 import time
 import pexpect
+import os
 import os.path
 from requests.models import Response
 sys.path.append( "../" )
@@ -39,6 +40,10 @@
     def connect( self, **connectargs ):
         """
         Creates ssh handle for ONOS "bench".
+        NOTE:
+        The ip_address would come from the topo file using the host tag, the
+        value can be an environment variable as well as a "localhost" to get
+        the ip address needed to ssh to the "bench"
         """
         try:
             for key in connectargs:
@@ -52,6 +57,57 @@
                 self.home = "~/onos"
 
             self.name = self.options[ 'name' ]
+
+            for key in self.options:
+                if key == "nodes":
+                    # Maximum number of ONOS nodes to run
+                    self.maxNodes = int( self.options[ 'nodes' ] )
+                    break
+                self.maxNodes = None
+
+
+            # Grabs all OC environment variables
+            self.onosIps = {}  # Dictionary of all possible ONOS ip
+
+            try:
+                if self.maxNodes:
+                    main.log.info( self.name + ": Creating cluster data with " +
+                                   str( self.maxNodes ) + " maximum number" +
+                                   " of nodes" )
+
+                    for i in range( self.maxNodes ):
+                        envString = "OC" + str( i + 1 )
+                        self.onosIps[ envString ] = os.getenv( envString )
+
+                    if not self.onosIps:
+                        main.log.info( "Could not read any environment variable"
+                                       + " please load a cell file with all" +
+                                        " onos IP" )
+                    else:
+                        main.log.info( self.name + ": Found " +
+                                       str( self.onosIps.values() ) +
+                                       " ONOS IPs" )
+
+            except KeyError:
+                main.log.info( "Invalid environment variable" )
+            except Exception as inst:
+                main.log.error( "Uncaught exception: " + str( inst ) )
+
+            try:
+                if os.getenv( str( self.ip_address ) ) != None:
+                    self.ip_address = os.getenv( str( self.ip_address ) )
+                else:
+                    main.log.info( self.name +
+                                   ": Trying to connect to " +
+                                   self.ip_address )
+
+            except KeyError:
+                main.log.info( "Invalid host name," +
+                               " connecting to local host instead" )
+                self.ip_address = 'localhost'
+            except Exception as inst:
+                main.log.error( "Uncaught exception: " + str( inst ) )
+
             self.handle = super( OnosDriver, self ).connect(
                 user_name=self.user_name,
                 ip_address=self.ip_address,
@@ -61,11 +117,13 @@
 
             self.handle.sendline( "cd " + self.home )
             self.handle.expect( "\$" )
+
             if self.handle:
                 return self.handle
             else:
                 main.log.info( "NO ONOS HANDLE" )
                 return main.FALSE
+
         except pexpect.EOF:
             main.log.error( self.name + ": EOF exception found" )
             main.log.error( self.name + ":     " + self.handle.before )
@@ -587,7 +645,7 @@
             main.exit()
 
     def createCellFile( self, benchIp, fileName, mnIpAddrs,
-                        appString, *onosIpAddrs ):
+                        appString, onosIpAddrs ):
         """
         Creates a cell file based on arguments
         Required:
@@ -623,7 +681,7 @@
         tempCount = 1
 
         # Create ONOSNIC ip address prefix
-        tempOnosIp = onosIpAddrs[ 0 ]
+        tempOnosIp = str( onosIpAddrs[ 0 ] )
         tempList = []
         tempList = tempOnosIp.split( "." )
         # Omit last element of list to format for NIC
@@ -1979,102 +2037,14 @@
             main.cleanup()
             main.exit()
 
-    def getOnosIps(self):
+    def getOnosIps( self ):
+        """
+            Get all onos IPs stored in
+        """
 
-        import os
-        
-        # reads env for OC variables, also saves file with OC variables. If file and env conflict 
-        # priority goes to env. If file has OCs that are not in the env, the file OCs are used. 
-        # In other words, if the env is set, the test will use those values. 
+        return sorted( self.onosIps.values() )
 
-        # returns a list of ip addresses for the onos nodes, will work with up to 7 nodes + OCN and OCI
-        # returns in format [ OC1 ip, OC2 ...ect. , OCN, OCI ]
-
-        envONOSIps = {}
-
-        x = 1
-        while True:
-            try:
-                temp = os.environ[ 'OC' + str(x) ]
-            except KeyError: 
-                break
-            envONOSIps[ ("OC" + str(x)) ] = temp 
-            x += 1 
-
-        try: 
-            temp = os.environ[ 'OCN' ] 
-            envONOSIps[ "OCN" ] = temp
-        except KeyError: 
-            main.log.info("OCN not set in env")
-
-        try:
-            temp = os.environ[ 'OCI' ]
-            envONOSIps[ "OCI" ] = temp
-        except:
-            main.log.error("OCI not set in env")
-
-        print(str(envONOSIps))
-
-        order = [ "OC1", "OC2", "OC3","OC4","OC5","OC6","OC7","OCN","OCI" ]
-        ONOSIps = []
-
-        try: 
-            if os.path.exists("myIps"):
-                ipFile = open("myIps","r+")
-            else: 
-                ipFile = open("myIps","w+")
-
-            fileONOSIps = ipFile.readlines()
-            ipFile.close()
-
-            print str(fileONOSIps)
-            
-            if str(fileONOSIps) == "[]": 
-                ipFile = open("myIps","w+")
-                for key in envONOSIps:
-                    ipFile.write(key+ "=" + envONOSIps[key] + "\n")
-                ipFile.close()
-                for i in order: 
-                    if i in envONOSIps: 
-                        ONOSIps.append(envONOSIps[i])
-                
-                return ONOSIps 
-
-            else: 
-                fileDict = {}
-                for line in fileONOSIps: 
-                    line = line.replace("\n","")
-                    line = line.split("=") 
-                    key = line[0]
-                    value = line[1]
-                    fileDict[key] = value 
-
-                for x in envONOSIps: 
-                    if x in fileDict: 
-                        if envONOSIps[x] == fileDict[x]: 
-                            continue
-                        else: 
-                            fileDict[x] = envONOSIps[x]
-                    else: 
-                        fileDict[x] = envONOSIps[x]
-
-                ipFile = open("myIps","w+")
-                for key in order: 
-                    if key in fileDict: 
-                        ipFile.write(key + "=" + fileDict[key] + "\n")
-                        ONOSIps.append(fileDict[key]) 
-                ipFile.close()
-
-                return ONOSIps 
-
-        except IOError as a:
-            main.log.error(a) 
-
-        except Exception as a:
-            main.log.error(a) 
-
-
-    def logReport(self, nodeIp, searchTerms, outputMode="s"):
+    def logReport( self, nodeIp, searchTerms, outputMode="s" ):
         '''
             - accepts either a list or a string for "searchTerms" these
               terms will be searched for in the log and have their 
diff --git a/TestON/tests/SAMPstartTemplate/Dependency/newFuncTopo.py b/TestON/tests/SAMPstartTemplate/Dependency/newFuncTopo.py
new file mode 100755
index 0000000..57ad42f
--- /dev/null
+++ b/TestON/tests/SAMPstartTemplate/Dependency/newFuncTopo.py
@@ -0,0 +1,152 @@
+#!/usr/bin/python
+
+"""
+Custom topology for Mininet
+"""
+from mininet.topo import Topo
+from mininet.net import Mininet
+from mininet.node import Host, RemoteController
+from mininet.node import Node
+from mininet.node import CPULimitedHost
+from mininet.link import TCLink
+from mininet.cli import CLI
+from mininet.log import setLogLevel
+from mininet.util import dumpNodeConnections
+from mininet.node import ( UserSwitch, OVSSwitch, IVSSwitch )
+
+class VLANHost( Host ):
+    def config( self, vlan=100, **params ):
+		r = super( Host, self ).config( **params )
+		intf = self.defaultIntf()
+		self.cmd( 'ifconfig %s inet 0' % intf )
+		self.cmd( 'vconfig add %s %d' % ( intf, vlan ) )
+		self.cmd( 'ifconfig %s.%d inet %s' % ( intf, vlan, params['ip'] ) )
+		newName = '%s.%d' % ( intf, vlan )
+		intf.name = newName
+		self.nameToIntf[ newName ] = intf
+		return r
+
+class IPv6Host( Host ):
+    def config( self, v6Addr='1000:1/64', **params ):
+		r = super( Host, self ).config( **params )
+		intf = self.defaultIntf()
+		self.cmd( 'ifconfig %s inet 0' % intf )
+		self.cmd( 'ip -6 addr add %s dev %s' % ( v6Addr, intf ) )
+		return r
+
+class dualStackHost( Host ):
+    def config( self, v6Addr='2000:1/64', **params ):
+		r = super( Host, self ).config( **params )
+		intf = self.defaultIntf()
+		self.cmd( 'ip -6 addr add %s dev %s' % ( v6Addr, intf ) )
+		return r
+
+class MyTopo( Topo ):
+
+	def __init__( self ):			 
+		# Initialize topology
+		Topo.__init__( self )
+							  
+		# Switch S5 Hosts
+		host1=self.addHost( 'h1', ip='10.1.0.2/24' )
+		host2=self.addHost( 'h2', cls=IPv6Host, v6Addr='1000::2/64' )
+		host3=self.addHost( 'h3', ip='10.1.0.3/24', cls=dualStackHost, v6Addr='2000::2/64' )
+		#VLAN hosts
+		host4=self.addHost( 'h4', ip='100.1.0.2/24', cls=VLANHost, vlan=100 )
+		host5=self.addHost( 'h5', ip='200.1.0.2/24', cls=VLANHost, vlan=200 )
+		#VPN-1 and VPN-2 Hosts
+		host6=self.addHost( 'h6', ip='11.1.0.2/24' )
+		host7=self.addHost( 'h7', ip='12.1.0.2/24' )
+		#Multicast Sender
+		host8=self.addHost( 'h8', ip='10.1.0.4/24' )
+
+		# Switch S6 Hosts
+		host9=self.addHost( 'h9', ip='10.1.0.5/24' )
+		host10=self.addHost( 'h10', cls=IPv6Host, v6Addr='1000::3/64' )
+		host11=self.addHost( 'h11', ip='10.1.0.6/24', cls=dualStackHost, v6Addr='2000::3/64' )
+		#VLAN hosts
+		host12=self.addHost( 'h12', ip='100.1.0.3/24', cls=VLANHost, vlan=100 )
+		host13=self.addHost( 'h13', ip='200.1.0.3/24', cls=VLANHost, vlan=200 )
+		#VPN-1 and VPN-2 Hosts
+		host14=self.addHost( 'h14', ip='11.1.0.3/24' )
+		host15=self.addHost( 'h15', ip='12.1.0.3/24' )
+		#Multicast Receiver
+		host16=self.addHost( 'h16', ip='10.1.0.7/24' )
+
+		# Switch S7 Hosts
+		host17=self.addHost( 'h17', ip='10.1.0.8/24' )
+		host18=self.addHost( 'h18', cls=IPv6Host, v6Addr='1000::4/64' )
+		host19=self.addHost( 'h19', ip='10.1.0.9/24', cls=dualStackHost, v6Addr='2000::4/64' )
+		#VLAN hosts
+		host20=self.addHost( 'h20', ip='100.1.0.4/24', cls=VLANHost, vlan=100 )
+		host21=self.addHost( 'h21', ip='200.1.0.4/24', cls=VLANHost, vlan=200 )
+		#VPN-1 and VPN-2 Hosts
+		host22=self.addHost( 'h22', ip='11.1.0.4/24' )
+		host23=self.addHost( 'h23', ip='12.1.0.4/24' )
+		#Multicast Receiver
+		host24=self.addHost( 'h24', ip='10.1.0.10/24' )
+
+		s1 = self.addSwitch( 's1' )
+		s2 = self.addSwitch( 's2' )
+		s3 = self.addSwitch( 's3' )
+		s4 = self.addSwitch( 's4' )
+		s5 = self.addSwitch( 's5' )
+		s6 = self.addSwitch( 's6' )
+		s7 = self.addSwitch( 's7' )
+																								    
+		self.addLink(s5,host1)
+		self.addLink(s5,host2)
+		self.addLink(s5,host3)
+		self.addLink(s5,host4)
+		self.addLink(s5,host5)
+		self.addLink(s5,host6)
+		self.addLink(s5,host7)
+		self.addLink(s5,host8)
+
+		self.addLink(s6,host9)
+		self.addLink(s6,host10)
+		self.addLink(s6,host11)
+		self.addLink(s6,host12)
+		self.addLink(s6,host13)
+		self.addLink(s6,host14)
+		self.addLink(s6,host15)
+		self.addLink(s6,host16)
+
+		self.addLink(s7,host17)
+		self.addLink(s7,host18)
+		self.addLink(s7,host19)
+		self.addLink(s7,host20)
+		self.addLink(s7,host21)
+		self.addLink(s7,host22)
+		self.addLink(s7,host23)
+		self.addLink(s7,host24)
+
+		self.addLink(s1,s2)																							 
+		self.addLink(s1,s3)
+		self.addLink(s1,s4)
+		self.addLink(s1,s5)
+		
+		self.addLink(s2,s3)
+		self.addLink(s2,s5)
+		self.addLink(s2,s6)
+
+		self.addLink(s3,s4)
+		self.addLink(s3,s6)
+		
+		self.addLink(s4,s7)
+		topos = { 'mytopo': ( lambda: MyTopo() ) }
+
+# HERE THE CODE DEFINITION OF THE TOPOLOGY ENDS
+
+def setupNetwork():
+    "Create network"
+    topo = MyTopo()
+    network = Mininet(topo=topo, autoSetMacs=True, controller=None)
+    network.start()
+    CLI( network )
+    network.stop()
+
+if __name__ == '__main__':
+    setLogLevel('info')
+    #setLogLevel('debug')
+    setupNetwork()
diff --git a/TestON/tests/SAMPstartTemplate/Dependency/startUp.py b/TestON/tests/SAMPstartTemplate/Dependency/startUp.py
new file mode 100644
index 0000000..bf2a2b6
--- /dev/null
+++ b/TestON/tests/SAMPstartTemplate/Dependency/startUp.py
@@ -0,0 +1,38 @@
+"""
+    This wrapper function is use for starting up onos instance
+"""
+
+import time
+import os
+import json
+
+def onosBuild( main, gitBranch ):
+    """
+        This includes pulling ONOS and building it using maven install
+    """
+
+    buildResult = main.FALSE
+
+    # Git checkout a branch of ONOS
+    checkOutResult = main.ONOSbench.gitCheckout( gitBranch )
+    # Does the git pull on the branch that was checked out
+    if not checkOutResult:
+        main.log.warn( "Failed to checked out " + gitBranch +
+                                           " branch")
+    else:
+        main.log.info( "Successfully checked out " + gitBranch +
+                                           " branch")
+    gitPullResult = main.ONOSbench.gitPull()
+    if gitPullResult == main.ERROR:
+        main.log.error( "Error pulling git branch" )
+    else:
+        main.log.info( "Successfully pulled " + gitBranch + " branch" )
+
+    # Maven clean install
+    buildResult = main.ONOSbench.cleanInstall()
+
+    return buildResult
+
+
+
+
diff --git a/TestON/tests/SAMPstartTemplate/SAMPstartTemplate.params b/TestON/tests/SAMPstartTemplate/SAMPstartTemplate.params
index 04f6110..1fa6036 100755
--- a/TestON/tests/SAMPstartTemplate/SAMPstartTemplate.params
+++ b/TestON/tests/SAMPstartTemplate/SAMPstartTemplate.params
@@ -1,33 +1,34 @@
 <PARAMS>
-    <testcases>10,9,10,9</testcases>
 
-    <SCALE>1,3</SCALE>
-    <availableNodes>3</availableNodes>
+    <testcases>1,2,2,2</testcases>
+
+    <SCALE>
+        <size>1,2,3</size>
+        <max>3</max>
+    </SCALE>
+
+    <DEPENDENCY>
+        <path>/tests/SAMPstartTemplate/Dependency/</path>
+        <wrapper1>startUp</wrapper1>
+        <topology>newFuncTopo.py</topology>
+    </DEPENDENCY>
+
     <ENV>
-        <cellName>functionality</cellName>
+        <cellName>productionCell</cellName>
         <cellApps>drivers,openflow,proxyarp,mobility</cellApps>
     </ENV>
+
     <GIT>
         <pull>False</pull>
         <branch>master</branch>
     </GIT>
+
     <CTRL>
-        <num>3</num>
-        <ip1>OC1</ip1>
-        <port1>6633</port1>
-        <ip2>OC2</ip2>
-        <port2>6633</port2>
-        <ip3>OC3</ip3>
-        <port3>6633</port3>
+        <port>6633</port>
     </CTRL>
-    <BENCH>
-        <user>admin</user>
-        <ip1>OCN</ip1>
-    </BENCH>
-    <MININET>
-        <switch>7</switch>
-        <links>20</links>
-        <topo>~/mininet/custom/newFuncTopo.py</topo>
-    </MININET>
+
+    <SLEEP>
+        <startup>15</startup>
+    </SLEEP>
 
 </PARAMS>
diff --git a/TestON/tests/SAMPstartTemplate/SAMPstartTemplate.py b/TestON/tests/SAMPstartTemplate/SAMPstartTemplate.py
index 9df58af..acd899d 100644
--- a/TestON/tests/SAMPstartTemplate/SAMPstartTemplate.py
+++ b/TestON/tests/SAMPstartTemplate/SAMPstartTemplate.py
@@ -7,104 +7,122 @@
     def __init__( self ):
         self.default = ''
 
-    def CASE10( self, main ):
+    def CASE1( self, main ):
         import time
         import os
         import imp
-        """
-        Startup sequence:
-        git pull
-        cell <name>
-        onos-verify-cell
-        onos-remove-raft-log
-        mvn clean install
-        onos-package
-        onos-install -f
-        onos-wait-for-start
-        """
-        global init
-        global globalONOSip
-        try:
-            if type(init) is not bool:
-                init = False
-        except NameError:
-            init = False
 
-        #Local variables
-        cellName = main.params[ 'ENV' ][ 'cellName' ]
-        apps = main.params[ 'ENV' ][ 'cellApps' ]
+        """
+        - Construct tests variables
+        - GIT ( optional )
+            - Checkout ONOS master branch
+            - Pull latest ONOS code
+        - Building ONOS ( optional )
+            - Install ONOS package
+            - Build ONOS package
+        """
+
+        main.case( "Constructing test variables and building ONOS package" )
+        main.step( "Constructing test variables" )
+        stepResult = main.FALSE
+
+        # Test variables
+        main.testOnDirectory = os.path.dirname( os.getcwd ( ) )
+        main.cellName = main.params[ 'ENV' ][ 'cellName' ]
+        main.apps = main.params[ 'ENV' ][ 'cellApps' ]
         gitBranch = main.params[ 'GIT' ][ 'branch' ]
-        benchIp = os.environ[ 'OCN' ]
-        benchUser = main.params[ 'BENCH' ][ 'user' ]
-        topology = main.params[ 'MININET' ][ 'topo' ]
-        main.numSwitch = int( main.params[ 'MININET' ][ 'switch' ] )
-        main.numLinks = int( main.params[ 'MININET' ][ 'links' ] )
-        main.numCtrls = main.params[ 'CTRL' ][ 'num' ]
-        main.ONOSport = []
-        main.hostsData = {}
-        PULLCODE = False
-        if main.params[ 'GIT' ][ 'pull' ] == 'True':
-            PULLCODE = True
-        main.case( "Setting up test environment" )
+        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' ]
+        main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
+        gitPull = main.params[ 'GIT' ][ 'pull' ]
+        main.cellData = {} # for creating cell file
         main.CLIs = []
-        for i in range( 1, int( main.numCtrls ) + 1 ):
+        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 ) ) )
-            main.ONOSport.append( main.params[ 'CTRL' ][ 'port' + str( i ) ] )
 
         # -- INIT SECTION, ONLY RUNS ONCE -- #
-        if init == False:
-            init = True
+        main.startUp = imp.load_source( wrapperFile1,
+                                        main.dependencyPath +
+                                        wrapperFile1 +
+                                        ".py" )
 
-            main.scale = ( main.params[ 'SCALE' ] ).split( "," )
-            main.numCtrls = int( main.scale[ 0 ] )
+        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
 
-            if PULLCODE:
-                main.step( "Git checkout and pull " + gitBranch )
-                main.ONOSbench.gitCheckout( gitBranch )
-                gitPullResult = main.ONOSbench.gitPull()
-                if gitPullResult == main.ERROR:
-                    main.log.error( "Error pulling git branch" )
-                main.step( "Using mvn clean & install" )
-                cleanInstallResult = main.ONOSbench.cleanInstall()
-                stepResult = cleanInstallResult
-                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" )
+        utilities.assert_equals( expect=main.TRUE,
+                                 actual=stepResult,
+                                 onpass="Successfully construct " +
+                                        "test variables ",
+                                 onfail="Failed to construct test variables" )
 
-            globalONOSip = main.ONOSbench.getOnosIps()
+        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" )
 
-        maxNodes = ( len( globalONOSip ) - 2 )
+    def CASE2( self, main ):
+        """
+        - Set up cell
+            - Create cell file
+            - Set cell file
+            - Verify cell file
+        - Kill ONOS process
+        - Uninstall ONOS cluster
+        - Verify ONOS start up
+        - Install ONOS cluster
+        - Connect to cli
+        """
 
+        # main.scale[ 0 ] determines the current number of ONOS controller
         main.numCtrls = int( main.scale[ 0 ] )
-        main.scale.remove( main.scale[ 0 ] )
 
-        main.ONOSip = []
-        for i in range( maxNodes ):
-            main.ONOSip.append( globalONOSip[ i ] )
+        main.case( "Starting up " + str( main.numCtrls ) +
+                   " node(s) ONOS cluster" )
 
         #kill off all onos processes
         main.log.info( "Safety check, killing all ONOS processes" +
                        " before initiating enviornment setup" )
-        for i in range( maxNodes ):
-            main.ONOSbench.onosDie( globalONOSip[ i ] )
+
+        for i in range( main.maxNodes ):
+            main.ONOSbench.onosDie( main.ONOSip[ i ] )
 
         print "NODE COUNT = ", main.numCtrls
-        main.log.info( "Creating cell file" )
-        cellIp = []
+
+        tempOnosIp = []
         for i in range( main.numCtrls ):
-            cellIp.append( str( main.ONOSip[ i ] ) )
-        print cellIp
-        main.ONOSbench.createCellFile( benchIp, cellName, "",
-                                       str( apps ), *cellIp )
+            tempOnosIp.append( main.ONOSip[i] )
+
+        main.ONOSbench.createCellFile( main.ONOSbench.ip_address, "temp", main.Mininet1.ip_address, main.apps, tempOnosIp )
 
         main.step( "Apply cell to environment" )
-        cellResult = main.ONOSbench.setCell( cellName )
+        cellResult = main.ONOSbench.setCell( "temp" )
         verifyResult = main.ONOSbench.verifyCell()
         stepResult = cellResult and verifyResult
         utilities.assert_equals( expect=main.TRUE,
@@ -121,6 +139,7 @@
                                  onpass="Successfully created ONOS package",
                                  onfail="Failed to create ONOS package" )
 
+        time.sleep( main.startUpSleep )
         main.step( "Uninstalling ONOS package" )
         onosUninstallResult = main.TRUE
         for i in range( main.numCtrls ):
@@ -131,7 +150,8 @@
                                  actual=stepResult,
                                  onpass="Successfully uninstalled ONOS package",
                                  onfail="Failed to uninstall ONOS package" )
-        time.sleep( 5 )
+
+        time.sleep( main.startUpSleep )
         main.step( "Installing ONOS package" )
         onosInstallResult = main.TRUE
         for i in range( main.numCtrls ):
@@ -143,11 +163,12 @@
                                  onpass="Successfully installed ONOS package",
                                  onfail="Failed to install ONOS package" )
 
-        time.sleep( 20 )
+        time.sleep( main.startUpSleep )
         main.step( "Starting ONOS service" )
         stopResult = main.TRUE
         startResult = main.TRUE
         onosIsUp = main.TRUE
+
         for i in range( main.numCtrls ):
             onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
         if onosIsUp == main.TRUE:
@@ -178,12 +199,15 @@
                                  onpass="Successfully start ONOS cli",
                                  onfail="Failed to start ONOS cli" )
 
+        # Remove the first element in main.scale list
+        main.scale.remove( main.scale[ 0 ] )
+
     def CASE9( self, main ):
         '''
             Report errors/warnings/exceptions
         '''
         main.log.info("Error report: \n" )
-        main.ONOSbench.logReport( globalONOSip[ 0 ],
+        main.ONOSbench.logReport( main.ONOSip[ 0 ],
                                   [ "INFO",
                                     "FOLLOWER",
                                     "WARN",
@@ -191,7 +215,6 @@
                                     "ERROR",
                                     "Except" ],
                                   "s" )
-        #main.ONOSbench.logReport( globalONOSip[1], [ "INFO" ], "d" )
 
     def CASE11( self, main ):
         """
@@ -212,3 +235,11 @@
             main.cleanup()
             main.exit()
 
+    def CASE12( self, main ):
+        """
+            Test random ONOS command
+        """
+
+        main.CLIs[ 0 ].startOnosCli( main.ONOSip[ 0 ] )
+        print main.CLIs[ 0 ].leaders()
+
diff --git a/TestON/tests/SAMPstartTemplate/SAMPstartTemplate.topo b/TestON/tests/SAMPstartTemplate/SAMPstartTemplate.topo
index e6613de..4a116c3 100755
--- a/TestON/tests/SAMPstartTemplate/SAMPstartTemplate.topo
+++ b/TestON/tests/SAMPstartTemplate/SAMPstartTemplate.topo
@@ -2,45 +2,48 @@
     <COMPONENT>
 
         <ONOSbench>
-            <host>OCN</host>
+            <host>localhost</host>
             <user>admin</user>
             <password>onos_test</password>
             <type>OnosDriver</type>
             <connect_order>1</connect_order>
             <COMPONENTS>
-                <home>~/ONOS</home>
+                <nodes>3</nodes>
             </COMPONENTS>
         </ONOSbench>
 
         <ONOScli1>
-            <host>OCN</host>
+            <host>localhost</host>
             <user>admin</user>
             <password>onos_test</password>
             <type>OnosCliDriver</type>
             <connect_order>2</connect_order>
-            <COMPONENTS> </COMPONENTS>
+            <COMPONENTS>
+            </COMPONENTS>
         </ONOScli1>
 
         <ONOScli2>
-            <host>OCN</host>
+            <host>localhost</host>
             <user>admin</user>
             <password>onos_test</password>
             <type>OnosCliDriver</type>
             <connect_order>3</connect_order>
-            <COMPONENTS> </COMPONENTS>
+            <COMPONENTS>
+            </COMPONENTS>
         </ONOScli2>
 
          <ONOScli3>
-            <host>OCN</host>
+            <host>localhost</host>
             <user>admin</user>
             <password>onos_test</password>
             <type>OnosCliDriver</type>
             <connect_order>4</connect_order>
-            <COMPONENTS> </COMPONENTS>
+            <COMPONENTS>
+            </COMPONENTS>
         </ONOScli3>
 
         <Mininet1>
-            <host>OCN</host>
+            <host>localhost</host>
             <user>admin</user>
             <password>onos_test</password>
             <type>MininetCliDriver</type>