Enable TESTS={'mytest':test} in --custom files

This commit is contained in:
Bob Lantz
2016-05-11 19:30:18 -07:00
parent 475bb4d911
commit e6b0430a87
+31 -26
View File
@@ -88,14 +88,15 @@ LINKS = { 'default': Link,
'ovs': OVSLink } 'ovs': OVSLink }
# optional tests to run # Names of tests that are Mininet() methods
TESTS = [ 'cli', 'build', 'pingall', 'pingpair', 'iperf', 'all', 'iperfudp', TESTNAMES = [ 'cli', 'build', 'pingall', 'pingpair', 'iperf', 'all', 'iperfudp',
'none' ] 'none' ]
ALTSPELLING = { 'pingall': 'pingAll', # Map to alternate functions and/or spellings of Mininet() methods
'pingpair': 'pingPair', TESTS = { 'pingall': 'pingAll',
'iperfudp': 'iperfUdp', 'pingpair': 'pingPair',
'iperfUDP': 'iperfUdp' } 'iperfudp': 'iperfUdp',
'iperfUDP': 'iperfUdp' }
def addDictOption( opts, choicesDict, default, name, **kwargs ): def addDictOption( opts, choicesDict, default, name, **kwargs ):
@@ -158,7 +159,8 @@ class MininetRunner( object ):
def setCustom( self, name, value ): def setCustom( self, name, value ):
"Set custom parameters for MininetRunner." "Set custom parameters for MininetRunner."
if name in ( 'topos', 'switches', 'hosts', 'controllers', 'links' ): if name in ( 'topos', 'switches', 'hosts', 'controllers', 'links'
'testnames', 'tests' ):
# Update dictionaries # Update dictionaries
param = name.upper() param = name.upper()
globals()[ param ].update( value ) globals()[ param ].update( value )
@@ -208,10 +210,9 @@ class MininetRunner( object ):
type='string', type='string',
help='read custom classes or params from .py file(s)' help='read custom classes or params from .py file(s)'
) )
testList = TESTNAMES + TESTS.keys()
opts.add_option( '--test', type='choice', choices=TESTS, opts.add_option( '--test', default=[], action='append',
default=TESTS[ 0 ], dest='tests', help='|'.join( testList ) )
help='|'.join( TESTS ) )
opts.add_option( '--xterms', '-x', action='store_true', opts.add_option( '--xterms', '-x', action='store_true',
default=False, help='spawn xterms for each node' ) default=False, help='spawn xterms for each node' )
opts.add_option( '--ipbase', '-i', type='string', default='10.0.0.0/8', opts.add_option( '--ipbase', '-i', type='string', default='10.0.0.0/8',
@@ -358,23 +359,27 @@ class MininetRunner( object ):
if self.options.pre: if self.options.pre:
cli( mn, script=self.options.pre ) cli( mn, script=self.options.pre )
test = self.options.test
test = ALTSPELLING.get( test, test )
mn.start() mn.start()
if test == 'none': if not self.options.tests:
pass
elif test == 'all':
mn.waitConnected()
mn.start()
mn.ping()
mn.iperf()
elif test == 'cli':
cli( mn ) cli( mn )
elif test != 'build':
mn.waitConnected() for test in self.options.tests:
getattr( mn, test )() test = TESTS.get( test, test )
if callable( test ): # user added TESTMAP={'mytest': testfn}
test( mn )
elif test == 'none':
pass
elif test == 'all':
mn.waitConnected()
mn.start()
mn.ping()
mn.iperf()
elif test == 'cli':
cli( mn )
elif test != 'build':
mn.waitConnected()
getattr( mn, test )()
if self.options.post: if self.options.post:
cli( mn, script=self.options.post ) cli( mn, script=self.options.post )