Commit 43dc6c0f authored by Martín Ferrari's avatar Martín Ferrari

add address handling; fix tests

parent f498c73c
......@@ -63,9 +63,37 @@ class _NSInterface(_Interface):
return self._slave.set_if(iface)
def add_v4_address(self, address, prefix_len, broadcast = None):
pass
addr = ipv4address(address, prefix_len, broadcast)
self._slave.add_addr(self._ns_if, addr)
def add_v6_address(self, address, prefix_len):
pass
addr = ipv6address(address, prefix_len)
self._slave.add_addr(self._ns_if, addr)
def del_v4_address(self, address, prefix_len, broadcast = None):
addr = ipv4address(address, prefix_len, broadcast)
self._slave.del_addr(self._ns_if, addr)
def del_v6_address(self, address, prefix_len):
addr = ipv6address(address, prefix_len)
self._slave.del_addr(self._ns_if, addr)
def get_addresses(self):
addresses = self._slave.get_addr_data(self._ns_if)
ret = []
for a in addresses:
if hasattr(a, 'broadcast'):
ret.append(dict(
address = a.address,
prefix_len = a.prefix_len,
broadcast = a.broadcast,
family = 'inet'))
else:
ret.append(dict(
address = a.address,
prefix_len = a.prefix_len,
family = 'inet6'))
return ret
class NodeInterface(_NSInterface):
"""Class to create and handle a virtual interface inside a name space, it
......
......@@ -15,8 +15,8 @@ class TestUtils(unittest.TestCase):
self.assertTrue(devs['lo']['up'])
self.assertEquals(devs['lo']['lladdr'], '00:00:00:00:00:00')
self.assertTrue( {
'addr': '127.0.0.1', 'plen': 8,
'bcast': None, 'family': 'inet'
'address': '127.0.0.1', 'prefix_len': 8,
'broadcast': None, 'family': 'inet'
} in devs['lo']['addr'])
class TestInterfaces(unittest.TestCase):
......@@ -115,20 +115,20 @@ class TestInterfaces(unittest.TestCase):
devs = get_devs_netns(node0)
self.assertTrue( {
'addr': '10.0.0.1', 'plen': 24,
'bcast': '10.0.0.255', 'family': 'inet'
'address': '10.0.0.1', 'prefix_len': 24,
'broadcast': '10.0.0.255', 'family': 'inet'
} in devs[if0.name]['addr'])
self.assertTrue( {
'addr': '10.0.2.1', 'plen': 26,
'bcast': None, 'family': 'inet'
'address': '10.0.2.1', 'prefix_len': 26,
'broadcast': '10.0.2.63', 'family': 'inet'
} in devs[if0.name]['addr'])
self.assertTrue( {
'addr': 'fe80::222:19ff:fe22:615d', 'plen': 64,
'bcast': None, 'family': 'inet6'
'address': 'fe80::222:19ff:fe22:615d', 'prefix_len': 64,
'family': 'inet6'
} in devs[if0.name]['addr'])
# FIXME: proper tests when I decide on the data format
self.assertTrue(len(if0.get_addresses()) >= 2)
self.assertEquals(if0.get_addresses(), devs[if0.name]['addr'])
# FIXME: Links
......
......@@ -18,7 +18,9 @@ class TestNode(unittest.TestCase):
nodes = netns.get_nodes()
self.assertEquals(nodes, [node])
@test_util.skip("Not implemented")
def test_detect_fork(self):
# Test that netns recognises a fork
chld = os.fork()
if chld == 0:
......
......@@ -34,17 +34,17 @@ def process_ipcmd(str):
match = re.search(r'^\s+inet ([0-9.]+)/(\d+)(?: brd ([0-9.]+))?', line)
if match != None:
out[cur]['addr'].append({
'addr': match.group(1),
'plen': int(match.group(2)),
'bcast': match.group(3),
'address': match.group(1),
'prefix_len': int(match.group(2)),
'broadcast': match.group(3),
'family': 'inet'})
continue
match = re.search(r'^\s+inet6 ([0-9a-f:]+)/(\d+)(?: |$)', line)
if match != None:
out[cur]['addr'].append({
'addr': match.group(1),
'plen': int(match.group(2)),
'address': match.group(1),
'prefix_len': int(match.group(2)),
'family': 'inet6'})
continue
......
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