Spacing tweaks for pep8 checker
This commit is contained in:
+2
-2
@@ -73,7 +73,7 @@ def cleanup():
|
||||
dps = sh("ovs-vsctl --timeout=1 list-br").strip().splitlines()
|
||||
if dps:
|
||||
sh( "ovs-vsctl " + " -- ".join( "--if-exists del-br " + dp
|
||||
for dp in dps if dp ) )
|
||||
for dp in dps if dp ) )
|
||||
# And in case the above didn't work...
|
||||
dps = sh("ovs-vsctl --timeout=1 list-br").strip().splitlines()
|
||||
for dp in dps:
|
||||
@@ -89,7 +89,7 @@ def cleanup():
|
||||
info( "*** Killing stale mininet node processes\n" )
|
||||
killprocs( 'mininet:' )
|
||||
|
||||
info ( "*** Shutting down stale tunnels\n" )
|
||||
info( "*** Shutting down stale tunnels\n" )
|
||||
killprocs( 'Tunnel=Ethernet' )
|
||||
killprocs( '.ssh/mn')
|
||||
sh( 'rm -f ~/.ssh/mn/*' )
|
||||
|
||||
+4
-3
@@ -37,7 +37,7 @@ import atexit
|
||||
from mininet.log import info, output, error
|
||||
from mininet.term import makeTerms, runX11
|
||||
from mininet.util import ( quietRun, dumpNodeConnections,
|
||||
dumpPorts )
|
||||
dumpPorts )
|
||||
|
||||
class CLI( Cmd ):
|
||||
"Simple command-line interface to talk to nodes."
|
||||
@@ -357,7 +357,7 @@ class CLI( Cmd ):
|
||||
return
|
||||
sw = args[ 0 ]
|
||||
command = args[ 1 ]
|
||||
if sw not in self.mn or self.mn.get( sw ) not in self.mn.switches :
|
||||
if sw not in self.mn or self.mn.get( sw ) not in self.mn.switches:
|
||||
error( 'invalid switch: %s\n' % args[ 1 ] )
|
||||
else:
|
||||
sw = args[ 0 ]
|
||||
@@ -367,7 +367,8 @@ class CLI( Cmd ):
|
||||
elif command == 'stop':
|
||||
self.mn.get( sw ).stop( deleteIntfs=False )
|
||||
else:
|
||||
error( 'invalid command: switch <switch name> {start, stop}\n' )
|
||||
error( 'invalid command: '
|
||||
'switch <switch name> {start, stop}\n' )
|
||||
|
||||
def default( self, line ):
|
||||
"""Called on an input line when the command prefix is not recognized.
|
||||
|
||||
+5
-3
@@ -91,7 +91,8 @@ class Intf( object ):
|
||||
"Return updated IP address based on ifconfig"
|
||||
# use pexec instead of node.cmd so that we dont read
|
||||
# backgrounded output from the cli.
|
||||
ifconfig, _err, _exitCode = self.node.pexec( 'ifconfig %s' % self.name )
|
||||
ifconfig, _err, _exitCode = self.node.pexec(
|
||||
'ifconfig %s' % self.name )
|
||||
ips = self._ipMatchRegex.findall( ifconfig )
|
||||
self.ip = ips[ 0 ] if ips else None
|
||||
return self.ip
|
||||
@@ -333,8 +334,9 @@ class TCIntf( Intf ):
|
||||
|
||||
# Delay/jitter/loss/max_queue_size using netem
|
||||
delaycmds, parent = self.delayCmds( delay=delay, jitter=jitter,
|
||||
loss=loss, max_queue_size=max_queue_size,
|
||||
parent=parent )
|
||||
loss=loss,
|
||||
max_queue_size=max_queue_size,
|
||||
parent=parent )
|
||||
cmds += delaycmds
|
||||
|
||||
# Ugly but functional: display configuration info
|
||||
|
||||
+3
-4
@@ -99,7 +99,7 @@ from math import ceil
|
||||
from mininet.cli import CLI
|
||||
from mininet.log import info, error, debug, output, warn
|
||||
from mininet.node import ( Node, Host, OVSKernelSwitch, DefaultController,
|
||||
Controller )
|
||||
Controller )
|
||||
from mininet.nodelib import NAT
|
||||
from mininet.link import Link, Intf
|
||||
from mininet.util import quietRun, fixLimits, numCores, ensureRoot
|
||||
@@ -170,7 +170,6 @@ class Mininet( object ):
|
||||
if topo and build:
|
||||
self.build()
|
||||
|
||||
|
||||
def waitConnected( self, timeout=None, delay=.5 ):
|
||||
"""wait for each switch to connect to a controller,
|
||||
up to 5 seconds
|
||||
@@ -260,7 +259,7 @@ class Mininet( object ):
|
||||
else:
|
||||
controller_new = controller( name, **params )
|
||||
# Add new controller to net
|
||||
if controller_new: # allow controller-less setups
|
||||
if controller_new: # allow controller-less setups
|
||||
self.controllers.append( controller_new )
|
||||
self.nameToNode[ name ] = controller_new
|
||||
return controller_new
|
||||
@@ -335,7 +334,7 @@ class Mininet( object ):
|
||||
@staticmethod
|
||||
def randMac():
|
||||
"Return a random, non-multicast MAC address"
|
||||
return macColonHex( random.randint(1, 2**48 - 1) & 0xfeffffffffff |
|
||||
return macColonHex( random.randint(1, 2**48 - 1) & 0xfeffffffffff |
|
||||
0x020000000000 )
|
||||
|
||||
def addLink( self, node1, node2, port1=None, port2=None,
|
||||
|
||||
+22
-20
@@ -129,7 +129,7 @@ class Node( object ):
|
||||
# bash -m: enable job control, i: force interactive
|
||||
# -s: pass $* to shell, and make process easy to find in ps
|
||||
# prompt is set to sentinel chr( 127 )
|
||||
cmd = [ 'mnexec', opts, 'env', 'PS1=' + chr( 127 ),
|
||||
cmd = [ 'mnexec', opts, 'env', 'PS1=' + chr( 127 ),
|
||||
'bash', '--norc', '-mis', 'mininet:' + self.name ]
|
||||
# Spawn a shell subprocess in a pseudo-tty, to disable buffering
|
||||
# in the subprocess and insulate it from signals (e.g. SIGINT)
|
||||
@@ -380,7 +380,7 @@ class Node( object ):
|
||||
"""Execute a command using popen
|
||||
returns: out, err, exitcode"""
|
||||
popen = self.popen( *args, stdin=PIPE, stdout=PIPE, stderr=PIPE,
|
||||
**kwargs )
|
||||
**kwargs )
|
||||
# Warning: this can fail with large numbers of fds!
|
||||
out, err = popen.communicate()
|
||||
exitcode = popen.wait()
|
||||
@@ -950,12 +950,12 @@ class UserSwitch( Switch ):
|
||||
we re-create the user switch's configuration, but as a
|
||||
leaf of the TCIntf-created configuration."""
|
||||
if isinstance( intf, TCIntf ):
|
||||
ifspeed = 10000000000 # 10 Gbps
|
||||
ifspeed = 10000000000 # 10 Gbps
|
||||
minspeed = ifspeed * 0.001
|
||||
|
||||
res = intf.config( **intf.params )
|
||||
|
||||
if res is None: # link may not have TC parameters
|
||||
if res is None: # link may not have TC parameters
|
||||
return
|
||||
|
||||
# Re-add qdisc, root, and default classes user switch created, but
|
||||
@@ -988,7 +988,7 @@ class UserSwitch( Switch ):
|
||||
' 1> ' + ofplog + ' 2>' + ofplog + ' &' )
|
||||
if "no-slicing" not in self.dpopts:
|
||||
# Only TCReapply if slicing is enable
|
||||
sleep(1) # Allow ofdatapath to start before re-arranging qdisc's
|
||||
sleep(1) # Allow ofdatapath to start before re-arranging qdisc's
|
||||
for intf in self.intfList():
|
||||
if not intf.IP():
|
||||
self.TCReapply( intf )
|
||||
@@ -1055,7 +1055,7 @@ class OVSSwitch( Switch ):
|
||||
"Open vSwitch switch. Depends on ovs-vsctl."
|
||||
|
||||
def __init__( self, name, failMode='secure', datapath='kernel',
|
||||
inband=False, protocols=None, **params ):
|
||||
inband=False, protocols=None, **params ):
|
||||
"""Init.
|
||||
name: name for switch
|
||||
failMode: controller loss behavior (secure|open)
|
||||
@@ -1087,13 +1087,13 @@ class OVSSwitch( Switch ):
|
||||
'"service openvswitch-switch start".\n' )
|
||||
exit( 1 )
|
||||
version = quietRun( 'ovs-vsctl --version' )
|
||||
cls.OVSVersion = findall( r'\d+\.\d+', version )[ 0 ]
|
||||
cls.OVSVersion = findall( r'\d+\.\d+', version )[ 0 ]
|
||||
|
||||
@classmethod
|
||||
def isOldOVS( cls ):
|
||||
"Is OVS ersion < 1.10?"
|
||||
return ( StrictVersion( cls.OVSVersion ) <
|
||||
StrictVersion( '1.10' ) )
|
||||
StrictVersion( '1.10' ) )
|
||||
|
||||
@classmethod
|
||||
def batchShutdown( cls, switches ):
|
||||
@@ -1128,7 +1128,7 @@ class OVSSwitch( Switch ):
|
||||
"Return ovsdb UUIDs for our controllers"
|
||||
uuids = []
|
||||
controllers = self.cmd( 'ovs-vsctl -- get Bridge', self,
|
||||
'Controller' ).strip()
|
||||
'Controller' ).strip()
|
||||
if controllers.startswith( '[' ) and controllers.endswith( ']' ):
|
||||
controllers = controllers[ 1 : -1 ]
|
||||
uuids = [ c.strip() for c in controllers.split( ',' ) ]
|
||||
@@ -1137,7 +1137,7 @@ class OVSSwitch( Switch ):
|
||||
def connected( self ):
|
||||
"Are we connected to at least one of our controllers?"
|
||||
results = [ 'true' in self.cmd( 'ovs-vsctl -- get Controller',
|
||||
uuid, 'is_connected' )
|
||||
uuid, 'is_connected' )
|
||||
for uuid in self.controllerUUIDs() ]
|
||||
return reduce( or_, results, False )
|
||||
|
||||
@@ -1148,15 +1148,15 @@ class OVSSwitch( Switch ):
|
||||
'OVS kernel switch does not work in a namespace' )
|
||||
# Annoyingly, --if-exists option seems not to work
|
||||
self.cmd( 'ovs-vsctl del-br', self )
|
||||
int( self.dpid, 16 ) # DPID must be a hex string
|
||||
int( self.dpid, 16 ) # DPID must be a hex string
|
||||
# Interfaces and controllers
|
||||
intfs = ' '.join( '-- add-port %s %s ' % ( self, intf ) +
|
||||
'-- set Interface %s ' % intf +
|
||||
'ofport_request=%s ' % self.ports[ intf ]
|
||||
for intf in self.intfList()
|
||||
if self.ports[ intf ] and not intf.IP() )
|
||||
for intf in self.intfList()
|
||||
if self.ports[ intf ] and not intf.IP() )
|
||||
clist = ' '.join( '%s:%s:%d' % ( c.protocol, c.IP(), c.port )
|
||||
for c in controllers )
|
||||
for c in controllers )
|
||||
if self.listenPort:
|
||||
clist += ' ptcp:%s' % self.listenPort
|
||||
# Construct big ovs-vsctl command for new versions of OVS
|
||||
@@ -1196,7 +1196,6 @@ class OVSSwitch( Switch ):
|
||||
for intf in self.intfList():
|
||||
self.TCReapply( intf )
|
||||
|
||||
|
||||
def stop( self, deleteIntfs=True ):
|
||||
"""Terminate OVS switch.
|
||||
deleteIntfs: delete interfaces? (True)"""
|
||||
@@ -1354,17 +1353,20 @@ class Controller( Node ):
|
||||
return '<%s %s: %s:%s pid=%s> ' % (
|
||||
self.__class__.__name__, self.name,
|
||||
self.IP(), self.port, self.pid )
|
||||
|
||||
@classmethod
|
||||
def isAvailable( cls ):
|
||||
"Is controller available?"
|
||||
return quietRun( 'which controller' )
|
||||
|
||||
|
||||
class OVSController( Controller ):
|
||||
"Open vSwitch controller"
|
||||
def __init__( self, name, command='ovs-controller', **kwargs ):
|
||||
if quietRun( 'which test-controller' ):
|
||||
command = 'test-controller'
|
||||
Controller.__init__( self, name, command=command, **kwargs )
|
||||
|
||||
@classmethod
|
||||
def isAvailable( cls ):
|
||||
return ( quietRun( 'which ovs-controller' ) or
|
||||
@@ -1411,11 +1413,11 @@ class RYU( Controller ):
|
||||
ryuArgs = [ ryuArgs ]
|
||||
|
||||
Controller.__init__( self, name,
|
||||
command='ryu-manager',
|
||||
cargs='--ofp-tcp-listen-port %s ' +
|
||||
' '.join( ryuArgs ),
|
||||
cdir=ryuCoreDir,
|
||||
**kwargs )
|
||||
command='ryu-manager',
|
||||
cargs='--ofp-tcp-listen-port %s ' +
|
||||
' '.join( ryuArgs ),
|
||||
cdir=ryuCoreDir,
|
||||
**kwargs )
|
||||
|
||||
class RemoteController( Controller ):
|
||||
"Controller running outside of Mininet's control."
|
||||
|
||||
+1
-1
@@ -82,7 +82,7 @@ class NAT( Node ):
|
||||
super( NAT, self).config( **params )
|
||||
|
||||
if not self.localIntf:
|
||||
self.localIntf = self.defaultIntf()
|
||||
self.localIntf = self.defaultIntf()
|
||||
|
||||
self.cmd( 'sysctl net.ipv4.ip_forward=0' )
|
||||
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ def tunnelX11( node, display=None):
|
||||
port = 6000 + int( float( screen ) )
|
||||
connection = r'TCP\:%s\:%s' % ( host, port )
|
||||
cmd = [ "socat", "TCP-LISTEN:%d,fork,reuseaddr" % port,
|
||||
"EXEC:'mnexec -a 1 socat STDIO %s'" % connection ]
|
||||
"EXEC:'mnexec -a 1 socat STDIO %s'" % connection ]
|
||||
return 'localhost:' + screen, node.popen( cmd )
|
||||
|
||||
def makeTerm( node, title='Node', term='xterm', display=None ):
|
||||
|
||||
@@ -40,7 +40,7 @@ class testOptionsTopoCommon( object ):
|
||||
"""Verify ability to create networks with host and link options
|
||||
(common code)."""
|
||||
|
||||
switchClass = None # overridden in subclasses
|
||||
switchClass = None # overridden in subclasses
|
||||
|
||||
@staticmethod
|
||||
def tearDown():
|
||||
@@ -87,7 +87,7 @@ class testOptionsTopoCommon( object ):
|
||||
upperBound, lowerBound ) )
|
||||
msg += info
|
||||
|
||||
self.assertGreaterEqual( float( measured ),lowerBound, msg=msg )
|
||||
self.assertGreaterEqual( float( measured ), lowerBound, msg=msg )
|
||||
self.assertLessEqual( float( measured ), upperBound, msg=msg )
|
||||
|
||||
def testCPULimits( self ):
|
||||
@@ -125,8 +125,8 @@ class testOptionsTopoCommon( object ):
|
||||
def testLinkBandwidth( self ):
|
||||
"Verify that link bandwidths are accurate within a bound."
|
||||
if self.switchClass is UserSwitch:
|
||||
self.skipTest ( 'UserSwitch has very poor performance -'
|
||||
' skipping for now' )
|
||||
self.skipTest( 'UserSwitch has very poor performance -'
|
||||
' skipping for now' )
|
||||
BW = 5 # Mbps
|
||||
BW_TOLERANCE = 0.8 # BW fraction below which test should fail
|
||||
# Verify ability to create limited-link topo first;
|
||||
@@ -195,7 +195,6 @@ class testOptionsTopoCommon( object ):
|
||||
self.assertWithinTolerance( rttval, DELAY_MS * 4.0,
|
||||
DELAY_TOLERANCE, msg )
|
||||
|
||||
|
||||
def testLinkLoss( self ):
|
||||
"Verify that we see packet drops with a high configured loss rate."
|
||||
LOSS_PERCENT = 99
|
||||
@@ -257,9 +256,10 @@ class testOptionsTopoIVS( testOptionsTopoCommon, unittest.TestCase ):
|
||||
switchClass = IVSSwitch
|
||||
|
||||
@unittest.skipUnless( quietRun( 'which ofprotocol' ),
|
||||
'Reference user switch is not installed' )
|
||||
'Reference user switch is not installed' )
|
||||
class testOptionsTopoUserspace( testOptionsTopoCommon, unittest.TestCase ):
|
||||
"Verify ability to create networks with host and link options (UserSwitch)."
|
||||
"""Verify ability to create networks with host and link options
|
||||
(UserSwitch)."""
|
||||
longMessage = True
|
||||
switchClass = UserSwitch
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ from mininet.clean import cleanup
|
||||
class testSingleSwitchCommon( object ):
|
||||
"Test ping with single switch topology (common code)."
|
||||
|
||||
switchClass = None # overridden in subclasses
|
||||
switchClass = None # overridden in subclasses
|
||||
|
||||
@staticmethod
|
||||
def tearDown():
|
||||
@@ -59,7 +59,7 @@ class testSingleSwitchIVS( testSingleSwitchCommon, unittest.TestCase ):
|
||||
switchClass = IVSSwitch
|
||||
|
||||
@unittest.skipUnless( quietRun( 'which ofprotocol' ),
|
||||
'Reference user switch is not installed' )
|
||||
'Reference user switch is not installed' )
|
||||
class testSingleSwitchUserspace( testSingleSwitchCommon, unittest.TestCase ):
|
||||
"Test ping with single switch topology (Userspace switch)."
|
||||
switchClass = UserSwitch
|
||||
@@ -71,7 +71,7 @@ class testSingleSwitchUserspace( testSingleSwitchCommon, unittest.TestCase ):
|
||||
class testLinearCommon( object ):
|
||||
"Test all-pairs ping with LinearNet (common code)."
|
||||
|
||||
switchClass = None # overridden in subclasses
|
||||
switchClass = None # overridden in subclasses
|
||||
|
||||
def testLinear5( self ):
|
||||
"Ping test on a 5-switch topology"
|
||||
|
||||
@@ -8,7 +8,8 @@ import sys
|
||||
|
||||
from mininet.net import Mininet
|
||||
from mininet.node import Host, Controller
|
||||
from mininet.node import UserSwitch, OVSSwitch, OVSLegacyKernelSwitch, IVSSwitch
|
||||
from mininet.node import ( UserSwitch, OVSSwitch, OVSLegacyKernelSwitch,
|
||||
IVSSwitch )
|
||||
from mininet.topo import Topo
|
||||
from mininet.log import setLogLevel
|
||||
from mininet.util import quietRun
|
||||
@@ -18,7 +19,7 @@ from mininet.clean import cleanup
|
||||
class TestSwitchDpidAssignmentOVS( unittest.TestCase ):
|
||||
"Verify Switch dpid assignment."
|
||||
|
||||
switchClass = OVSSwitch # overridden in subclasses
|
||||
switchClass = OVSSwitch # overridden in subclasses
|
||||
|
||||
def tearDown( self ):
|
||||
"Clean up if necessary"
|
||||
@@ -27,11 +28,12 @@ class TestSwitchDpidAssignmentOVS( unittest.TestCase ):
|
||||
if sys.exc_info != ( None, None, None ):
|
||||
cleanup()
|
||||
|
||||
def testDefaultDpid ( self ):
|
||||
def testDefaultDpid( self ):
|
||||
"""Verify that the default dpid is assigned using a valid provided
|
||||
canonical switchname if no dpid is passed in switch creation."""
|
||||
switch = Mininet( Topo(),
|
||||
self.switchClass, Host, Controller ).addSwitch( 's1' )
|
||||
self.switchClass,
|
||||
Host, Controller ).addSwitch( 's1' )
|
||||
self.assertEqual( switch.defaultDpid(), switch.dpid )
|
||||
|
||||
def dpidFrom( self, num ):
|
||||
@@ -45,7 +47,7 @@ class TestSwitchDpidAssignmentOVS( unittest.TestCase ):
|
||||
dpid = self.dpidFrom( 0xABCD )
|
||||
switch = Mininet( Topo(), self.switchClass,
|
||||
Host, Controller ).addSwitch(
|
||||
's1', dpid=dpid )
|
||||
's1', dpid=dpid )
|
||||
self.assertEqual( switch.dpid, dpid )
|
||||
|
||||
def testDefaultDpidAssignmentFailure( self ):
|
||||
|
||||
+3
-3
@@ -78,7 +78,6 @@ class MultiGraph( object ):
|
||||
"Return list of graph edges"
|
||||
return list( self.edges_iter( data=data, keys=keys ) )
|
||||
|
||||
|
||||
def __getitem__( self, node ):
|
||||
"Return link dict for given src node"
|
||||
return self.edge[ node ]
|
||||
@@ -147,7 +146,7 @@ class Topo( object ):
|
||||
return result
|
||||
|
||||
def addLink( self, node1, node2, port1=None, port2=None,
|
||||
key=None, **opts ):
|
||||
key=None, **opts ):
|
||||
"""node1, node2: nodes to link together
|
||||
port1, port2: ports (optional)
|
||||
opts: link options (optional)
|
||||
@@ -306,7 +305,8 @@ class SingleSwitchTopo( Topo ):
|
||||
class SingleSwitchReversedTopo( Topo ):
|
||||
"""Single switch connected to k hosts, with reversed ports.
|
||||
The lowest-numbered host is connected to the highest-numbered port.
|
||||
Useful to verify that Mininet properly handles custom port numberings."""
|
||||
Useful to verify that Mininet properly handles custom port
|
||||
numberings."""
|
||||
|
||||
def build( self, k=2 ):
|
||||
"k: number of hosts"
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ class TorusTopo( Topo ):
|
||||
def build( self, x, y ):
|
||||
if x < 3 or y < 3:
|
||||
raise Exception( 'Please use 3x3 or greater for compatibility '
|
||||
'with 2.1' )
|
||||
'with 2.1' )
|
||||
hosts, switches, dpid = {}, {}, 0
|
||||
# Create and wire interior
|
||||
for i in range( 0, x ):
|
||||
|
||||
+3
-3
@@ -200,7 +200,7 @@ def moveIntfNoRetry( intf, dstNode, printError=False ):
|
||||
return True
|
||||
|
||||
def moveIntf( intf, dstNode, printError=True,
|
||||
retries=3, delaySecs=0.001 ):
|
||||
retries=3, delaySecs=0.001 ):
|
||||
"""Move interface to node, retrying on failure.
|
||||
intf: string, interface
|
||||
dstNode: destination Node
|
||||
@@ -546,13 +546,13 @@ def waitListening( client=None, server='127.0.0.1', port=80, timeout=None ):
|
||||
"""Wait until server is listening on port.
|
||||
returns True if server is listening"""
|
||||
runCmd = ( client.cmd if client else
|
||||
partial( quietRun, shell=True ) )
|
||||
partial( quietRun, shell=True ) )
|
||||
if not runCmd( 'which telnet' ):
|
||||
raise Exception('Could not find telnet' )
|
||||
# pylint: disable=maybe-no-member
|
||||
serverIP = server if isinstance( server, basestring ) else server.IP()
|
||||
cmd = ( 'sh -c "echo A | telnet -e A %s %s"' %
|
||||
( serverIP, port ) )
|
||||
( serverIP, port ) )
|
||||
time = 0
|
||||
while 'Connected' not in runCmd( cmd ):
|
||||
if timeout:
|
||||
|
||||
Reference in New Issue
Block a user