Commit f92007e0 authored by Martín Ferrari's avatar Martín Ferrari

More tests. Remove add/remove route checks, it is really complicated to...

More tests. Remove add/remove route checks, it is really complicated to emulate what the kernel checks
parent 546472f4
...@@ -638,13 +638,15 @@ def get_route_data(): ...@@ -638,13 +638,15 @@ def get_route_data():
return [x for x in get_all_route_data() if x.tipe == 'unicast'] return [x for x in get_all_route_data() if x.tipe == 'unicast']
def add_route(route): def add_route(route):
if route in get_all_route_data(): # Cannot really test this
raise ValueError('Route already exists') #if route in get_all_route_data():
# raise ValueError('Route already exists')
_add_del_route('add', route) _add_del_route('add', route)
def del_route(route): def del_route(route):
if route not in get_all_route_data(): # Cannot really test this
raise ValueError('Route does not exist') #if route not in get_all_route_data():
# raise ValueError('Route does not exist')
_add_del_route('del', route) _add_del_route('del', route)
def _add_del_route(action, route): def _add_del_route(action, route):
......
...@@ -9,9 +9,9 @@ class TestRouting(unittest.TestCase): ...@@ -9,9 +9,9 @@ class TestRouting(unittest.TestCase):
node = netns.Node(nonetns = True) node = netns.Node(nonetns = True)
routes = node.get_routes() routes = node.get_routes()
if(len(routes)): if(len(routes)):
self.assertRaises(ValueError, node.add_route, routes[0]) self.assertRaises(RuntimeError, node.add_route, routes[0])
routes[0].interface += 1 # should be enough to make it unique routes[0].interface += 1 # should be enough to make it unique
self.assertRaises(ValueError, node.del_route, routes[0]) self.assertRaises(RuntimeError, node.del_route, routes[0])
@test_util.skipUnless(os.getuid() == 0, "Test requires root privileges") @test_util.skipUnless(os.getuid() == 0, "Test requires root privileges")
def test_routing(self): def test_routing(self):
...@@ -21,7 +21,9 @@ class TestRouting(unittest.TestCase): ...@@ -21,7 +21,9 @@ class TestRouting(unittest.TestCase):
if0 = node.add_if() if0 = node.add_if()
if0.add_v4_address('10.0.0.1', 24) if0.add_v4_address('10.0.0.1', 24)
if0.up = True if0.up = True
self.assertEquals(len(node.get_routes()), 1) routes = node.get_routes()
self.assertEquals(routes, [node.route(prefix = '10.0.0.0',
prefix_len = 24, interface = if0)])
node.add_route(nexthop = '10.0.0.2') # default route node.add_route(nexthop = '10.0.0.2') # default route
node.add_route(prefix = '10.1.0.0', prefix_len = 16, node.add_route(prefix = '10.1.0.0', prefix_len = 16,
...@@ -29,7 +31,20 @@ class TestRouting(unittest.TestCase): ...@@ -29,7 +31,20 @@ class TestRouting(unittest.TestCase):
node.add_route(prefix = '11.1.0.1', prefix_len = 32, interface = if0) node.add_route(prefix = '11.1.0.1', prefix_len = 32, interface = if0)
routes = node.get_routes() routes = node.get_routes()
# FIXME:... self.assertTrue(node.route(nexthop = '10.0.0.2', interface = if0)
in routes)
self.assertTrue(node.route(prefix = '10.1.0.0', prefix_len = 16,
nexthop = '10.0.0.3', interface = if0) in routes)
self.assertTrue(node.route(prefix = '11.1.0.1', prefix_len = 32,
interface = if0) in routes)
node.del_route(nexthop = '10.0.0.2') # default route
node.del_route(prefix = '10.1.0.0', prefix_len = 16,
nexthop = '10.0.0.3')
node.del_route(prefix = '11.1.0.1', prefix_len = 32, interface = if0)
node.del_route(prefix = '10.0.0.0', prefix_len = 24, interface = if0)
self.assertEquals(node.get_routes(), [])
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment