Make host discovery function more generic
Change-Id: I9501100b7e689d823d0ba4fca27b94e7fd943a17
diff --git a/TestON/drivers/common/cli/emulator/mininetclidriver.py b/TestON/drivers/common/cli/emulator/mininetclidriver.py
index 54d9747..59e1441 100644
--- a/TestON/drivers/common/cli/emulator/mininetclidriver.py
+++ b/TestON/drivers/common/cli/emulator/mininetclidriver.py
@@ -574,55 +574,40 @@
main.cleanAndExit()
- def discoverIpv4Hosts( self, hostList, wait=1 , dstIp="6.6.6.6"):
+ def discoverHosts( self, hostList=[], wait=1, dstIp="6.6.6.6", dstIp6="1020::3fe" ):
'''
- Can only be used if hosts already have ipv4 addresses.
-
- Hosts in hostList will do a single ping to a non-existent (dstIp) address for ONOS
- to discover them again.
+ Hosts in hostList will do a single ping to a non-existent address for ONOS to
+ discover them. A host will use ping/ping6 to send echo requests depending on if
+ it has IPv4/IPv6 addresses configured.
+ Optional:
+ hostList: a list of names of the hosts that need to be discovered. If not
+ specified mininet will send ping from all the hosts
+ wait: timeout for IPv4/IPv6 echo requests
+ dstIp: destination address used by IPv4 hosts
+ dstIp6: destination address used by IPv6 hosts
+ Returns:
+ main.TRUE if all ping packets were successfully sent. Otherwise main.FALSE
'''
try:
- main.log.info( "Issuing dumb pings for ipv6 hosts to be discovered" )
- cmd = " ping -c 1 -i 1 -W " + str( wait ) + " "
+ if not hostList:
+ hosts = self.getHosts( getInterfaces=False )
+ hostList = hosts.keys()
+ discoveryResult = main.TRUE
for host in hostList:
- pingCmd = str( host ) + cmd + dstIp
- self.handle.sendline( pingCmd )
- self.handle.expect( "mininet>", timeout=wait + 1 )
-
- except pexpect.TIMEOUT:
- main.log.exception( self.name + ": TIMEOUT exception" )
- response = self.handle.before
- # NOTE: Send ctrl-c to make sure command is stopped
- self.handle.send( "\x03" )
- self.handle.expect( "Interrupt" )
- response += self.handle.before + self.handle.after
- self.handle.expect( "mininet>" )
- response += self.handle.before + self.handle.after
- main.log.debug( response )
- return main.FALSE
- except pexpect.EOF:
- main.log.error( self.name + ": EOF exception found" )
- main.log.error( self.name + ": " + self.handle.before )
- main.cleanAndExit()
- except Exception:
- main.log.exception( self.name + ": Uncaught exception!" )
- main.cleanAndExit()
-
- def discoverIpv6Hosts( self, hostList, wait=1, dstIp="1020::3fe" ):
- '''
- Can only be used if hosts already have ipv6 addresses.
-
- Hosts in hostList will do a single ping to a non-existent address (dstIp) for ONOS
- to discover them again.
- '''
- try:
- main.log.info( "Issuing dump pings for ipv6 hosts to be discovered" )
- cmd = " ping6 -c 1 -i 1 -W " + str( wait ) + " "
- for host in hostList:
- pingCmd = str( host ) + cmd + dstIp
- self.handle.sendline( pingCmd )
- self.handle.expect( "mininet>", timeout=wait + 1 )
-
+ cmd = ""
+ if self.getIPAddress( host ):
+ cmd = "{} ping -c 1 -i 1 -W {} {}".format( host, wait, dstIp )
+ main.log.debug( "Sending IPv4 probe ping from host {}".format( host ) )
+ elif self.getIPAddress( host, proto='IPV6' ):
+ cmd = "{} ping6 -c 1 -i 1 -W {} {}".format( host, wait, dstIp6 )
+ main.log.debug( "Sending IPv6 probe ping from host {}".format( host ) )
+ else:
+ main.log.warn( "No IP addresses configured on host {}, skipping discovery".format( host ) )
+ discoveryResult = main.FALSE
+ if cmd:
+ self.handle.sendline( cmd )
+ self.handle.expect( "mininet>", timeout=wait + 1 )
+ return discoveryResult
except pexpect.TIMEOUT:
main.log.exception( self.name + ": TIMEOUT exception" )
response = self.handle.before
diff --git a/TestON/tests/USECASE/SegmentRouting/dependencies/Testcaselib.py b/TestON/tests/USECASE/SegmentRouting/dependencies/Testcaselib.py
index 44055d3..b8ad87f 100644
--- a/TestON/tests/USECASE/SegmentRouting/dependencies/Testcaselib.py
+++ b/TestON/tests/USECASE/SegmentRouting/dependencies/Testcaselib.py
@@ -650,7 +650,7 @@
onfail="Failed to kill switch?" )
@staticmethod
- def recoverSwitch( main, switch, switches, links, rediscoverHosts=False ):
+ def recoverSwitch( main, switch, switches, links, rediscoverHosts=False, hostsToDiscover=[] ):
"""
Params: switches, links: number of expected switches and links after SwitchUp, ex.: '4', '6'
Recover a switch and verify ONOS can see the proper change
@@ -665,8 +665,7 @@
main.switchSleep ) )
time.sleep( main.switchSleep )
if rediscoverHosts:
- main.Network.discoverIpv4Hosts( main.internalIpv4Hosts )
- main.Network.discoverIpv6Hosts( main.internalIpv6Hosts )
+ main.Network.discoverHosts( hostList=hostsToDiscover )
main.log.info( "Waiting %s seconds for hosts to get re-discovered" % (
main.switchSleep ) )
time.sleep( main.switchSleep )