Changed mininet cli driver connect/disconnect functionality; and onos driver connect function
diff --git a/TestON/drivers/common/cli/emulator/mininetclidriver.py b/TestON/drivers/common/cli/emulator/mininetclidriver.py
index a45ed20..cd64fd0 100644
--- a/TestON/drivers/common/cli/emulator/mininetclidriver.py
+++ b/TestON/drivers/common/cli/emulator/mininetclidriver.py
@@ -59,19 +59,46 @@
"""
Here the main is the TestON instance after creating
all the log handles."""
- for key in connectargs:
- vars( self )[ key ] = connectargs[ key ]
+ try:
+ for key in connectargs:
+ vars( self )[ key ] = connectargs[ key ]
- self.name = self.options[ 'name' ]
- self.handle = super(
- MininetCliDriver,
- self ).connect(
- user_name=self.user_name,
- ip_address=self.ip_address,
- port=None,
- pwd=self.pwd )
+ self.name = self.options[ 'name' ]
+ self.handle = super(
+ MininetCliDriver,
+ self ).connect(
+ user_name=self.user_name,
+ ip_address=self.ip_address,
+ port=None,
+ pwd=self.pwd )
- self.sshHandle = self.handle
+ if self.handle:
+ main.log.info("Connection successful to the host " +
+ self.user_name +
+ "@" +
+ self.ip_address )
+ return main.TRUE
+ else:
+ main.log.error( "Connection failed to the host " +
+ self.user_name +
+ "@" +
+ self.ip_address )
+ msin.log.error( "Failed to connect to the Mininet CLI" )
+ return main.FALSE
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ main.cleanup()
+ main.exit()
+ except:
+ main.log.info( self.name + ":::::::::::::::::::::::" )
+ main.log.error( traceback.print_exc() )
+ main.log.info( ":::::::::::::::::::::::" )
+ main.cleanup()
+ main.exit()
+
+
+ def startNet( self, topoFile = '', args = '', timeout = 120 ):
if self.handle:
main.log.info(
@@ -82,7 +109,7 @@
'Cleanup\scomplete',
pexpect.EOF,
pexpect.TIMEOUT ],
- 120 )
+ timeout )
if i == 0:
main.log.info( self.name + ": Sending sudo password" )
self.handle.sendline( self.pwd )
@@ -90,7 +117,7 @@
'\$',
pexpect.EOF,
pexpect.TIMEOUT ],
- 120 )
+ timeout )
if i == 1:
main.log.info( self.name + ": Clean" )
elif i == 2:
@@ -99,51 +126,68 @@
main.log.error(
self.name +
": Something while cleaning MN took too long... " )
+ if topoFile == '' and args == '':
+ main.log.info( self.name + ": building fresh mininet" )
+ # for reactive/PARP enabled tests
+ cmdString = "sudo mn " + self.options[ 'arg1' ] +\
+ " " + self.options[ 'arg2' ] +\
+ " --mac --controller " +\
+ self.options[ 'controller' ] + " " +\
+ self.options[ 'arg3' ]
- main.log.info( self.name + ": building fresh mininet" )
- # for reactive/PARP enabled tests
- cmdString = "sudo mn " + self.options[ 'arg1' ] +\
- " " + self.options[ 'arg2' ] +\
- " --mac --controller " +\
- self.options[ 'controller' ] + " " +\
- self.options[ 'arg3' ]
+ argList = self.options[ 'arg1' ].split( "," )
+ global topoArgList
+ topoArgList = argList[ 0 ].split( " " )
+ argList = map( int, argList[ 1: ] )
+ topoArgList = topoArgList[ 1: ] + argList
- argList = self.options[ 'arg1' ].split( "," )
- global topoArgList
- topoArgList = argList[ 0 ].split( " " )
- argList = map( int, argList[ 1: ] )
- topoArgList = topoArgList[ 1: ] + argList
-
- self.handle.sendline( cmdString )
- self.handle.expect( [ "sudo mn", pexpect.EOF, pexpect.TIMEOUT ] )
- while True:
+ self.handle.sendline( cmdString )
+ self.handle.expect( [ "sudo mn",
+ pexpect.EOF,
+ pexpect.TIMEOUT ] )
+ while True:
+ i = self.handle.expect( [ 'mininet>',
+ '\*\*\*',
+ 'Exception',
+ pexpect.EOF,
+ pexpect.TIMEOUT ],
+ timeout )
+ if i == 0:
+ main.log.info( self.name + ": mininet built" )
+ return main.TRUE
+ if i == 1:
+ self.handle.expect(
+ [ "\n", pexpect.EOF, pexpect.TIMEOUT ] )
+ main.log.info( self.handle.before )
+ elif i == 2:
+ main.log.error(
+ self.name +
+ ": Launching mininet failed..." )
+ return main.FALSE
+ elif i == 3:
+ main.log.error( self.name + ": Connection timeout" )
+ return main.FALSE
+ elif i == 4: # timeout
+ main.log.error(
+ self.name +
+ ": Something took too long... " )
+ return main.FALSE
+ return main.TRUE
+ else:
+ main.log.info( "Starting topo file " + topoFile )
+ if args == None:
+ args = ''
+ else:
+ main.log.info( "args = " + args)
+ self.handle.sendline( 'sudo ' + topoFile + ' ' + args)
+ i = 1
i = self.handle.expect( [ 'mininet>',
- '\*\*\*',
- 'Exception',
- pexpect.EOF,
- pexpect.TIMEOUT ],
- 300 )
- if i == 0:
- main.log.info( self.name + ": mininet built" )
- return main.TRUE
- if i == 1:
- self.handle.expect(
- [ "\n", pexpect.EOF, pexpect.TIMEOUT ] )
- main.log.info( self.handle.before )
- elif i == 2:
- main.log.error(
- self.name +
- ": Launching mininet failed..." )
- return main.FALSE
- elif i == 3:
- main.log.error( self.name + ": Connection timeout" )
- return main.FALSE
- elif i == 4: # timeout
- main.log.error(
- self.name +
- ": Something took too long... " )
- return main.FALSE
- return main.TRUE
+ pexpect.EOF ,
+ pexpect.TIMEOUT ],
+ timeout)
+ main.log.info(self.name + ": Network started")
+ return main.TRUE
+
else: # if no handle
main.log.error(
self.name +
@@ -367,6 +411,89 @@
else:
return main.TRUE
+ def moveHost( self, host, oldSw, newSw, ):
+ """
+ Moves a host from one switch to another on the fly
+ Note: The intf between host and oldSw when detached
+ using detach(), will still show up in the 'net'
+ cmd, because switch.detach() doesn't affect switch.intfs[]
+ (which is correct behavior since the interfaces
+ haven't moved).
+ """
+ if self.handle:
+ try:
+ # Bring link between oldSw-host down
+ cmd = "py net.configLinkStatus('" + oldSw + "'," + "'" + host + "'," +\
+ "'down')"
+ print "cmd1= ", cmd
+ response = self.execute(
+ cmd=cmd,
+ prompt="mininet>",
+ timeout=10 )
+
+ # Determine hostintf and Oldswitchintf
+ cmd = "px hintf,sintf = " + host + ".connectionsTo(" + oldSw +\
+ ")[0]"
+ print "cmd2= ", cmd
+ self.handle.sendline( cmd )
+ self.handle.expect( "mininet>" )
+
+ # Determine ipaddress of the host-oldSw interface
+ cmd = "px ipaddr = hintf.IP()"
+ print "cmd3= ", cmd
+ self.handle.sendline( cmd )
+ self.handle.expect( "mininet>" )
+
+ # Detach interface between oldSw-host
+ cmd = "px " + oldSw + ".detach( sintf )"
+ print "cmd4= ", cmd
+ self.handle.sendline( cmd )
+ self.handle.expect( "mininet>" )
+
+ # Add link between host-newSw
+ cmd = "py net.addLink(" + host + "," + newSw + ")"
+ print "cmd5= ", cmd
+ self.handle.sendline( cmd )
+ self.handle.expect( "mininet>" )
+
+ # Determine hostintf and Newswitchintf
+ cmd = "px hintf,sintf = " + host + ".connectionsTo(" + newSw +\
+ ")[0]"
+ print "cmd6= ", cmd
+ self.handle.sendline( cmd )
+ self.handle.expect( "mininet>" )
+
+ # Attach interface between newSw-host
+ cmd = "px " + newSw + ".attach( sintf )"
+ print "cmd3= ", cmd
+ self.handle.sendline( cmd )
+ self.handle.expect( "mininet>" )
+
+ # Set ipaddress of the host-newSw interface
+ cmd = "px " + host + ".setIP( ip = ipaddr, intf = hintf)"
+ print "cmd7 = ", cmd
+ self.handle.sendline( cmd )
+ self.handle.expect( "mininet>" )
+
+ cmd = "net"
+ print "cmd8 = ", cmd
+ self.handle.sendline( cmd )
+ self.handle.expect( "mininet>" )
+ print "output = ", self.handle.before
+
+ # Determine ipaddress of the host-newSw interface
+ cmd = "h1 ifconfig"
+ print "cmd9= ", cmd
+ self.handle.sendline( cmd )
+ self.handle.expect( "mininet>" )
+ print "ifconfig o/p = ", self.handle.before
+
+ return main.TRUE
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ return main.FALSE
+
def changeIP( self, host, intf, newIP, newNetmask ):
"""
Changes the ip address of a host on the fly
@@ -1108,6 +1235,29 @@
main.exit()
def disconnect( self ):
+ """
+ Called at the end of the test to disconnect the handle.
+ """
+ self.handle.sendline('')
+ i = 1
+ i = self.handle.expect( ['mininet>',pexpect.EOF,pexpect.TIMEOUT ], timeout = 2)
+ if i == 0:
+ self.stopNet()
+ response = ''
+ # print "Disconnecting Mininet"
+ if self.handle:
+ self.handle.sendline( "exit" )
+ self.handle.expect( "exit" )
+ self.handle.expect( "(.*)" )
+ main.log.info( "Mininet CLI is successfully disconnected" )
+ response = self.handle.before
+ else:
+ main.log.error( "Connection failed to the host" )
+ response = main.FALSE
+
+ return response
+
+ def stopNet( self ):
main.log.info( self.name + ": Disconnecting mininet..." )
response = ''
if self.handle:
@@ -1116,10 +1266,7 @@
cmd="exit",
prompt="(.*)",
timeout=120 )
- response = self.execute(
- cmd="exit",
- prompt="(.*)",
- timeout=120 )
+ main.log.info( self.name + ": Disconnected")
self.handle.sendline( "sudo mn -c" )
response = main.TRUE
except pexpect.EOF:
@@ -1132,6 +1279,8 @@
response = main.FALSE
return response
+
+
def arping( self, src, dest, destmac ):
self.handle.sendline( '' )
self.handle.expect( [ "mininet", pexpect.EOF, pexpect.TIMEOUT ] )
diff --git a/TestON/drivers/common/cli/onosdriver.py b/TestON/drivers/common/cli/onosdriver.py
index a9a5a03..50994ee 100644
--- a/TestON/drivers/common/cli/onosdriver.py
+++ b/TestON/drivers/common/cli/onosdriver.py
@@ -45,7 +45,9 @@
if key == "home":
self.home = self.options[ 'home' ]
break
-
+ if self.home == None or self.home == "":
+ self.home = "~/ONOS"
+
self.name = self.options[ 'name' ]
self.handle = super( OnosDriver, self ).connect(
user_name=self.user_name,
@@ -238,7 +240,7 @@
# main.log.info( self.name + ": Stopping ONOS" )
# self.stop()
self.handle.sendline( "cd " + self.home )
- self.handle.expect( "ONOS\$" )
+ self.handle.expect( self.home + "\$" )
if comp1 == "":
self.handle.sendline( "git pull" )
else:
@@ -274,7 +276,7 @@
main.log.info(
self.name +
": Git Pull - pulling repository now" )
- self.handle.expect( "ONOS\$", 120 )
+ self.handle.expect( self.home + "\$", 120 )
# So that only when git pull is done, we do mvn clean compile
return main.TRUE
elif i == 3:
@@ -345,7 +347,7 @@
"""
try:
self.handle.sendline( "cd " + self.home )
- self.handle.expect( "ONOS\$" )
+ self.handle.expect( self.home + "\$" )
main.log.info(
self.name +
": Checking out git branch: " +
@@ -385,7 +387,7 @@
self.name +
": Git Checkout %s : Already on this branch" %
branch )
- self.handle.expect( "ONOS\$" )
+ self.handle.expect( self.home + "\$" )
# main.log.info( "DEBUG: after checkout cmd = "+
# self.handle.before )
return main.TRUE
@@ -394,7 +396,7 @@
self.name +
": Git checkout %s - Switched to this branch" %
branch )
- self.handle.expect( "ONOS\$" )
+ self.handle.expect( self.home + "\$" )
# main.log.info( "DEBUG: after checkout cmd = "+
# self.handle.before )
return main.TRUE
@@ -413,7 +415,7 @@
files would be overwritten by checkout:" +
str(
self.handle.before ) )
- self.handle.expect( "ONOS\$" )
+ self.handle.expect( self.home + "\$" )
return main.ERROR
elif i == 6:
main.log.error( self.name +
@@ -421,7 +423,7 @@
"You need to resolve your\
current index first:" +
str( self.handle.before ) )
- self.handle.expect( "ONOS\$" )
+ self.handle.expect( self.home + "\$" )
return main.ERROR
else:
main.log.error(