More pylint fixes...

This commit is contained in:
Bob Lantz
2014-12-04 02:57:36 -08:00
parent 18aab5b786
commit 4965421215
4 changed files with 41 additions and 29 deletions
+23 -12
View File
@@ -25,7 +25,8 @@ from mininet.cli import CLI
from mininet.log import lg, LEVELS, info, debug, warn, error from mininet.log import lg, LEVELS, info, debug, warn, error
from mininet.net import Mininet, MininetWithControlNet, VERSION from mininet.net import Mininet, MininetWithControlNet, VERSION
from mininet.node import ( Host, CPULimitedHost, Controller, OVSController, from mininet.node import ( Host, CPULimitedHost, Controller, OVSController,
RYU, NOX, RemoteController, findController, DefaultController, RYU, NOX, RemoteController, findController,
DefaultController,
UserSwitch, OVSSwitch, OVSBridge, UserSwitch, OVSSwitch, OVSBridge,
OVSLegacyKernelSwitch, IVSSwitch ) OVSLegacyKernelSwitch, IVSSwitch )
from mininet.nodelib import LinuxBridge from mininet.nodelib import LinuxBridge
@@ -132,7 +133,7 @@ class MininetRunner( object ):
self.setup() self.setup()
self.begin() self.begin()
def custom( self, option, opt_str, value, parser ): def custom( self, _option, _opt_str, value, _parser ):
"""Parse custom file and add params. """Parse custom file and add params.
option: option e.g. --custom option: option e.g. --custom
opt_str: option string e.g. --custom opt_str: option string e.g. --custom
@@ -168,9 +169,12 @@ class MininetRunner( object ):
# Add or modify global variable or class # Add or modify global variable or class
globals()[ name ] = value globals()[ name ] = value
def setNat( self, option, opt_str, value, parser ): def setNat( self, _option, opt_str, value, parser ):
"Set NAT option(s)"
assert self # satisfy pylint
parser.values.nat = True parser.values.nat = True
if parser.rargs and parser.rargs[ 0 ][ 0 ] != '-': #first arg, first char != '-' # first arg, first char != '-'
if parser.rargs and parser.rargs[ 0 ][ 0 ] != '-':
value = parser.rargs.pop( 0 ) value = parser.rargs.pop( 0 )
_, args, kwargs = splitArgs( opt_str + ',' + value ) _, args, kwargs = splitArgs( opt_str + ',' + value )
parser.values.nat_args = args parser.values.nat_args = args
@@ -201,7 +205,8 @@ class MininetRunner( object ):
default=False, help='clean and exit' ) default=False, help='clean and exit' )
opts.add_option( '--custom', action='callback', opts.add_option( '--custom', action='callback',
callback=self.custom, callback=self.custom,
type='string', help='read custom classes or params from .py file(s)' ) type='string',
help='read custom classes or params from .py file(s)' )
opts.add_option( '--test', type='choice', choices=TESTS, opts.add_option( '--test', type='choice', choices=TESTS,
default=TESTS[ 0 ], default=TESTS[ 0 ],
help='|'.join( TESTS ) ) help='|'.join( TESTS ) )
@@ -231,10 +236,12 @@ class MininetRunner( object ):
default=False, help="pin hosts to CPU cores " default=False, help="pin hosts to CPU cores "
"(requires --host cfs or --host rt)" ) "(requires --host cfs or --host rt)" )
opts.add_option( '--nat', action='callback', callback=self.setNat, opts.add_option( '--nat', action='callback', callback=self.setNat,
help="adds a NAT to the topology that connects Mininet hosts" help="adds a NAT to the topology that"
" to the physical network." " connects Mininet hosts to the physical network."
" Warning: This may route any traffic on the machine that uses Mininet's" " Warning: This may route any traffic on the machine"
" IP subnet into the Mininet network. If you need to change" " that uses Mininet's"
" IP subnet into the Mininet network."
" If you need to change"
" Mininet's IP subnet, see the --ipbase option." ) " Mininet's IP subnet, see the --ipbase option." )
opts.add_option( '--version', action='callback', callback=version, opts.add_option( '--version', action='callback', callback=version,
help='prints the version and exits' ) help='prints the version and exits' )
@@ -265,6 +272,9 @@ class MininetRunner( object ):
% self.options.verbosity ) % self.options.verbosity )
lg.setLogLevel( self.options.verbosity ) lg.setLogLevel( self.options.verbosity )
# Maybe we'll reorganize this someday...
# pylint: disable=too-many-branches,too-many-statements
def begin( self ): def begin( self ):
"Create and run mininet." "Create and run mininet."
@@ -279,15 +289,16 @@ class MininetRunner( object ):
CONTROLLERS[ 'default' ] = findController() CONTROLLERS[ 'default' ] = findController()
if CONTROLLERS[ 'default' ] is None: if CONTROLLERS[ 'default' ] is None:
if self.options.switch == 'default': if self.options.switch == 'default':
# Fall back to OVS Bridge, which does not use an OF controller info( '*** No default OpenFlow controller found '
info( '*** No default OpenFlow controller found for default switch!\n' ) 'for default switch!\n' )
info( '*** Falling back to OVS Bridge\n' ) info( '*** Falling back to OVS Bridge\n' )
self.options.switch = 'ovsbr' self.options.switch = 'ovsbr'
self.options.controller = 'none' self.options.controller = 'none'
elif self.options.switch in ( 'ovsbr', 'lxbr' ): elif self.options.switch in ( 'ovsbr', 'lxbr' ):
self.options.controller = 'none' self.options.controller = 'none'
else: else:
raise Exception( "Could not find a default controller for switch %s" % raise Exception( "Could not find a default controller "
"for switch %s" %
self.options.switch ) self.options.switch )
topo = buildTopo( TOPOS, self.options.topo ) topo = buildTopo( TOPOS, self.options.topo )
+1 -1
View File
@@ -44,7 +44,7 @@ class LinuxRouter( Node ):
class NetworkTopo( Topo ): class NetworkTopo( Topo ):
"A simple topology of a router with three subnets (one host in each)." "A simple topology of a router with three subnets (one host in each)."
def build( self, **opts ): def build( self, **_opts ):
router = self.addNode( 'r0', cls=LinuxRouter, ip='192.168.1.1/24' ) router = self.addNode( 'r0', cls=LinuxRouter, ip='192.168.1.1/24' )
h1 = self.addHost( 'h1', ip='192.168.1.100/24', h1 = self.addHost( 'h1', ip='192.168.1.100/24',
defaultRoute='via 192.168.1.1' ) defaultRoute='via 192.168.1.1' )
+10 -6
View File
@@ -13,8 +13,10 @@ Controller icon from http://semlabs.co.uk/
OpenFlow icon from https://www.opennetworking.org/ OpenFlow icon from https://www.opennetworking.org/
""" """
# For now, tolerate long lines and long module # Miniedit needs some work in order to pass pylint...
# pylint: disable=line-too-long,too-many-lines # pylint: disable=line-too-long,too-many-lines,too-many-branches
# pylint: disable=too-many-statements,attribute-defined-outside-init
# pylint: disable=missing-docstring
MINIEDIT_VERSION = '2.2.0.1' MINIEDIT_VERSION = '2.2.0.1'
@@ -1573,7 +1575,7 @@ class MiniEdit( Frame ):
self.createDataLinkBindings() self.createDataLinkBindings()
self.link = self.linkWidget = None self.link = self.linkWidget = None
f.close f.close()
def findWidgetByName( self, name ): def findWidgetByName( self, name ):
for widget in self.widgetToItem: for widget in self.widgetToItem:
@@ -2624,8 +2626,10 @@ class MiniEdit( Frame ):
# Ultimately we will either want to use a topo or # Ultimately we will either want to use a topo or
# mininet object here, probably. # mininet object here, probably.
def addLink( self, source, dest, linktype='data', linkopts={} ): def addLink( self, source, dest, linktype='data', linkopts=None ):
"Add link to model." "Add link to model."
if linkopts is None:
linkopts = {}
source.links[ dest ] = self.link source.links[ dest ] = self.link
dest.links[ source ] = self.link dest.links[ source ] = self.link
self.links[ self.link ] = {'type' :linktype, self.links[ self.link ] = {'type' :linktype,
@@ -3142,7 +3146,7 @@ class MiniEdit( Frame ):
return return
self.net.nameToNode[ name ].cmd( 'iperf -s -p 5001 &' ) self.net.nameToNode[ name ].cmd( 'iperf -s -p 5001 &' )
""" BELOW HERE IS THE TOPOLOGY IMPORT CODE """ ### BELOW HERE IS THE TOPOLOGY IMPORT CODE ###
def parseArgs( self ): def parseArgs( self ):
"""Parse command-line args and return options object. """Parse command-line args and return options object.
@@ -3562,7 +3566,7 @@ def addDictOption( opts, choicesDict, default, name, helpStr=None ):
if __name__ == '__main__': if __name__ == '__main__':
setLogLevel( 'info' ) setLogLevel( 'info' )
app = MiniEdit() app = MiniEdit()
""" import topology if specified """ ### import topology if specified ###
app.parseArgs() app.parseArgs()
app.importTopo() app.importTopo()
+7 -10
View File
@@ -30,8 +30,9 @@ from mininet.util import quietRun
from mininet.log import error from mininet.log import error
class VLANHost( Host ): class VLANHost( Host ):
"Host connected to VLAN interface"
def config( self, vlan=100, **params ): def config( self, vlan=100, **params ):
"""Configure VLANHost according to (optional) parameters: """Configure VLANHost according to (optional) parameters:
vlan: VLAN ID for default interface""" vlan: VLAN ID for default interface"""
@@ -90,7 +91,7 @@ class VLANStarTopo( Topo ):
self.addLink( h, s1 ) self.addLink( h, s1 )
def exampleCustomTags( vlan ): def exampleCustomTags():
"""Simple example that exercises VLANStarTopo""" """Simple example that exercises VLANStarTopo"""
net = Mininet( topo=VLANStarTopo() ) net = Mininet( topo=VLANStarTopo() )
@@ -110,16 +111,12 @@ if __name__ == '__main__':
setLogLevel( 'info' ) setLogLevel( 'info' )
if not quietRun( 'which vconfig' ): if not quietRun( 'which vconfig' ):
error( "Cannot find command 'vconfig'\nThe packge", error( "Cannot find command 'vconfig'\nThe package",
"'vlan' is required in Ubuntu or Debian,", "'vlan' is required in Ubuntu or Debian,",
"or 'vconfig' in Fedora\n" ) "or 'vconfig' in Fedora\n" )
exit() exit()
try:
vlan = int( sys.argv[ 1 ] )
except Exception:
vlan = None
if vlan: if len( sys.argv ) >= 2:
exampleAllHosts( vlan ) exampleAllHosts( vlan=int( sys.argv[ 1 ] ) )
else: else:
exampleCustomTags( vlan ) exampleCustomTags()