Merge "Add unit tests for ip_lib.get_routing_table"
This commit is contained in:
commit
f51c872a12
@ -1306,6 +1306,47 @@ class TestDeviceExists(base.BaseTestCase):
|
||||
self.assertFalse(ip_lib.ensure_device_is_ready("eth0"))
|
||||
|
||||
|
||||
class TestGetRoutingTable(base.BaseTestCase):
|
||||
@mock.patch.object(ip_lib, 'IPWrapper')
|
||||
def _test_get_routing_table(self, version, ip_route_output, expected,
|
||||
mock_ipwrapper):
|
||||
instance = mock_ipwrapper.return_value
|
||||
mock_netns = instance.netns
|
||||
mock_execute = mock_netns.execute
|
||||
mock_execute.return_value = ip_route_output
|
||||
self.assertEqual(expected, ip_lib.get_routing_table(version))
|
||||
|
||||
def test_get_routing_table_4(self):
|
||||
ip_route_output = ("""
|
||||
default via 192.168.3.120 dev wlp3s0 proto static metric 1024
|
||||
10.0.0.0/8 dev tun0 proto static scope link metric 1024
|
||||
""")
|
||||
expected = [{'destination': 'default',
|
||||
'nexthop': '192.168.3.120',
|
||||
'device': 'wlp3s0',
|
||||
'scope': None},
|
||||
{'destination': '10.0.0.0/8',
|
||||
'nexthop': None,
|
||||
'device': 'tun0',
|
||||
'scope': 'link'}]
|
||||
self._test_get_routing_table(4, ip_route_output, expected)
|
||||
|
||||
def test_get_routing_table_6(self):
|
||||
ip_route_output = ("""
|
||||
2001:db8:0:f101::/64 dev tap-1 proto kernel metric 256 pref medium
|
||||
default via 2001:db8:0:f101::4 dev tap-1 metric 1024 pref medium
|
||||
""")
|
||||
expected = [{'destination': '2001:db8:0:f101::/64',
|
||||
'nexthop': None,
|
||||
'device': 'tap-1',
|
||||
'scope': None},
|
||||
{'destination': 'default',
|
||||
'nexthop': '2001:db8:0:f101::4',
|
||||
'device': 'tap-1',
|
||||
'scope': None}]
|
||||
self._test_get_routing_table(6, ip_route_output, expected)
|
||||
|
||||
|
||||
class TestIpNeighCommand(TestIPCmdBase):
|
||||
def setUp(self):
|
||||
super(TestIpNeighCommand, self).setUp()
|
||||
|
Loading…
Reference in New Issue
Block a user