Add cleanup and fix pylint errors

This commit is contained in:
Bob Lantz
2014-12-02 22:58:57 -08:00
parent c45bfab318
commit 03ef55672d
+27 -11
View File
@@ -20,16 +20,23 @@ class testSwitchDpidAssignmentCommon ( object ):
switchClass = None # overridden in subclasses switchClass = None # overridden in subclasses
def tearDown( self ):
"Clean up if necessary"
if sys.exc_info != ( None, None, None ):
cleanup()
def testDefaultDpid ( self ): def testDefaultDpid ( self ):
"""Verify that the default dpid is assigned using a valid provided """Verify that the default dpid is assigned using a valid provided
canonical switchname if no dpid is passed in switch creation.""" canonical switchname if no dpid is passed in switch creation."""
switch = Mininet( Topo(), self.switchClass, Host, Controller ).addSwitch( 's1' ) switch = Mininet( Topo(),
self.switchClass, Host, Controller ).addSwitch( 's1' )
self.assertEqual( switch.defaultDpid(), switch.dpid ) self.assertEqual( switch.defaultDpid(), switch.dpid )
def testActualDpidAssignment( self ): def testActualDpidAssignment( self ):
"""Verify that Switch dpid is the actual dpid assigned if dpid is """Verify that Switch dpid is the actual dpid assigned if dpid is
passed in switch creation.""" passed in switch creation."""
switch = Mininet( Topo(), self.switchClass, Host, Controller ).addSwitch( 'A', dpid = '000000000000ABCD' ) switch = Mininet( Topo(), self.switchClass,
Host, Controller ).addSwitch( 'A', dpid = '000000000000ABCD' )
self.assertEqual( switch.dpid, '000000000000ABCD' ) self.assertEqual( switch.dpid, '000000000000ABCD' )
def testDefaultDpidAssignmentFailure( self ): def testDefaultDpidAssignmentFailure( self ):
@@ -37,7 +44,8 @@ class testSwitchDpidAssignmentCommon ( object ):
name of the switch does not contin a digit. Also verify the name of the switch does not contin a digit. Also verify the
exception message.""" exception message."""
with self.assertRaises( Exception ) as raises_cm: with self.assertRaises( Exception ) as raises_cm:
Mininet( Topo(), self.switchClass, Host, Controller ).addSwitch( 'A' ) Mininet( Topo(), self.switchClass,
Host, Controller ).addSwitch( 'A' )
self.assertEqual(raises_cm.exception.message, 'Unable to derive ' self.assertEqual(raises_cm.exception.message, 'Unable to derive '
'default datapath ID - please either specify a dpid ' 'default datapath ID - please either specify a dpid '
'or use a canonical switch name such as s23.') 'or use a canonical switch name such as s23.')
@@ -47,17 +55,21 @@ class testSwitchDpidAssignmentCommon ( object ):
16 - len(hex of first string of contiguous digits passed in switch 16 - len(hex of first string of contiguous digits passed in switch
name) 0's followed by hex of first string of contiguous digits passed name) 0's followed by hex of first string of contiguous digits passed
in switch name.""" in switch name."""
switch = Mininet( Topo(), self.switchClass, Host, Controller ).addSwitch( 's123' ) switch = Mininet( Topo(), self.switchClass,
Host, Controller ).addSwitch( 's123' )
dpid = hex( int(re.findall( r'\d+', switch.name ) [0]) ) [ 2: ] dpid = hex( int(re.findall( r'\d+', switch.name ) [0]) ) [ 2: ]
try: try:
if issubclass(UserSwitch, self.switchClass): if issubclass(UserSwitch, self.switchClass):
# Dpid lenght of UserSwitch = 12 # Dpid lenght of UserSwitch = 12
self.assertEqual( switch.dpid, '0' * (12 - len(dpid)) + str(dpid) ) self.assertEqual( switch.dpid,
'0' * (12 - len(dpid)) + str(dpid) )
else: else:
self.assertEqual( switch.dpid, '0' * (16 - len(dpid)) + str(dpid) ) self.assertEqual( switch.dpid,
'0' * (16 - len(dpid)) + str(dpid) )
except TypeError: except TypeError:
# Switch is OVS User Switch # Switch is OVS User Switch
self.assertEqual( switch.dpid, '0' * (16 - len(dpid)) + str(dpid) ) self.assertEqual( switch.dpid,
'0' * (16 - len(dpid)) + str(dpid) )
class testSwitchOVSKernel( testSwitchDpidAssignmentCommon, unittest.TestCase ): class testSwitchOVSKernel( testSwitchDpidAssignmentCommon, unittest.TestCase ):
@@ -68,18 +80,22 @@ class testSwitchOVSUser( testSwitchDpidAssignmentCommon, unittest.TestCase ):
"""Test dpid assignnment of OVS User Switch.""" """Test dpid assignnment of OVS User Switch."""
switchClass = partial(OVSSwitch, datapath = 'user') switchClass = partial(OVSSwitch, datapath = 'user')
@unittest.skipUnless( quietRun( 'which ovs-openflowd' ), 'OVS Legacy Kernel switch is not installed' ) @unittest.skipUnless( quietRun( 'which ovs-openflowd' ),
class testSwitchOVSLegacyKernel( testSwitchDpidAssignmentCommon, unittest.TestCase ): 'OVS Legacy Kernel switch is not installed' )
class testSwitchOVSLegacyKernel( testSwitchDpidAssignmentCommon,
unittest.TestCase ):
"""Test dpid assignnment of OVS Legacy Kernel Switch.""" """Test dpid assignnment of OVS Legacy Kernel Switch."""
switchClass = OVSLegacyKernelSwitch switchClass = OVSLegacyKernelSwitch
@unittest.skipUnless( quietRun( 'which ivs-ctl' ), 'IVS switch is not installed' ) @unittest.skipUnless( quietRun( 'which ivs-ctl' ), 'IVS switch is not installed' )
class testSwitchIVS( testSwitchDpidAssignmentCommon, unittest.TestCase ): class testSwitchIVS( testSwitchDpidAssignmentCommon,
unittest.TestCase ):
"""Test dpid assignment of IVS switch.""" """Test dpid assignment of IVS switch."""
switchClass = IVSSwitch switchClass = IVSSwitch
@unittest.skipUnless( quietRun( 'which ofprotocol' ), 'Reference user switch is not installed' ) @unittest.skipUnless( quietRun( 'which ofprotocol' ), 'Reference user switch is not installed' )
class testSwitchUserspace( testSwitchDpidAssignmentCommon, unittest.TestCase ): class testSwitchUserspace( testSwitchDpidAssignmentCommon,
unittest.TestCase ):
"""Test dpid assignment of Userspace switch.""" """Test dpid assignment of Userspace switch."""
switchClass = UserSwitch switchClass = UserSwitch