Add static code checking for style and errors
This required a change to logging, which now uses a singleton pattern. For all future checkins, 'make codecheck' should pass.
This commit is contained in:
+33
-33
@@ -12,47 +12,47 @@ irreplaceable!
|
||||
"""
|
||||
|
||||
from subprocess import Popen, PIPE
|
||||
import re
|
||||
|
||||
from mininet.util import quietRun
|
||||
from mininet.xterm import cleanUpScreens
|
||||
|
||||
def sh( cmd ):
|
||||
"Print a command and send it to the shell"
|
||||
print cmd
|
||||
return Popen( [ '/bin/sh', '-c', cmd ],
|
||||
stdout=PIPE ).communicate()[ 0 ]
|
||||
|
||||
|
||||
def sh(cmd):
|
||||
"Print a command and send it to the shell"
|
||||
print cmd
|
||||
return Popen(['/bin/sh', '-c', cmd], stdout=PIPE).communicate()[0]
|
||||
|
||||
|
||||
def cleanup():
|
||||
"""Clean up junk which might be left over from old runs;
|
||||
do fast stuff before slow dp and link removal!"""
|
||||
|
||||
print "*** Removing excess controllers/ofprotocols/ofdatapaths/pings/noxes"
|
||||
zombies = 'controller ofprotocol ofdatapath ping nox_core lt-nox_core '
|
||||
zombies += 'udpbwtest'
|
||||
# Note: real zombie processes can't actually be killed, since they
|
||||
# are already (un)dead. Then again,
|
||||
# you can't connect to them either, so they're mostly harmless.
|
||||
sh( 'killall -9 ' + zombies + ' 2> /dev/null' )
|
||||
"""Clean up junk which might be left over from old runs;
|
||||
do fast stuff before slow dp and link removal!"""
|
||||
|
||||
print "*** Removing junk from /tmp"
|
||||
sh( 'rm -f /tmp/vconn* /tmp/vlogs* /tmp/*.out /tmp/*.log' )
|
||||
print "*** Removing excess controllers/ofprotocols/ofdatapaths/pings/noxes"
|
||||
zombies = 'controller ofprotocol ofdatapath ping nox_core lt-nox_core '
|
||||
zombies += 'udpbwtest'
|
||||
# Note: real zombie processes can't actually be killed, since they
|
||||
# are already (un)dead. Then again,
|
||||
# you can't connect to them either, so they're mostly harmless.
|
||||
sh('killall -9 ' + zombies + ' 2> /dev/null')
|
||||
|
||||
print "*** Removing old screen sessions"
|
||||
cleanUpScreens()
|
||||
print "*** Removing junk from /tmp"
|
||||
sh('rm -f /tmp/vconn* /tmp/vlogs* /tmp/*.out /tmp/*.log')
|
||||
|
||||
print "*** Removing excess kernel datapaths"
|
||||
dps = sh( "ps ax | egrep -o 'dp[0-9]+' | sed 's/dp/nl:/'" ).split( '\n')
|
||||
for dp in dps:
|
||||
if dp != '': sh( 'dpctl deldp ' + dp )
|
||||
|
||||
print "*** Removing all links of the pattern foo-ethX"
|
||||
links = sh( "ip link show | egrep -o '(\w+-eth\w+)'" ).split( '\n' )
|
||||
for link in links:
|
||||
if link != '': sh( "ip link del " + link )
|
||||
print "*** Removing old screen sessions"
|
||||
cleanUpScreens()
|
||||
|
||||
print "*** Cleanup complete."
|
||||
print "*** Removing excess kernel datapaths"
|
||||
dps = sh("ps ax | egrep -o 'dp[0-9]+' | sed 's/dp/nl:/'").split('\n')
|
||||
for dp in dps:
|
||||
if dp != '':
|
||||
sh('dpctl deldp ' + dp)
|
||||
|
||||
print "*** Removing all links of the pattern foo-ethX"
|
||||
links = sh("ip link show | egrep -o '(\w+-eth\w+)'").split('\n')
|
||||
for link in links:
|
||||
if link != '':
|
||||
sh("ip link del " + link)
|
||||
|
||||
print "*** Cleanup complete."
|
||||
|
||||
if __name__ == "__main__":
|
||||
cleanup()
|
||||
cleanup()
|
||||
|
||||
+26
-25
@@ -13,7 +13,7 @@ try:
|
||||
except ImportError:
|
||||
USE_RIPCORD = False
|
||||
|
||||
from mininet.logging_mod import lg, set_loglevel, LEVELS
|
||||
from mininet.logging_mod import lg, LEVELS
|
||||
from mininet.net import Mininet, init
|
||||
from mininet.node import KernelSwitch, Host, Controller, ControllerParams, NOX
|
||||
from mininet.node import RemoteController, UserSwitch
|
||||
@@ -21,43 +21,44 @@ from mininet.topo import SingleSwitchTopo, LinearTopo, SingleSwitchReversedTopo
|
||||
|
||||
# built in topologies, created only when run
|
||||
TOPO_DEF = 'minimal'
|
||||
TOPOS = {'minimal' : (lambda: SingleSwitchTopo(k = 2)),
|
||||
'reversed' : (lambda: SingleSwitchReversedTopo(k = 2)),
|
||||
'single4' : (lambda: SingleSwitchTopo(k = 4)),
|
||||
'single100' : (lambda: SingleSwitchTopo(k = 100)),
|
||||
'linear2' : (lambda: LinearTopo(k = 2)),
|
||||
'linear100' : (lambda: LinearTopo(k = 100))}
|
||||
TOPOS = {'minimal': (lambda: SingleSwitchTopo(k = 2)),
|
||||
'reversed': (lambda: SingleSwitchReversedTopo(k = 2)),
|
||||
'single4': (lambda: SingleSwitchTopo(k = 4)),
|
||||
'single100': (lambda: SingleSwitchTopo(k = 100)),
|
||||
'linear2': (lambda: LinearTopo(k = 2)),
|
||||
'linear100': (lambda: LinearTopo(k = 100))}
|
||||
if USE_RIPCORD:
|
||||
TOPOS_RIPCORD = {
|
||||
'tree16' : (lambda: TreeTopo(depth = 3, fanout = 4)),
|
||||
'tree64' : (lambda: TreeTopo(depth = 4, fanout = 4)),
|
||||
'tree1024' : (lambda: TreeTopo(depth = 3, fanout = 32)),
|
||||
'fattree4' : (lambda: FatTreeTopo(k = 4)),
|
||||
'fattree6' : (lambda: FatTreeTopo(k = 6)),
|
||||
'vl2' : (lambda: VL2Topo(da = 4, di = 4))}
|
||||
'tree16': (lambda: TreeTopo(depth = 3, fanout = 4)),
|
||||
'tree64': (lambda: TreeTopo(depth = 4, fanout = 4)),
|
||||
'tree1024': (lambda: TreeTopo(depth = 3, fanout = 32)),
|
||||
'fattree4': (lambda: FatTreeTopo(k = 4)),
|
||||
'fattree6': (lambda: FatTreeTopo(k = 6)),
|
||||
'vl2': (lambda: VL2Topo(da = 4, di = 4))}
|
||||
TOPOS.update(TOPOS_RIPCORD)
|
||||
|
||||
SWITCH_DEF = 'kernel'
|
||||
SWITCHES = {'kernel' : KernelSwitch,
|
||||
'user' : UserSwitch}
|
||||
SWITCHES = {'kernel': KernelSwitch,
|
||||
'user': UserSwitch}
|
||||
|
||||
HOST_DEF = 'process'
|
||||
HOSTS = {'process' : Host}
|
||||
HOSTS = {'process': Host}
|
||||
|
||||
CONTROLLER_DEF = 'ref'
|
||||
# a and b are the name and inNamespace params.
|
||||
CONTROLLERS = {'ref' : Controller,
|
||||
'nox_dump' : lambda a, b: NOX(a, b, 'packetdump'),
|
||||
'nox_pysw' : lambda a, b: NOX(a, b, 'pyswitch'),
|
||||
'remote' : lambda a, b: None,
|
||||
'none' : lambda a, b: None}
|
||||
CONTROLLERS = {'ref': Controller,
|
||||
'nox_dump': lambda a, b: NOX(a, b, 'packetdump'),
|
||||
'nox_pysw': lambda a, b: NOX(a, b, 'pyswitch'),
|
||||
'remote': lambda a, b: None,
|
||||
'none': lambda a, b: None}
|
||||
|
||||
# optional tests to run
|
||||
TESTS = ['cli', 'build', 'ping_all', 'ping_pair', 'iperf', 'all', 'iperf_udp']
|
||||
|
||||
|
||||
def add_dict_option(opts, choices_dict, default, name, help_str = None):
|
||||
'''Convenience function to add choices dicts to OptionParser.
|
||||
|
||||
|
||||
@param opts OptionParser instance
|
||||
@param choices_dict dictionary of valid choices, must include default
|
||||
@param default default choice key
|
||||
@@ -82,14 +83,14 @@ class MininetRunner(object):
|
||||
def __init__(self):
|
||||
'''Init.'''
|
||||
self.options = None
|
||||
|
||||
|
||||
self.parse_args()
|
||||
self.setup()
|
||||
self.begin()
|
||||
|
||||
def parse_args(self):
|
||||
'''Parse command-line args and return options object.
|
||||
|
||||
|
||||
@return opts parse options dict
|
||||
'''
|
||||
opts = OptionParser()
|
||||
@@ -124,7 +125,7 @@ class MininetRunner(object):
|
||||
'''Setup and validate environment.'''
|
||||
|
||||
# set logging verbosity
|
||||
set_loglevel(self.options.verbosity)
|
||||
lg.set_loglevel(self.options.verbosity)
|
||||
|
||||
# validate environment setup
|
||||
init()
|
||||
|
||||
Reference in New Issue
Block a user