fix --twait (#1040)

- pass timeout correctly to waitConnected()
- handle surprising behavior that 1 == True in Python
- mn --test none does not call waitConnected()
This commit is contained in:
lantz
2021-02-09 11:26:39 -08:00
committed by GitHub
parent f8e54cad47
commit 5ef6e1dedc
2 changed files with 11 additions and 6 deletions
+5 -2
View File
@@ -101,7 +101,6 @@ CLI = None # Set below if needed
# Locally defined tests # Locally defined tests
def allTest( net ): def allTest( net ):
"Run ping and iperf tests" "Run ping and iperf tests"
net.waitConnected()
net.start() net.start()
net.ping() net.ping()
net.iperf() net.iperf()
@@ -131,7 +130,6 @@ def runTests( mn, options ):
if callable( testfn ): if callable( testfn ):
testfn( mn, *args, **kwargs ) testfn( mn, *args, **kwargs )
elif hasattr( mn, test ): elif hasattr( mn, test ):
mn.waitConnected()
getattr( mn, test )( *args, **kwargs ) getattr( mn, test )( *args, **kwargs )
else: else:
raise Exception( 'Test %s is unknown - please specify one of ' raise Exception( 'Test %s is unknown - please specify one of '
@@ -389,6 +387,11 @@ class MininetRunner( object ):
placement=PLACEMENT[ opts.placement ] ) placement=PLACEMENT[ opts.placement ] )
mininet.cli.CLI = ClusterCLI mininet.cli.CLI = ClusterCLI
# Wait for controllers to connect unless we're running null test
if ( opts.test and opts.test != [ 'none' ] and
isinstance( opts.wait, bool ) ):
opts.wait = True
mn = Net( topo=topo, mn = Net( topo=topo,
switch=switch, host=host, controller=controller, link=link, switch=switch, host=host, controller=controller, link=link,
ipBase=opts.ipbase, inNamespace=opts.innamespace, ipBase=opts.ipbase, inNamespace=opts.innamespace,
+6 -4
View File
@@ -183,8 +183,11 @@ class Mininet( object ):
delay: seconds to sleep per iteration delay: seconds to sleep per iteration
returns: True if all switches are connected""" returns: True if all switches are connected"""
info( '*** Waiting for switches to connect\n' ) info( '*** Waiting for switches to connect\n' )
time = 0 time = 0.0
remaining = list( self.switches ) remaining = list( self.switches )
# False: 0s timeout; None: wait forever (preserve 2.2 behavior)
if isinstance( timeout, bool ):
timeout = None if timeout else 0
while True: while True:
for switch in tuple( remaining ): for switch in tuple( remaining ):
if switch.connected(): if switch.connected():
@@ -193,8 +196,7 @@ class Mininet( object ):
if not remaining: if not remaining:
info( '\n' ) info( '\n' )
return True return True
# Still allow None to preserve 2.2 behavior if timeout is not None and time >= timeout:
if timeout not in ( None, True ) and time > timeout:
break break
sleep( delay ) sleep( delay )
time += delay time += delay
@@ -561,7 +563,7 @@ class Mininet( object ):
started.update( { s: s for s in success } ) started.update( { s: s for s in success } )
info( '\n' ) info( '\n' )
if self.waitConn: if self.waitConn:
self.waitConnected() self.waitConnected( self.waitConn )
def stop( self ): def stop( self ):
"Stop the controller(s), switches and hosts" "Stop the controller(s), switches and hosts"