From b2fcab827df2555f7453aa6e5658a52aecac2c07 Mon Sep 17 00:00:00 2001 From: Bob Lantz <rlantz@cs.stanford.edu> Date: Tue, 2 Dec 2014 22:58:10 -0800 Subject: [PATCH] Add cleanup and fix pylint errors --- mininet/test/test_hifi.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/mininet/test/test_hifi.py b/mininet/test/test_hifi.py index 82d6da5e..c314630c 100755 --- a/mininet/test/test_hifi.py +++ b/mininet/test/test_hifi.py @@ -4,6 +4,7 @@ Test creation and pings for topologies with link and/or CPU options.""" import unittest +import sys from functools import partial from mininet.net import Mininet @@ -13,6 +14,7 @@ from mininet.topo import Topo from mininet.log import setLogLevel from mininet.util import quietRun +from mininet.clean import cleanup # Number of hosts for each test N = 2 @@ -40,6 +42,11 @@ class testOptionsTopoCommon( object ): switchClass = None # overridden in subclasses + def tearDown( self ): + "Clean up if necessary" + if sys.exc_info != ( None, None, None ): + cleanup() + def runOptionsTopoTest( self, n, msg, hopts=None, lopts=None ): "Generic topology-with-options test runner." mn = Mininet( topo=SingleSwitchOptionsTopo( n=n, hopts=hopts, @@ -96,7 +103,8 @@ def testCPULimits( self ): results = mn.runCpuLimitTest( cpu=CPU_FRACTION ) mn.stop() hostUsage = '\n'.join( 'h%s: %s' % - ( n + 1, results[ ( n - 1 ) * 5: ( n * 5 ) - 1 ] ) + ( n + 1, + results[ (n - 1) * 5 : (n * 5) - 1 ] ) for n in range( N ) ) hoptsStr = ', '.join( '%s: %s' % ( opt, value ) for opt, value in hopts.items() ) @@ -106,7 +114,8 @@ def testCPULimits( self ): 'hopts = %s\n' 'host = CPULimitedHost\n' 'Switch = %s\n' - % ( CPU_FRACTION * 100, hostUsage, N, hoptsStr, self.switchClass ) ) + % ( CPU_FRACTION * 100, hostUsage, N, hoptsStr, + self.switchClass ) ) for pct in results: #divide cpu by 100 to convert from percentage to fraction self.assertWithinTolerance( pct/100, CPU_FRACTION, @@ -115,7 +124,8 @@ def testCPULimits( self ): def testLinkBandwidth( self ): "Verify that link bandwidths are accurate within a bound." if self.switchClass is UserSwitch: - self.skipTest ( 'UserSwitch has very poor performance, so skip for now' ) + self.skipTest ( 'UserSwitch has very poor performance -' + ' skipping for now' ) BW = 5 # Mbps BW_TOLERANCE = 0.8 # BW fraction below which test should fail # Verify ability to create limited-link topo first; @@ -124,7 +134,7 @@ def testLinkBandwidth( self ): mn = Mininet( SingleSwitchOptionsTopo( n=N, lopts=lopts ), link=TCLink, switch=self.switchClass, waitConnected=True ) - bw_strs = mn.run( mn.iperf, format='m' ) + bw_strs = mn.run( mn.iperf, fmt='m' ) loptsStr = ', '.join( '%s: %s' % ( opt, value ) for opt, value in lopts.items() ) msg = ( '\nTesting link bandwidth limited to %d Mbps per link\n' @@ -160,12 +170,12 @@ def testLinkDelay( self ): mn.stop() test_outputs = ping_delays[0] # Ignore unused variables below - # pylint: disable-msg=W0612 + # pylint: disable=W0612 node, dest, ping_outputs = test_outputs sent, received, rttmin, rttavg, rttmax, rttdev = ping_outputs pingFailMsg = 'sent %s pings, only received %s' % ( sent, received ) self.assertEqual( sent, received, msg=pingFailMsg ) - # pylint: enable-msg=W0612 + # pylint: enable=W0612 loptsStr = ', '.join( '%s: %s' % ( opt, value ) for opt, value in lopts.items() ) msg = ( '\nTesting Link Delay of %s ms\n' @@ -212,7 +222,8 @@ def testLinkLoss( self ): 'lopts = %s\n' 'host = default\n' 'switch = %s\n' - % ( LOSS_PERCENT, dropped_total, N, loptsStr, self.switchClass ) ) + % ( LOSS_PERCENT, dropped_total, N, loptsStr, + self.switchClass ) ) self.assertGreater( dropped_total, 0, msg ) -- GitLab