Make cleanup a param of mn, not a separate script
Also switch from print to info statements, to enable a non-verbose clean. Instead of 'mnclean', now run 'mn -c'.
This commit is contained in:
@@ -16,6 +16,7 @@ import os.path
|
||||
import sys
|
||||
import time
|
||||
|
||||
from mininet.clean import cleanup
|
||||
from mininet.log import lg, LEVELS, info
|
||||
from mininet.net import Mininet, init
|
||||
from mininet.node import KernelSwitch, Host, Controller, ControllerParams, NOX
|
||||
@@ -144,6 +145,8 @@ class MininetRunner( object ):
|
||||
opts.add_option( '--topo', type='string', default=TOPODEF,
|
||||
help='[' + ' '.join( TOPOS.keys() ) + '],arg1,arg2,'
|
||||
'...argN')
|
||||
opts.add_option( '--clean', '-c', action='store_true',
|
||||
default=False, help='clean and exit' )
|
||||
opts.add_option( '--custom', type='string', default=None,
|
||||
help='read custom topo and node params from .py file' )
|
||||
opts.add_option( '--test', type='choice', choices=TESTS,
|
||||
@@ -184,6 +187,10 @@ class MininetRunner( object ):
|
||||
def begin( self ):
|
||||
"Create and run mininet."
|
||||
|
||||
if self.options.clean:
|
||||
cleanup()
|
||||
exit()
|
||||
|
||||
start = time.time()
|
||||
|
||||
topo = buildTopo( self.options.topo )
|
||||
|
||||
Executable → Regular
+9
-10
@@ -14,17 +14,19 @@ nothing irreplaceable!
|
||||
|
||||
from subprocess import Popen, PIPE
|
||||
|
||||
from mininet.log import info
|
||||
from mininet.xterm import cleanUpScreens
|
||||
|
||||
def sh( cmd ):
|
||||
"Print a command and send it to the shell"
|
||||
print cmd
|
||||
info( cmd + '\n' )
|
||||
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"
|
||||
info("*** Removing excess controllers/ofprotocols/ofdatapaths/pings/noxes"
|
||||
"\n")
|
||||
zombies = 'controller ofprotocol ofdatapath ping nox_core lt-nox_core '
|
||||
zombies += 'udpbwtest'
|
||||
# Note: real zombie processes can't actually be killed, since they
|
||||
@@ -32,25 +34,22 @@ def cleanup():
|
||||
# you can't connect to them either, so they're mostly harmless.
|
||||
sh( 'killall -9 ' + zombies + ' 2> /dev/null' )
|
||||
|
||||
print "*** Removing junk from /tmp"
|
||||
info("*** Removing junk from /tmp\n")
|
||||
sh( 'rm -f /tmp/vconn* /tmp/vlogs* /tmp/*.out /tmp/*.log' )
|
||||
|
||||
print "*** Removing old screen sessions"
|
||||
info("*** Removing old screen sessions")
|
||||
cleanUpScreens()
|
||||
|
||||
print "*** Removing excess kernel datapaths"
|
||||
info("*** Removing excess kernel datapaths\n")
|
||||
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"
|
||||
info("*** Removing all links of the pattern foo-ethX\n")
|
||||
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()
|
||||
info("*** Cleanup complete.\n")
|
||||
Reference in New Issue
Block a user