Changed copyMininetFile of onosdriver to scp function in clidriver
Change-Id: I52a11e7f97e727777e3ea891b453d4741fc32d1e
diff --git a/TestON/drivers/common/cli/emulator/mininetclidriver.py b/TestON/drivers/common/cli/emulator/mininetclidriver.py
index 1d5322d..89a2611 100644
--- a/TestON/drivers/common/cli/emulator/mininetclidriver.py
+++ b/TestON/drivers/common/cli/emulator/mininetclidriver.py
@@ -49,6 +49,7 @@
super( Emulator, self ).__init__()
self.handle = self
self.name = None
+ self.home = None
self.wrapped = sys.modules[ __name__ ]
self.flag = 0
@@ -59,8 +60,14 @@
try:
for key in connectargs:
vars( self )[ key ] = connectargs[ key ]
-
+ self.home = "~/mininet"
self.name = self.options[ 'name' ]
+ for key in self.options:
+ if key == "home":
+ self.home = self.options[ 'home' ]
+ break
+ if self.home is None or self.home == "":
+ self.home = "~/mininet"
try:
if os.getenv( str( self.ip_address ) ) != None:
diff --git a/TestON/drivers/common/cli/emulator/poxclidriver.py b/TestON/drivers/common/cli/emulator/poxclidriver.py
index 39effc7..2d92139 100644
--- a/TestON/drivers/common/cli/emulator/poxclidriver.py
+++ b/TestON/drivers/common/cli/emulator/poxclidriver.py
@@ -57,15 +57,7 @@
self.name = self.options[ 'name' ]
poxLibPath = 'default'
- copy = super(
- PoxCliDriver,
- self ).secureCopy(
- self.user_name,
- self.ip_address,
- '/home/openflow/pox/pox/core.py',
- self.pwd,
- path +
- '/lib/pox/' )
+
self.handle = super(
PoxCliDriver,
self ).connect(
diff --git a/TestON/drivers/common/cli/onosdriver.py b/TestON/drivers/common/cli/onosdriver.py
index b6965d3..0bdb9b0 100644
--- a/TestON/drivers/common/cli/onosdriver.py
+++ b/TestON/drivers/common/cli/onosdriver.py
@@ -1453,25 +1453,31 @@
main.cleanup()
main.exit()
- def runOnosTopoCfg( self, instanceName, jsonFile ):
+ def onosTopoCfg( self, onosIp, jsonFile ):
"""
- On ONOS bench, run this command:
- {ONOS_HOME}/tools/test/bin/onos-topo-cfg $OC1 filename
- which starts the rest and copies
- the json file to the onos instance
+ Description:
+ Execute onos-topo-cfg command
+ Required:
+ onosIp - IP of the onos node you want to send the json to
+ jsonFile - File path of the json file
+ Return:
+ Returns main.TRUE if the command is successfull; Returns
+ main.FALSE if there was an error
"""
try:
self.handle.sendline( "" )
self.handle.expect( "\$" )
- self.handle.sendline( "cd " + self.home + "/tools/test/bin" )
- self.handle.expect( "/bin$" )
- cmd = "./onos-topo-cfg " + instanceName + " " + jsonFile
- print "cmd = ", cmd
- self.handle.sendline( cmd )
- self.handle.expect( "\$" )
- self.handle.sendline( "cd ~" )
- self.handle.expect( "\$" )
- return main.TRUE
+ cmd = "onos-topo-cfg "
+ self.handle.sendline( cmd + str( onosIp ) + " " + jsonFile )
+ handle = self.handle.before
+ print handle
+ if "Error" in handle:
+ main.log.error( self.name + ": " + self.handle.before )
+ return main.FALSE
+ else:
+ self.handle.expect( "\$" )
+ return main.TRUE
+
except pexpect.EOF:
main.log.error( self.name + ": EOF exception found" )
main.log.error( self.name + ": " + self.handle.before )
diff --git a/TestON/drivers/common/clidriver.py b/TestON/drivers/common/clidriver.py
index bac11a4..fd1a401 100644
--- a/TestON/drivers/common/clidriver.py
+++ b/TestON/drivers/common/clidriver.py
@@ -252,27 +252,44 @@
prompt="(.*)",
timeout=120 )
- def secureCopy( self, user_name, ip_address, filepath, pwd, dst_path ):
-
- # scp openflow@192.168.56.101:/home/openflow/sample
- # /home/paxterra/Desktop/
+ def secureCopy( self, userName, ipAddress, filePath, dstPath, pwd="",
+ direction="from" ):
"""
- Connection will establish to the remote host using ssh.
- It will take user_name ,ip_address and password as arguments<br>
- and will return the handle.
+ Definition:
+ Execute scp command in linux to copy to/from a remote host
+ Required:
+ str userName - User name of the remote host
+ str ipAddress - IP address of the remote host
+ str filePath - File path including the file it self
+ str dstPath - Destination path
+ Optional:
+ str pwd - Password of the host
+ str direction - Direction of the scp, default to "from" which means
+ copy "from" the remote machine to local machine,
+ while "to" means copy "to" the remote machine from
+ local machine
"""
+ returnVal = main.TRUE
ssh_newkey = 'Are you sure you want to continue connecting'
refused = "ssh: connect to host " + \
- ip_address + " port 22: Connection refused"
+ ipAddress + " port 22: Connection refused"
- cmd = 'scp ' + str( user_name ) + '@' + str( ip_address ) + ':' + \
- str( filepath ) + ' ' + str(dst_path )
+ if direction == "from":
+ cmd = 'scp ' + str( userName ) + '@' + str( ipAddress ) + ':' + \
+ str( filePath ) + ' ' + str( dstPath )
+ elif direction == "to":
+ cmd = 'scp ' + str( filePath ) + ' ' + str( userName ) + \
+ '@' + str( ipAddress ) + ':' + str( dstPath )
+ else:
+ main.log.debug( "Wrong direction using secure copy command!" )
+ return main.FALSE
main.log.info( "Sending: " + cmd )
- self.handle = pexpect.spawn( cmd )
+ self.handle.sendline( cmd )
i = self.handle.expect( [
ssh_newkey,
'password:',
+ "100%",
pexpect.EOF,
pexpect.TIMEOUT,
refused ],
@@ -285,27 +302,50 @@
if i == 1:
main.log.info( "ssh connection asked for password, gave password" )
self.handle.sendline( pwd )
- # self.handle.expect( user_name )
-
- elif i == 2:
- main.log.error( "Connection timeout" )
- pass
- elif i == 3: # timeout
+ # self.handle.expect( userName )
+ if i == 2:
+ main.log.info( "Secure copy successful\n" + self.handle.before )
+ returnVal = main.TRUE
+ elif i == 3:
+ main.log.error( "Pexpect.EOF found!!!" )
+ main.cleanup()
+ main.exit()
+ elif i == 4: # timeout
main.log.error(
"No route to the Host " +
- user_name +
+ userName +
"@" +
- ip_address )
- return main.FALSE
- elif i == 4:
+ ipAddress )
+ returnVal = main.FALSE
+ elif i == 5:
main.log.error(
"ssh: connect to host " +
- ip_address +
+ ipAddress +
" port 22: Connection refused" )
- return main.FALSE
+ returnVal = main.FALSE
self.handle.sendline( "" )
self.handle.expect( "$" )
- print self.handle.before
- return self.handle
+ return returnVal
+
+ def scp( self, remoteHost, filePath, dstPath, direction="from" ):
+ """
+ Definition:
+ Execute scp command in linux to copy to/from a remote host
+ Required:
+ * remoteHost - Test ON component to be parsed
+ str filePath - File path including the file it self
+ str dstPath - Destination path
+ Optional:
+ str direction - Direction of the scp, default to "from" which means
+ copy "from" the remote machine to local machine,
+ while "to" means copy "to" the remote machine from
+ local machine
+ """
+ return self.secureCopy( remoteHost.user_name,
+ remoteHost.ip_address,
+ filePath,
+ dstPath,
+ pwd=remoteHost.pwd,
+ direction=direction )