Python 3 compatibility
This commit is contained in:
@@ -901,6 +901,7 @@ class Switch( Node ):
|
|||||||
if nums:
|
if nums:
|
||||||
dpid = hex( int( nums[ 0 ] ) )[ 2: ]
|
dpid = hex( int( nums[ 0 ] ) )[ 2: ]
|
||||||
else:
|
else:
|
||||||
|
self.terminate() # Python 3.6 crash workaround
|
||||||
raise Exception( 'Unable to derive default datapath ID - '
|
raise Exception( 'Unable to derive default datapath ID - '
|
||||||
'please either specify a dpid or use a '
|
'please either specify a dpid or use a '
|
||||||
'canonical switch name such as s23.' )
|
'canonical switch name such as s23.' )
|
||||||
|
|||||||
@@ -30,10 +30,11 @@ class TestSwitchDpidAssignmentOVS( unittest.TestCase ):
|
|||||||
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(),
|
net = Mininet( Topo(), self.switchClass, Host, Controller )
|
||||||
self.switchClass,
|
switch = net.addSwitch( 's1' )
|
||||||
Host, Controller ).addSwitch( 's1' )
|
|
||||||
self.assertEqual( switch.defaultDpid(), switch.dpid )
|
self.assertEqual( switch.defaultDpid(), switch.dpid )
|
||||||
|
net.stop()
|
||||||
|
|
||||||
|
|
||||||
def dpidFrom( self, num ):
|
def dpidFrom( self, num ):
|
||||||
"Compute default dpid from number"
|
"Compute default dpid from number"
|
||||||
@@ -44,31 +45,35 @@ class TestSwitchDpidAssignmentOVS( unittest.TestCase ):
|
|||||||
"""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 )
|
dpid = self.dpidFrom( 0xABCD )
|
||||||
switch = Mininet( Topo(), self.switchClass,
|
net = Mininet( Topo(), self.switchClass, Host, Controller )
|
||||||
Host, Controller ).addSwitch(
|
switch = net.addSwitch( 's1', dpid=dpid )
|
||||||
's1', dpid=dpid )
|
|
||||||
self.assertEqual( switch.dpid, dpid )
|
self.assertEqual( switch.dpid, dpid )
|
||||||
|
net.stop()
|
||||||
|
|
||||||
|
|
||||||
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
|
||||||
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."""
|
||||||
|
net = Mininet( Topo(), self.switchClass, Host, Controller )
|
||||||
with self.assertRaises( Exception ) as raises_cm:
|
with self.assertRaises( Exception ) as raises_cm:
|
||||||
Mininet( Topo(), self.switchClass,
|
net.addSwitch( 'A' )
|
||||||
Host, Controller ).addSwitch( 'A' )
|
self.assertTrue( '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.'
|
||||||
|
in str( raises_cm.exception ) )
|
||||||
|
net.stop()
|
||||||
|
|
||||||
def testDefaultDpidLen( self ):
|
def testDefaultDpidLen( self ):
|
||||||
"""Verify that Default dpid length is 16 characters consisting of
|
"""Verify that Default dpid length is 16 characters consisting of
|
||||||
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,
|
net = Mininet( Topo(), self.switchClass, Host, Controller )
|
||||||
Host, Controller ).addSwitch( 's123' )
|
switch = net.addSwitch( 's123' )
|
||||||
|
|
||||||
self.assertEqual( switch.dpid, self.dpidFrom( 123 ) )
|
self.assertEqual( switch.dpid, self.dpidFrom( 123 ) )
|
||||||
|
net.stop()
|
||||||
|
|
||||||
|
|
||||||
class OVSUser( OVSSwitch):
|
class OVSUser( OVSSwitch):
|
||||||
"OVS User Switch convenience class"
|
"OVS User Switch convenience class"
|
||||||
@@ -95,3 +100,4 @@ class testSwitchUserspace( TestSwitchDpidAssignmentOVS ):
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
setLogLevel( 'warning' )
|
setLogLevel( 'warning' )
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
cleanup()
|
||||||
|
|||||||
Reference in New Issue
Block a user