Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nemu3
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
nemu3
Commits
dba7c881
Commit
dba7c881
authored
May 26, 2010
by
Martín Ferrari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bunch of iface tests
parent
848aae5f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
75 additions
and
10 deletions
+75
-10
t/interfaces.py
t/interfaces.py
+75
-10
No files found.
t/interfaces.py
View file @
dba7c881
#!/usr/bin/env python
#!/usr/bin/env python
# vim:ts=4:sw=4:et:ai:sts=4
# vim:ts=4:sw=4:et:ai:sts=4
import
unittest
import
netns
import
netns
import
os
import
os
import
re
import
re
import
subprocess
import
subprocess
import
unittest
def
process_ipcmd
(
str
):
def
process_ipcmd
(
str
):
cur
=
None
cur
=
None
...
@@ -25,6 +25,7 @@ def process_ipcmd(str):
...
@@ -25,6 +25,7 @@ def process_ipcmd(str):
'qdisc'
:
match
.
group
(
5
),
'qdisc'
:
match
.
group
(
5
),
'addr'
:
[]
'addr'
:
[]
}
}
out
[
cur
][
'up'
]
=
'UP'
in
out
[
cur
][
'flags'
]
continue
continue
# Assume cur is defined
# Assume cur is defined
assert
cur
!=
None
assert
cur
!=
None
...
@@ -37,7 +38,7 @@ def process_ipcmd(str):
...
@@ -37,7 +38,7 @@ def process_ipcmd(str):
if
match
!=
None
:
if
match
!=
None
:
out
[
cur
][
'addr'
].
append
({
out
[
cur
][
'addr'
].
append
({
'addr'
:
match
.
group
(
1
),
'addr'
:
match
.
group
(
1
),
'plen'
:
match
.
group
(
2
),
'plen'
:
int
(
match
.
group
(
2
)
),
'bcast'
:
match
.
group
(
3
),
'bcast'
:
match
.
group
(
3
),
'family'
:
'inet'
})
'family'
:
'inet'
})
continue
continue
...
@@ -46,7 +47,7 @@ def process_ipcmd(str):
...
@@ -46,7 +47,7 @@ def process_ipcmd(str):
if match != None:
if match != None:
out[cur]['
addr
'].append({
out[cur]['
addr
'].append({
'
addr
': match.group(1),
'
addr
': match.group(1),
'
plen
':
match.group(2
),
'
plen
':
int(match.group(2)
),
'
family
': '
inet6
'})
'
family
': '
inet6
'})
continue
continue
...
@@ -71,9 +72,31 @@ class TestInterfaces(unittest.TestCase):
...
@@ -71,9 +72,31 @@ class TestInterfaces(unittest.TestCase):
# There should be at least loopback!
# There should be at least loopback!
self.assertTrue(len(devs) > 0)
self.assertTrue(len(devs) > 0)
self.assertTrue('
lo
' in devs)
self.assertTrue('
lo
' in devs)
self.assertTrue(devs['
lo
']['
up
'])
self.assertEquals(devs['
lo
']['
lladdr
'], '
00
:
00
:
00
:
00
:
00
:
00
')
self.assertEquals(devs['
lo
']['
lladdr
'], '
00
:
00
:
00
:
00
:
00
:
00
')
self.assertTrue( {
'
addr
': '
127.0
.
0.1
', '
plen
': 8,
'
bcast
': None, '
family
': '
inet
'
} in devs['
lo
']['
addr
'])
def test_interfaces(self):
def test_interface_creation(self):
node0 = netns.Node()
ifaces = []
for i in range(5):
ifaces.append(node0.add_if())
devs = get_devs_netns(node0)
for i in range(5):
self.assertFalse(devs['
lo
']['
up
'])
self.assertTrue(ifaces[i].name in devs)
devs = get_devs()
for i in range(5):
self.assertTrue(ifaces[i].peer_name in devs)
self.assertEquals(set(ifaces), node0.get_interfaces())
def test_interface_settings(self):
node0 = netns.Node()
node0 = netns.Node()
if0 = node0.add_if(mac_address = '
42
:
71
:
e0
:
90
:
ca
:
42
', mtu = 1492)
if0 = node0.add_if(mac_address = '
42
:
71
:
e0
:
90
:
ca
:
42
', mtu = 1492)
self.assertEquals(if0.mac_address, '
42
:
71
:
e0
:
90
:
ca
:
42
')
self.assertEquals(if0.mac_address, '
42
:
71
:
e0
:
90
:
ca
:
42
')
...
@@ -88,23 +111,65 @@ class TestInterfaces(unittest.TestCase):
...
@@ -88,23 +111,65 @@ class TestInterfaces(unittest.TestCase):
devs = get_devs_netns(node0)
devs = get_devs_netns(node0)
self.assertTrue(if0.name in devs)
self.assertTrue(if0.name in devs)
self.assertFalse(devs[if0.name]['
up
'])
self.assertEquals(devs[if0.name]['
lladdr
'], if0.mac_address)
self.assertEquals(devs[if0.name]['
lladdr
'], if0.mac_address)
self.assertEquals(devs[if0.name]['
mtu
'], if0.mtu)
self.assertEquals(devs[if0.name]['
mtu
'], if0.mtu)
if0.enable = True
devs = get_devs_netns(node0)
self.assertTrue(devs[if0.name]['
up
'])
# Verify that data is actually read from the kernel
node0.run_process(["ip", "link", "set", if0.name, "mtu", "1500"])
devs = get_devs_netns(node0)
self.assertEquals(devs[if0.name]['
mtu
'], 1500)
self.assertEquals(devs[if0.name]['
mtu
'], if0.mtu)
# FIXME: get_stats
def test_interface_migration(self):
node0 = netns.Node()
dummyname = "dummy%d" % os.getpid()
dummyname = "dummy%d" % os.getpid()
self.assertEquals(
self.assertEquals(
os.system("ip link add name %s type dummy" % dummyname), 0)
os.system("ip link add name %s type dummy" % dummyname), 0)
devs = get_devs()
devs = get_devs()
self.assertTrue(dummyname in devs)
self.assertTrue(dummyname in devs)
if1 = node0.import_if(dummyname)
if0 = node0.import_if(dummyname)
if1.mac_address = '
42
:
71
:
e0
:
90
:
ca
:
43
'
if0.mac_address = '
42
:
71
:
e0
:
90
:
ca
:
43
'
if1.mtu = 1400
if0.mtu = 1400
devs = get_devs_netns(node0)
self.assertTrue(if0.name in devs)
self.assertEquals(devs[if0.name]['
lladdr
'], if0.mac_address)
self.assertEquals(devs[if0.name]['
mtu
'], if0.mtu)
def test_interface_addresses(self):
node0 = netns.Node()
if0 = node0.add_if()
if0.add_v4_address(addr = '
10.0
.
0.1
', prefix_len = 24,
broadcast = '
10.0
.
0.255
')
if0.add_v4_address(addr = '
10.0
.
2.1
', prefix_len = 26)
if0.add_v6_address(addr = '
fe80
::
222
:
19
ff
:
fe22
:
615
d
', prefix_len = 64)
devs = get_devs_netns(node0)
devs = get_devs_netns(node0)
self.assertTrue(if1.name in devs)
self.assertTrue( {
self.assertEquals(devs[if1.name]['
lladdr
'], if1.mac_address)
'
addr
': '
10.0
.
0.1
', '
plen
': 24,
self.assertEquals(devs[if1.name]['
mtu
'], if1.mtu)
'
bcast
': '
10.0
.
0.255
', '
family
': '
inet
'
} in devs[if0.name]['
addr
'])
self.assertTrue( {
'
addr
': '
10.0
.
2.1
', '
plen
': 26,
'
bcast
': None, '
family
': '
inet
'
} in devs[if0.name]['
addr
'])
self.assertTrue( {
'
addr
': '
fe80
::
222
:
19
ff
:
fe22
:
615
d
', '
plen
': 64,
'
bcast
': None, '
family
': '
inet6
'
} in devs[if0.name]['
addr
'])
# FIXME: proper tests when I decide on the data format
self.assertTrue(len(if0.get_addresses()) >= 2)
# FIXME: Links
if __name__ == '
__main__
':
if __name__ == '
__main__
':
unittest.main()
unittest.main()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment