Reorganize and pass pylint
This commit is contained in:
Regular → Executable
+34
-38
@@ -5,8 +5,6 @@
|
||||
|
||||
import unittest
|
||||
import sys
|
||||
from functools import partial
|
||||
import re
|
||||
|
||||
from mininet.net import Mininet
|
||||
from mininet.node import Host, Controller
|
||||
@@ -16,13 +14,16 @@ from mininet.log import setLogLevel
|
||||
from mininet.util import quietRun
|
||||
from mininet.clean import cleanup
|
||||
|
||||
class testSwitchDpidAssignmentCommon ( object ):
|
||||
"""Verify Switch dpid assignment."""
|
||||
|
||||
switchClass = None # overridden in subclasses
|
||||
class TestSwitchDpidAssignmentOVS( unittest.TestCase ):
|
||||
"Verify Switch dpid assignment."
|
||||
|
||||
switchClass = OVSSwitch # overridden in subclasses
|
||||
|
||||
def tearDown( self ):
|
||||
"Clean up if necessary"
|
||||
# satisfy pylint
|
||||
assert self
|
||||
if sys.exc_info != ( None, None, None ):
|
||||
cleanup()
|
||||
|
||||
@@ -33,12 +34,19 @@ class testSwitchDpidAssignmentCommon ( object ):
|
||||
self.switchClass, Host, Controller ).addSwitch( 's1' )
|
||||
self.assertEqual( switch.defaultDpid(), switch.dpid )
|
||||
|
||||
def dpidFrom( self, num ):
|
||||
"Compute default dpid from number"
|
||||
fmt = ( '%0' + str( self.switchClass.dpidLen ) + 'x' )
|
||||
return fmt % num
|
||||
|
||||
def testActualDpidAssignment( self ):
|
||||
"""Verify that Switch dpid is the actual dpid assigned if dpid is
|
||||
passed in switch creation."""
|
||||
dpid = self.dpidFrom( 0xABCD )
|
||||
switch = Mininet( Topo(), self.switchClass,
|
||||
Host, Controller ).addSwitch( 'A', dpid = '000000000000ABCD' )
|
||||
self.assertEqual( switch.dpid, '000000000000ABCD' )
|
||||
Host, Controller ).addSwitch(
|
||||
's1', dpid=dpid )
|
||||
self.assertEqual( switch.dpid, dpid )
|
||||
|
||||
def testDefaultDpidAssignmentFailure( self ):
|
||||
"""Verify that Default dpid assignment raises an Exception if the
|
||||
@@ -58,49 +66,37 @@ class testSwitchDpidAssignmentCommon ( object ):
|
||||
in switch name."""
|
||||
switch = Mininet( Topo(), self.switchClass,
|
||||
Host, Controller ).addSwitch( 's123' )
|
||||
dpid = hex( int(re.findall( r'\d+', switch.name ) [0]) ) [ 2: ]
|
||||
try:
|
||||
if issubclass(UserSwitch, self.switchClass):
|
||||
# Dpid lenght of UserSwitch = 12
|
||||
self.assertEqual( switch.dpid,
|
||||
'0' * (12 - len(dpid)) + str(dpid) )
|
||||
else:
|
||||
self.assertEqual( switch.dpid,
|
||||
'0' * (16 - len(dpid)) + str(dpid) )
|
||||
except TypeError:
|
||||
# Switch is OVS User Switch
|
||||
self.assertEqual( switch.dpid,
|
||||
'0' * (16 - len(dpid)) + str(dpid) )
|
||||
|
||||
self.assertEqual( switch.dpid, self.dpidFrom( 123 ) )
|
||||
|
||||
class testSwitchOVSKernel( testSwitchDpidAssignmentCommon, unittest.TestCase ):
|
||||
"""Test dpid assignnment of OVS Kernel Switch."""
|
||||
switchClass = OVSSwitch
|
||||
class OVSUser( OVSSwitch):
|
||||
"OVS User Switch convenience class"
|
||||
def __init__( self, *args, **kwargs ):
|
||||
kwargs.update( datapath='user' )
|
||||
OVSSwitch.__init__( self, *args, **kwargs )
|
||||
|
||||
class testSwitchOVSUser( testSwitchDpidAssignmentCommon, unittest.TestCase ):
|
||||
"""Test dpid assignnment of OVS User Switch."""
|
||||
switchClass = partial(OVSSwitch, datapath = 'user')
|
||||
class testSwitchOVSUser( TestSwitchDpidAssignmentOVS ):
|
||||
"Test dpid assignnment of OVS User Switch."
|
||||
switchClass = OVSUser
|
||||
|
||||
@unittest.skipUnless( quietRun( 'which ovs-openflowd' ),
|
||||
'OVS Legacy Kernel switch is not installed' )
|
||||
class testSwitchOVSLegacyKernel( testSwitchDpidAssignmentCommon,
|
||||
unittest.TestCase ):
|
||||
"""Test dpid assignnment of OVS Legacy Kernel Switch."""
|
||||
class testSwitchOVSLegacyKernel( TestSwitchDpidAssignmentOVS ):
|
||||
"Test dpid assignnment of OVS Legacy Kernel Switch."
|
||||
switchClass = OVSLegacyKernelSwitch
|
||||
|
||||
@unittest.skipUnless( quietRun( 'which ivs-ctl' ), 'IVS switch is not installed' )
|
||||
class testSwitchIVS( testSwitchDpidAssignmentCommon,
|
||||
unittest.TestCase ):
|
||||
"""Test dpid assignment of IVS switch."""
|
||||
@unittest.skipUnless( quietRun( 'which ivs-ctl' ),
|
||||
'IVS switch is not installed' )
|
||||
class testSwitchIVS( TestSwitchDpidAssignmentOVS ):
|
||||
"Test dpid assignment of IVS switch."
|
||||
switchClass = IVSSwitch
|
||||
|
||||
@unittest.skipUnless( quietRun( 'which ofprotocol' ), 'Reference user switch is not installed' )
|
||||
class testSwitchUserspace( testSwitchDpidAssignmentCommon,
|
||||
unittest.TestCase ):
|
||||
"""Test dpid assignment of Userspace switch."""
|
||||
@unittest.skipUnless( quietRun( 'which ofprotocol' ),
|
||||
'Reference user switch is not installed' )
|
||||
class testSwitchUserspace( TestSwitchDpidAssignmentOVS ):
|
||||
"Test dpid assignment of Userspace switch."
|
||||
switchClass = UserSwitch
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'warning' )
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user