Commit 6dae3045 authored by Martín Ferrari's avatar Martín Ferrari

Improve tests

parent 6cfa840c
......@@ -26,7 +26,6 @@ class Node(object):
Node._nextnode += 1
def __del__(self):
print "__del__(%s)" % self
self.shutdown()
def shutdown(self):
......
......@@ -2,12 +2,12 @@
# vim:ts=4:sw=4:et:ai:sts=4
from test_util import get_devs, get_devs_netns
import netns
import netns, test_util
import os
import unittest
class TestInterfaces(unittest.TestCase):
def test_util(self):
def test_utils(self):
devs = get_devs()
# There should be at least loopback!
self.assertTrue(len(devs) > 0)
......@@ -19,6 +19,7 @@ class TestInterfaces(unittest.TestCase):
'bcast': None, 'family': 'inet'
} in devs['lo']['addr'])
@test_util.skipUnless(os.getuid() == 0, "Test requires root privileges")
def test_interface_creation(self):
node0 = netns.Node()
ifaces = []
......@@ -36,6 +37,7 @@ class TestInterfaces(unittest.TestCase):
self.assertEquals(set(ifaces), node0.get_interfaces())
@test_util.skipUnless(os.getuid() == 0, "Test requires root privileges")
def test_interface_settings(self):
node0 = netns.Node()
if0 = node0.add_if(mac_address = '42:71:e0:90:ca:42', mtu = 1492)
......@@ -67,6 +69,7 @@ class TestInterfaces(unittest.TestCase):
# FIXME: get_stats
@test_util.skipUnless(os.getuid() == 0, "Test requires root privileges")
def test_interface_migration(self):
node0 = netns.Node()
dummyname = "dummy%d" % os.getpid()
......@@ -84,6 +87,7 @@ class TestInterfaces(unittest.TestCase):
self.assertEquals(devs[if0.name]['lladdr'], if0.mac_address)
self.assertEquals(devs[if0.name]['mtu'], if0.mtu)
@test_util.skipUnless(os.getuid() == 0, "Test requires root privileges")
def test_interface_addresses(self):
node0 = netns.Node()
if0 = node0.add_if()
......
#!/usr/bin/env python
# vim:ts=4:sw=4:et:ai:sts=4
import netns
import os
import signal
import subprocess
import sys
import time
import netns, test_util
import os, signal, subprocess, sys, time
import unittest
class TestNode(unittest.TestCase):
# def setUp(self):
# pass
@test_util.skipUnless(os.getuid() == 0, "Test requires root privileges")
def test_node(self):
node = netns.Node()
self.failIfEqual(node.pid, os.getpid())
......@@ -20,20 +17,18 @@ class TestNode(unittest.TestCase):
os.kill(node.pid, 0)
nodes = netns.get_nodes()
self.assertEquals(nodes, set([node]))
self.assertEquals(nodes, [node])
# Test that netns recognises a fork
chld = os.fork()
if chld == 0:
if len(netns.get_nodes()) == 0:
sys.exit(0)
sys.exit(1)
os._exit(0)
os._exit(1)
(pid, exitcode) = os.waitpid(chld, 0)
self.assertEquals(exitcode, 0)
def test_routing(self):
node = netns.Node()
self.assertEquals(exitcode, 0, "Node does not recognise forks")
@test_util.skipUnless(os.getuid() == 0, "Test requires root privileges")
def test_cleanup(self):
def create_stuff():
a = netns.Node()
......@@ -53,7 +48,7 @@ class TestNode(unittest.TestCase):
# Test automatic destruction
orig_devs = len(get_devs())
create_stuff()
self.assertEquals(netns.get_nodes(), set())
self.assertEquals(netns.get_nodes(), [])
self.assertEquals(orig_devs, len(get_devs()))
# Test at_exit hooks
......
#!/usr/bin/env python
# vim:ts=4:sw=4:et:ai:sts=4
import netns
import unittest
import netns, test_util
import os, unittest
class TestRouting(unittest.TestCase):
@test_util.skipUnless(os.getuid() == 0, "Test requires root privileges")
def test_routing(self):
node = netns.Node()
if0 = node.add_if()
......
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