Reorganize and pass pylint
This commit is contained in:
Regular → Executable
+34
-38
@@ -5,8 +5,6 @@
|
|||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
import sys
|
import sys
|
||||||
from functools import partial
|
|
||||||
import re
|
|
||||||
|
|
||||||
from mininet.net import Mininet
|
from mininet.net import Mininet
|
||||||
from mininet.node import Host, Controller
|
from mininet.node import Host, Controller
|
||||||
@@ -16,13 +14,16 @@ from mininet.log import setLogLevel
|
|||||||
from mininet.util import quietRun
|
from mininet.util import quietRun
|
||||||
from mininet.clean import cleanup
|
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 ):
|
def tearDown( self ):
|
||||||
"Clean up if necessary"
|
"Clean up if necessary"
|
||||||
|
# satisfy pylint
|
||||||
|
assert self
|
||||||
if sys.exc_info != ( None, None, None ):
|
if sys.exc_info != ( None, None, None ):
|
||||||
cleanup()
|
cleanup()
|
||||||
|
|
||||||
@@ -33,12 +34,19 @@ class testSwitchDpidAssignmentCommon ( object ):
|
|||||||
self.switchClass, Host, Controller ).addSwitch( 's1' )
|
self.switchClass, Host, Controller ).addSwitch( 's1' )
|
||||||
self.assertEqual( switch.defaultDpid(), switch.dpid )
|
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 ):
|
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."""
|
||||||
|
dpid = self.dpidFrom( 0xABCD )
|
||||||
switch = Mininet( Topo(), self.switchClass,
|
switch = Mininet( Topo(), self.switchClass,
|
||||||
Host, Controller ).addSwitch( 'A', dpid = '000000000000ABCD' )
|
Host, Controller ).addSwitch(
|
||||||
self.assertEqual( switch.dpid, '000000000000ABCD' )
|
's1', dpid=dpid )
|
||||||
|
self.assertEqual( switch.dpid, dpid )
|
||||||
|
|
||||||
def testDefaultDpidAssignmentFailure( self ):
|
def testDefaultDpidAssignmentFailure( self ):
|
||||||
"""Verify that Default dpid assignment raises an Exception if the
|
"""Verify that Default dpid assignment raises an Exception if the
|
||||||
@@ -58,49 +66,37 @@ class testSwitchDpidAssignmentCommon ( object ):
|
|||||||
in switch name."""
|
in switch name."""
|
||||||
switch = Mininet( Topo(), self.switchClass,
|
switch = Mininet( Topo(), self.switchClass,
|
||||||
Host, Controller ).addSwitch( 's123' )
|
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 ):
|
class OVSUser( OVSSwitch):
|
||||||
"""Test dpid assignnment of OVS Kernel Switch."""
|
"OVS User Switch convenience class"
|
||||||
switchClass = OVSSwitch
|
def __init__( self, *args, **kwargs ):
|
||||||
|
kwargs.update( datapath='user' )
|
||||||
|
OVSSwitch.__init__( self, *args, **kwargs )
|
||||||
|
|
||||||
class testSwitchOVSUser( testSwitchDpidAssignmentCommon, unittest.TestCase ):
|
class testSwitchOVSUser( TestSwitchDpidAssignmentOVS ):
|
||||||
"""Test dpid assignnment of OVS User Switch."""
|
"Test dpid assignnment of OVS User Switch."
|
||||||
switchClass = partial(OVSSwitch, datapath = 'user')
|
switchClass = OVSUser
|
||||||
|
|
||||||
@unittest.skipUnless( quietRun( 'which ovs-openflowd' ),
|
@unittest.skipUnless( quietRun( 'which ovs-openflowd' ),
|
||||||
'OVS Legacy Kernel switch is not installed' )
|
'OVS Legacy Kernel switch is not installed' )
|
||||||
class testSwitchOVSLegacyKernel( testSwitchDpidAssignmentCommon,
|
class testSwitchOVSLegacyKernel( TestSwitchDpidAssignmentOVS ):
|
||||||
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' ),
|
||||||
class testSwitchIVS( testSwitchDpidAssignmentCommon,
|
'IVS switch is not installed' )
|
||||||
unittest.TestCase ):
|
class testSwitchIVS( TestSwitchDpidAssignmentOVS ):
|
||||||
"""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' ),
|
||||||
class testSwitchUserspace( testSwitchDpidAssignmentCommon,
|
'Reference user switch is not installed' )
|
||||||
unittest.TestCase ):
|
class testSwitchUserspace( TestSwitchDpidAssignmentOVS ):
|
||||||
"""Test dpid assignment of Userspace switch."""
|
"Test dpid assignment of Userspace switch."
|
||||||
switchClass = UserSwitch
|
switchClass = UserSwitch
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
setLogLevel( 'warning' )
|
setLogLevel( 'warning' )
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
Reference in New Issue
Block a user