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
43dc6c0f
Commit
43dc6c0f
authored
Jul 22, 2010
by
Martín Ferrari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add address handling; fix tests
parent
f498c73c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
17 deletions
+47
-17
src/netns/interface.py
src/netns/interface.py
+30
-2
t/test_interfaces.py
t/test_interfaces.py
+9
-9
t/test_node.py
t/test_node.py
+3
-1
t/test_util.py
t/test_util.py
+5
-5
No files found.
src/netns/interface.py
View file @
43dc6c0f
...
...
@@ -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
...
...
t/test_interfaces.py
View file @
43dc6c0f
...
...
@@ -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'
,
'p
len'
:
8
,
'bcast'
:
None
,
'family'
:
'inet'
'addr
ess'
:
'127.0.0.1'
,
'prefix_
len'
:
8
,
'b
road
cast'
:
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'
,
'p
len'
:
24
,
'bcast'
:
'10.0.0.255'
,
'family'
:
'inet'
'addr
ess'
:
'10.0.0.1'
,
'prefix_
len'
:
24
,
'b
road
cast'
:
'10.0.0.255'
,
'family'
:
'inet'
}
in
devs
[
if0
.
name
][
'addr'
])
self
.
assertTrue
(
{
'addr
'
:
'10.0.2.1'
,
'p
len'
:
26
,
'b
cast'
:
None
,
'family'
:
'inet'
'addr
ess'
:
'10.0.2.1'
,
'prefix_
len'
:
26
,
'b
roadcast'
:
'10.0.2.63'
,
'family'
:
'inet'
}
in
devs
[
if0
.
name
][
'addr'
])
self
.
assertTrue
(
{
'addr
'
:
'fe80::222:19ff:fe22:615d'
,
'p
len'
:
64
,
'
bcast'
:
None
,
'
family'
:
'inet6'
'addr
ess'
:
'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
...
...
t/test_node.py
View file @
43dc6c0f
...
...
@@ -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
:
...
...
t/test_util.py
View file @
43dc6c0f
...
...
@@ -34,17 +34,17 @@ def process_ipcmd(str):
match
=
re
.
search
(
r'^\
s+i
net ([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
),
'addr
ess
'
:
match
.
group
(
1
),
'p
refix_
len'
:
int
(
match
.
group
(
2
)),
'b
road
cast'
:
match
.
group
(
3
),
'family'
:
'inet'
})
continue
match
=
re
.
search
(
r'^\
s+i
net6 ([0-9a-f:]+)/(\
d+)(?: |$)
', line)
if match != None:
out[cur]['
addr
'].append({
'
addr
': match.group(1),
'
plen
': int(match.group(2)),
'
addr
ess
': match.group(1),
'
p
refix_
len
': int(match.group(2)),
'
family
': '
inet6
'})
continue
...
...
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