More pylint changes

This commit is contained in:
Bob Lantz
2014-12-04 00:51:05 -08:00
parent b905dddf19
commit 18aab5b786
17 changed files with 952 additions and 897 deletions
+26 -16
View File
@@ -123,7 +123,8 @@ class RemoteMixin( object ):
**kwargs: see Node()"""
# We connect to servers by IP address
self.server = server if server else 'localhost'
self.serverIP = serverIP if serverIP else self.findServerIP( self.server )
self.serverIP = ( serverIP if serverIP
else self.findServerIP( self.server ) )
self.user = user if user else self.findUser()
if controlPath is True:
# Set a default control path for shared SSH connections
@@ -143,21 +144,20 @@ class RemoteMixin( object ):
self.dest = None
self.sshcmd = []
self.isRemote = False
# Satisfy pylint
self.shell, self.pid, self.cmd = None, None, None
super( RemoteMixin, self ).__init__( name, **kwargs )
@staticmethod
def findUser():
"Try to return logged-in (usually non-root) user"
try:
return (
# If we're running sudo
return os.environ[ 'SUDO_USER' ]
except:
try:
# Logged-in user (if we have a tty)
return quietRun( 'who am i' ).split()[ 0 ]
except:
# Give up and return effective user
return quietRun( 'whoami' )
os.environ.get( 'SUDO_USER', False ) or
# Logged-in user (if we have a tty)
( quietRun( 'who am i' ).split() or [ False ] )[ 0 ] or
# Give up and return effective user
quietRun( 'whoami' ) )
# Determine IP address of local host
_ipMatchRegex = re.compile( r'\d+\.\d+\.\d+\.\d+' )
@@ -187,6 +187,8 @@ class RemoteMixin( object ):
self.pid = int( self.cmd( 'echo $$' ) )
def finishInit( self ):
"Wait for split initialization to complete"
assert self # please pylint
self.pid = int( self.waitOutput() )
def rpopen( self, *cmd, **opts ):
@@ -282,7 +284,8 @@ class RemoteOVSSwitch( RemoteMixin, OVSSwitch ):
cls = type( self )
if self.server not in cls.OVSVersions:
vers = self.cmd( 'ovs-vsctl --version' )
cls.OVSVersions[ self.server ] = re.findall( r'\d+\.\d+', vers )[ 0 ]
cls.OVSVersions[ self.server ] = re.findall(
r'\d+\.\d+', vers )[ 0 ]
return ( StrictVersion( cls.OVSVersions[ self.server ] ) <
StrictVersion( '1.10' ) )
@@ -301,6 +304,7 @@ class RemoteLink( Link ):
self.tunnel = None
kwargs.setdefault( 'params1', {} )
kwargs.setdefault( 'params2', {} )
self.cmd = None # satisfy pylint
Link.__init__( self, node1, node2, **kwargs )
def stop( self ):
@@ -324,9 +328,10 @@ class RemoteLink( Link ):
elif server1 == server2:
# Remote link on same remote server
return makeIntfPair( intfname1, intfname2, addr1, addr2,
run=node1.rcmd )
runCmd=node1.rcmd )
# Otherwise, make a tunnel
self.tunnel = self.makeTunnel( node1, node2, intfname1, intfname2, addr1, addr2 )
self.tunnel = self.makeTunnel( node1, node2, intfname1, intfname2,
addr1, addr2 )
return self.tunnel
@staticmethod
@@ -340,7 +345,7 @@ class RemoteLink( Link ):
cmd = 'ip link set %s netns %s' % ( intf, node.pid )
node.rcmd( cmd )
links = node.cmd( 'ip link show' )
if not ( ' %s:' % intf ) in links:
if not ' %s:' % intf in links:
if printError:
error( '*** Error: RemoteLink.moveIntf: ' + intf +
' not successfully moved to ' + node.name + '\n' )
@@ -442,8 +447,9 @@ class Placer( object ):
def place( self, node ):
"Return server for a given node"
assert self, node # satisfy pylint
# Default placement: run locally
return None
return 'localhost'
class RandomPlacer( Placer ):
@@ -451,6 +457,7 @@ class RandomPlacer( Placer ):
def place( self, nodename ):
"""Random placement function
nodename: node name"""
assert nodename # please pylint
# This may be slow with lots of servers
return self.servers[ randrange( 0, len( self.servers ) ) ]
@@ -467,6 +474,7 @@ class RoundRobinPlacer( Placer ):
def place( self, nodename ):
"""Round-robin placement function
nodename: node name"""
assert nodename # please pylint
# This may be slow with lots of servers
server = self.servers[ self.next ]
self.next = ( self.next + 1 ) % len( self.servers )
@@ -626,6 +634,7 @@ class MininetCluster( Mininet ):
def popen( self, cmd ):
"Popen() for server connections"
assert self # please pylint
old = signal( SIGINT, SIG_IGN )
conn = Popen( cmd, stdin=PIPE, stdout=PIPE, close_fds=True )
signal( SIGINT, old )
@@ -649,7 +658,7 @@ class MininetCluster( Mininet ):
cmd = [ 'sudo', '-E', '-u', self.user ]
cmd += self.sshcmd + [ '-n', dest, 'sudo true' ]
debug( ' '.join( cmd ), '\n' )
out, err, code = errRun( cmd )
_out, _err, code = errRun( cmd )
if code != 0:
error( '\nstartConnection: server connection check failed '
'to %s using command:\n%s\n'
@@ -665,6 +674,7 @@ class MininetCluster( Mininet ):
def modifiedaddHost( self, *args, **kwargs ):
"Slightly modify addHost"
assert self # please pylint
kwargs[ 'splitInit' ] = True
return Mininet.addHost( *args, **kwargs )
+16 -10
View File
@@ -5,6 +5,7 @@
from mininet.cli import CLI
from mininet.log import output, error
# pylint: disable=global-statement
nx, graphviz_layout, plt = None, None, None # Will be imported on demand
@@ -23,17 +24,19 @@ class ClusterCLI( CLI ):
colors = colors[ 0 : slen ]
return colors
def do_plot( self, line ):
def do_plot( self, _line ):
"Plot topology colored by node placement"
# Import networkx if needed
global nx, plt
if not nx:
try:
import networkx as nx
import matplotlib.pyplot as plt
import networkx
nx = networkx # satisfy pylint
from matplotlib import pyplot
plt = pyplot # satisfiy pylint
import pygraphviz
assert pygraphviz # silence pyflakes
except:
except ImportError:
error( 'plot requires networkx, matplotlib and pygraphviz - '
'please install them and try again\n' )
return
@@ -53,10 +56,13 @@ class ClusterCLI( CLI ):
pos = nx.graphviz_layout( g )
opts = { 'ax': None, 'font_weight': 'bold',
'width': 2, 'edge_color': 'darkblue' }
hcolors = [ color[ getattr( h, 'server', 'localhost' ) ] for h in hosts ]
scolors = [ color[ getattr( s, 'server', 'localhost' ) ] for s in switches ]
nx.draw_networkx( g, pos=pos, nodelist=hosts, node_size=800, label='host',
node_color=hcolors, node_shape='s', **opts )
hcolors = [ color[ getattr( h, 'server', 'localhost' ) ]
for h in hosts ]
scolors = [ color[ getattr( s, 'server', 'localhost' ) ]
for s in switches ]
nx.draw_networkx( g, pos=pos, nodelist=hosts, node_size=800,
label='host', node_color=hcolors, node_shape='s',
**opts )
nx.draw_networkx( g, pos=pos, nodelist=switches, node_size=1000,
node_color=scolors, node_shape='o', **opts )
# Get rid of axes, add title, and show
@@ -68,7 +74,7 @@ class ClusterCLI( CLI ):
plt.title( 'Node Placement', fontweight='bold' )
plt.show()
def do_status( self, line ):
def do_status( self, _line ):
"Report on node shell status"
nodes = self.mn.hosts + self.mn.switches
for node in nodes:
@@ -83,7 +89,7 @@ class ClusterCLI( CLI ):
output( 'All nodes are still running.\n' )
def do_placement( self, line ):
def do_placement( self, _line ):
"Describe node placement"
mn = self.mn
nodes = mn.hosts + mn.switches + mn.controllers
+4 -2
View File
@@ -27,9 +27,11 @@ def limit( bw=10, cpu=.1 ):
info( '*** Testing with', sched, 'bandwidth limiting\n' )
if sched == 'rt':
release = quietRun( 'uname -r' ).strip('\r\n')
output = quietRun( 'grep CONFIG_RT_GROUP_SCHED /boot/config-%s' % release )
output = quietRun( 'grep CONFIG_RT_GROUP_SCHED /boot/config-%s'
% release )
if output == '# CONFIG_RT_GROUP_SCHED is not set\n':
info( '*** RT Scheduler is not enabled in your kernel. Skipping this test\n' )
info( '*** RT Scheduler is not enabled in your kernel. '
'Skipping this test\n' )
continue
host = custom( CPULimitedHost, sched=sched, cpu=cpu )
net = Mininet( topo=myTopo, intf=intf, host=host )
+14 -7
View File
@@ -44,16 +44,23 @@ class LinuxRouter( Node ):
class NetworkTopo( Topo ):
"A simple topology of a router with three subnets (one host in each)."
def build( self, n=2, h=1, **opts ):
def build( self, **opts ):
router = self.addNode( 'r0', cls=LinuxRouter, ip='192.168.1.1/24' )
h1 = self.addHost( 'h1', ip='192.168.1.100/24', defaultRoute='via 192.168.1.1' )
h2 = self.addHost( 'h2', ip='172.16.0.100/12', defaultRoute='via 172.16.0.1' )
h3 = self.addHost( 'h3', ip='10.0.0.100/8', defaultRoute='via 10.0.0.1' )
self.addLink( h1, router, intfName2='r0-eth1', params2={ 'ip' : '192.168.1.1/24' } )
self.addLink( h2, router, intfName2='r0-eth2', params2={ 'ip' : '172.16.0.1/12' } )
self.addLink( h3, router, intfName2='r0-eth3', params2={ 'ip' : '10.0.0.1/8' } )
h1 = self.addHost( 'h1', ip='192.168.1.100/24',
defaultRoute='via 192.168.1.1' )
h2 = self.addHost( 'h2', ip='172.16.0.100/12',
defaultRoute='via 172.16.0.1' )
h3 = self.addHost( 'h3', ip='10.0.0.100/8',
defaultRoute='via 10.0.0.1' )
self.addLink( h1, router, intfName2='r0-eth1',
params2={ 'ip' : '192.168.1.1/24' } )
self.addLink( h2, router, intfName2='r0-eth2',
params2={ 'ip' : '172.16.0.1/12' } )
self.addLink( h3, router, intfName2='r0-eth3',
params2={ 'ip' : '10.0.0.1/8' } )
def run():
"Test linux router"
topo = NetworkTopo()
net = Mininet( topo=topo, controller=None ) # no controller needed
net.start()
+839 -826
View File
File diff suppressed because it is too large Load Diff
+2 -1
View File
@@ -11,7 +11,7 @@ from mininet.net import Mininet
from mininet.topo import Topo
def runMultiLink():
"Create and run multiple link network"
topo = simpleMultiLinkTopo( n=2 )
net = Mininet( topo=topo )
net.start()
@@ -19,6 +19,7 @@ def runMultiLink():
net.stop()
class simpleMultiLinkTopo( Topo ):
"Simple topology with multiple links"
def __init__( self, n, **kwargs ):
Topo.__init__( self, **kwargs )
+1 -2
View File
@@ -27,7 +27,7 @@ from mininet.util import irange
class InternetTopo(Topo):
"Single switch connected to n hosts."
def __init__(self, n=2, h=1, **opts):
def __init__(self, n=2, **opts):
Topo.__init__(self, **opts)
# set up inet switch
@@ -67,4 +67,3 @@ def run():
if __name__ == '__main__':
setLogLevel('info')
run()
+12 -7
View File
@@ -20,9 +20,12 @@ def validatePort( switch, intf ):
else:
return 1
def net():
def testPortNumbering():
"Create a network with 5 hosts."
"""Test port numbering:
Create a network with 5 hosts (using Mininet's
mid-level API) and check that implicit and
explicit port numbering works as expected."""
net = Mininet( controller=Controller )
@@ -45,18 +48,21 @@ def net():
net.addLink( h2, s1 )
net.addLink( h3, s1 )
net.addLink( h4, s1 )
net.addLink( h5, s1, port1 = 1, port2 = 9 ) # specify a different port to connect host 5 to on the switch.
# specify a different port to connect host 5 to on the switch.
net.addLink( h5, s1, port1=1, port2= 9)
info( '*** Starting network\n' )
net.start()
# print the interfaces and their port numbers
info( '\n*** printing and validating the ports running on each interface\n' )
info( '\n*** printing and validating the ports '
'running on each interface\n' )
for intfs in s1.intfList():
if not intfs.name == "lo":
info( intfs, ': ', s1.ports[intfs],
'\n' )
info ( 'Validating that', intfs, 'is actually on port', s1.ports[intfs], '... ' )
info ( 'Validating that', intfs,
'is actually on port', s1.ports[intfs], '... ' )
if validatePort( s1, intfs ):
info( 'Validated.\n' )
print '\n'
@@ -70,5 +76,4 @@ def net():
if __name__ == '__main__':
setLogLevel( 'info' )
net()
testPortNumbering()
+2 -2
View File
@@ -81,6 +81,6 @@ if __name__ == '__main__':
net = TreeNet( depth=1, fanout=4 )
# get sshd args from the command line or use default args
# useDNS=no -u0 to avoid reverse DNS lookup timeout
opts = ' '.join( sys.argv[ 1: ] ) if len( sys.argv ) > 1 else (
argvopts = ' '.join( sys.argv[ 1: ] ) if len( sys.argv ) > 1 else (
'-D -o UseDNS=no -u0' )
sshd( net, opts=opts )
sshd( net, opts=argvopts )
+1 -1
View File
@@ -35,7 +35,7 @@ class VLANHost( Host ):
"""Configure VLANHost according to (optional) parameters:
vlan: VLAN ID for default interface"""
r = super( Host, self ).config( **params )
r = super( VLANHost, self ).config( **params )
intf = self.defaultIntf()
# remove IP from default, "physical" interface
+2 -4
View File
@@ -727,10 +727,8 @@ class Mininet( object ):
if not quietRun( 'which telnet' ):
error( 'Cannot find telnet in $PATH - required for iperf test' )
return
if not hosts:
hosts = [ self.hosts[ 0 ], self.hosts[ -1 ] ]
else:
assert len( hosts ) == 2
hosts = hosts or [ self.hosts[ 0 ], self.hosts[ -1 ] ]
assert len( hosts ) == 2
client, server = hosts
output( '*** Iperf: testing ' + l4Type + ' bandwidth between ' )
output( "%s and %s\n" % ( client.name, server.name ) )
+3 -6
View File
@@ -888,8 +888,9 @@ class Switch( Node ):
def connected( self ):
"Is the switch connected to a controller? (override this method)"
raise NotImplementedError( "connected() needs to be implemented in"
" Switch subclass %s" % self.__class__ )
warn( "Warning: connected() needs to be implemented in"
" Switch subclass %s\n" % self.__class__ )
return True
def __repr__( self ):
"More informative string representation"
@@ -1290,10 +1291,6 @@ class IVSSwitch( Switch ):
return self.cmd( 'ovs-ofctl ' + ' '.join( args ) +
' tcp:127.0.0.1:%i' % self.listenPort )
def connected( self ):
"For now, return True since we can't tell if we're connected"
return True
class Controller( Node ):
"""A Controller is a Node that is running (or has execed?) an
+3 -3
View File
@@ -26,6 +26,6 @@ def runTests( testDir, verbosity=1 ):
if __name__ == '__main__':
setLogLevel( 'warning' )
# get the directory containing example tests
testDir = os.path.dirname( os.path.realpath( __file__ ) )
verbosity = 2 if '-v' in sys.argv else 1
runTests( testDir, verbosity )
thisdir = os.path.dirname( os.path.realpath( __file__ ) )
vlevel = 2 if '-v' in sys.argv else 1
runTests( testDir=thisdir, verbosity=vlevel )
+3 -2
View File
@@ -42,7 +42,8 @@ class testOptionsTopoCommon( object ):
switchClass = None # overridden in subclasses
def tearDown( self ):
@staticmethod
def tearDown():
"Clean up if necessary"
if sys.exc_info != ( None, None, None ):
cleanup()
@@ -151,7 +152,7 @@ class testOptionsTopoCommon( object ):
# As long as the kernel doesn't wait a long time before
# delivering bytes to the iperf server, its reported data rate
# should be close to the actual receive rate.
serverRate, clientRate = bw_strs
serverRate, _clientRate = bw_strs
bw = float( serverRate.split(' ')[0] )
self.assertWithinTolerance( bw, BW, BW_TOLERANCE, msg )
+4 -2
View File
@@ -23,7 +23,8 @@ class testSingleSwitchCommon( object ):
switchClass = None # overridden in subclasses
def tearDown( self ):
@staticmethod
def tearDown():
"Clean up if necessary"
if sys.exc_info != ( None, None, None ):
cleanup()
@@ -74,7 +75,8 @@ class testLinearCommon( object ):
def testLinear5( self ):
"Ping test on a 5-switch topology"
mn = Mininet( LinearTopo( k=5 ), self.switchClass, Host, Controller, waitConnected=True )
mn = Mininet( LinearTopo( k=5 ), self.switchClass, Host,
Controller, waitConnected=True )
dropped = mn.run( mn.ping )
self.assertEqual( dropped, 0 )
+18 -6
View File
@@ -19,6 +19,9 @@ def tsharkVersion():
versionMatch = re.findall( r'TShark \d+.\d+.\d+', versionStr )[0]
return versionMatch.split()[ 1 ]
# pylint doesn't understand pexpect.match, unfortunately!
# pylint:disable=maybe-no-member
class testWalkthrough( unittest.TestCase ):
"Test Mininet walkthrough"
@@ -33,7 +36,7 @@ class testWalkthrough( unittest.TestCase ):
def testWireshark( self ):
"Use tshark to test the of dissector"
# Satisfy pylint:
# Satisfy pylint
assert self
if StrictVersion( tsharkVersion() ) < StrictVersion( '1.12.0' ):
tshark = pexpect.spawn( 'tshark -i lo -R of' )
@@ -78,7 +81,8 @@ class testWalkthrough( unittest.TestCase ):
node = p.match.group( 1 )
actual.append( node )
p.expect( '\n' )
self.assertEqual( actual.sort(), nodes.sort(), '"nodes" and "dump" differ' )
self.assertEqual( actual.sort(), nodes.sort(),
'"nodes" and "dump" differ' )
p.expect( self.prompt )
p.sendline( 'exit' )
p.wait()
@@ -202,7 +206,8 @@ class testWalkthrough( unittest.TestCase ):
p.expect( self.prompt )
# test delay
p.sendline( 'h1 ping -c 4 h2' )
p.expect( r'rtt min/avg/max/mdev = ([\d\.]+)/([\d\.]+)/([\d\.]+)/([\d\.]+) ms' )
p.expect( r'rtt min/avg/max/mdev = '
r'([\d\.]+)/([\d\.]+)/([\d\.]+)/([\d\.]+) ms' )
delay = float( p.match.group( 2 ) )
self.assertTrue( delay > 40, 'Delay < 40ms' )
self.assertTrue( delay < 45, 'Delay > 40ms' )
@@ -226,10 +231,13 @@ class testWalkthrough( unittest.TestCase ):
def testCustomTopo( self ):
"Start Mininet using a custom topo, then run pingall"
# Satisfy pylint
assert self
custom = os.path.dirname( os.path.realpath( __file__ ) )
custom = os.path.join( custom, '../../custom/topo-2sw-2host.py' )
custom = os.path.normpath( custom )
p = pexpect.spawn( 'mn --custom %s --topo mytopo --test pingall' % custom )
p = pexpect.spawn(
'mn --custom %s --topo mytopo --test pingall' % custom )
p.expect( '0% dropped' )
p.expect( pexpect.EOF )
@@ -331,11 +339,15 @@ class testWalkthrough( unittest.TestCase ):
'Github is not reachable; cannot download Pox' )
def testRemoteController( self ):
"Test Mininet using Pox controller"
# Satisfy pylint
assert self
if not os.path.exists( '/tmp/pox' ):
p = pexpect.spawn( 'git clone https://github.com/noxrepo/pox.git /tmp/pox' )
p = pexpect.spawn(
'git clone https://github.com/noxrepo/pox.git /tmp/pox' )
p.expect( pexpect.EOF )
pox = pexpect.spawn( '/tmp/pox/pox.py forwarding.l2_learning' )
net = pexpect.spawn( 'mn --controller=remote,ip=127.0.0.1,port=6633 --test pingall' )
net = pexpect.spawn(
'mn --controller=remote,ip=127.0.0.1,port=6633 --test pingall' )
net.expect( '0% dropped' )
net.expect( pexpect.EOF )
pox.sendintr()
+2
View File
@@ -427,6 +427,7 @@ def fixLimits():
sysctlTestAndSet( 'net.ipv4.route.max_size', 32768 )
#Increase number of PTYs for nodes
sysctlTestAndSet( 'kernel.pty.max', 20000 )
# pylint: disable=broad-except
except Exception:
warn( "*** Error setting resource limits. "
"Mininet's performance may be affected.\n" )
@@ -549,6 +550,7 @@ def waitListening( client=None, server='127.0.0.1', port=80, timeout=None ):
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 ) )