Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
re6stnet
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
zhifan huang
re6stnet
Commits
8b3dfc3d
Commit
8b3dfc3d
authored
Apr 29, 2022
by
zhifan huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ad reboot test
parent
29496295
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
100 additions
and
100 deletions
+100
-100
re6st/tests/test_network/hmac.py
re6st/tests/test_network/hmac.py
+0
-39
re6st/tests/test_network/network_build.py
re6st/tests/test_network/network_build.py
+6
-5
re6st/tests/test_network/re6st_wrap.py
re6st/tests/test_network/re6st_wrap.py
+8
-4
re6st/tests/test_network/test_net.py
re6st/tests/test_network/test_net.py
+81
-52
re6st/tests/test_unit/test_registry.py
re6st/tests/test_unit/test_registry.py
+5
-0
No files found.
re6st/tests/test_network/hmac.py
deleted
100644 → 0
View file @
29496295
from
binascii
import
b2a_hex
import
psutil
import
logging
BABEL_HMAC
=
'babel_hmac0'
,
'babel_hmac1'
,
'babel_hmac2'
def
getConfig
(
db
,
name
):
r
=
db
.
execute
(
"SELECT value FROM config WHERE name=?"
,
(
name
,)).
fetchone
()
if
r
:
return
b2a_hex
(
*
r
)
def
checkHMAC
(
db
,
machines
):
hmac
=
[
getConfig
(
db
,
k
)
for
k
in
BABEL_HMAC
]
rc
=
True
for
x
in
psutil
.
Process
().
children
(
True
):
if
x
.
name
()
==
'babeld'
:
sign
=
accept
=
None
args
=
x
.
cmdline
()
for
x
in
args
:
if
x
.
endswith
(
'/babeld.log'
):
if
x
[:
-
11
].
split
(
'/'
)[
-
1
]
not
in
machines
:
break
elif
x
.
startswith
(
'key '
):
x
=
x
.
split
()
if
'sign'
in
x
:
sign
=
x
[
-
1
]
elif
'accept'
in
x
:
accept
=
x
[
-
1
]
else
:
i
=
0
if
hmac
[
0
]
else
1
if
hmac
[
i
]
!=
sign
or
hmac
[
i
+
1
]
!=
accept
:
logging
.
warn
(
'HMAC config wrong for in %s'
%
args
)
logging
.
warn
(
"HMAC sign: {}, accept: {}"
.
format
(
sign
,
accept
))
rc
=
False
if
rc
:
logging
.
info
(
'All nodes use Babel with the correct HMAC configuration'
)
else
:
logging
.
warn
(
'Expected config: %s'
%
dict
(
zip
(
BABEL_HMAC
,
hmac
)))
return
rc
re6st/tests/test_network/network_build.py
View file @
8b3dfc3d
from
sys
import
prefix
import
time
import
nemu
import
weakref
import
ipaddress
...
...
@@ -102,8 +102,8 @@ def network_demo():
nm
.
registrys
=
{
registry
:
[
m0
,
m1
,
m2
,
m3
,
m4
,
m5
]}
# for node in [registry
, m0, m2, m3, m4, m5]:
#
print "pid: {}".format(node.pid)
for
node
in
[
registry
,
internet
,
m0
,
m2
,
m3
,
m4
,
m5
]:
print
"pid: {}"
.
format
(
node
.
pid
)
g0_if_0
,
_
=
g1
.
connect_network
(
internet
)
m0
.
connect_network
(
internet
)
...
...
@@ -145,12 +145,13 @@ def network_demo():
node
.
add_route
(
nexthop
=
"10.1.10.1"
)
for
node
in
[
m0
,
m1
,
m2
,
m3
,
m4
,
m5
]:
app0
=
node
.
Popen
([
"ping"
,
"-c"
,
"1"
,
registry
.
ip
],
stdout
=
PIPE
)
ret
=
app0
.
wait
()
assert
ret
==
0
,
"network construct failed"
time
.
sleep
(
1000000
)
return
nm
...
...
@@ -176,4 +177,4 @@ def network_direct():
return
nm
if
__name__
==
"__main__"
:
network_d
irect
()
network_d
emo
()
re6st/tests/test_network/re6st_wrap.py
View file @
8b3dfc3d
...
...
@@ -264,14 +264,18 @@ class Re6stNode(object):
if
f
.
exists
():
f
.
unlink
()
def
stop
(
self
):
"""stop running re6stnet process"""
logging
.
debug
(
"{} teminate process {}"
.
format
(
self
.
name
,
self
.
proc
.
pid
))
self
.
proc
.
terminate
()
# timeout only in python3. deadlock maybe
wait_ps
(
self
.
proc
,
2
)
def
__del__
(
self
):
"""teminate process and rm temp dir"""
try
:
logging
.
debug
(
"{} teminate process {}"
.
format
(
self
.
name
,
self
.
proc
.
pid
))
self
.
proc
.
terminate
()
# timeout only in python3. deadlock maybe
wait_ps
(
self
.
proc
)
self
.
stop
()
except
Exception
as
e
:
logging
.
warn
(
"{}: {}"
.
format
(
self
.
name
,
e
))
...
...
re6st/tests/test_network/test_net.py
View file @
8b3dfc3d
"""contain ping-test for re6set net"""
import
os
import
unittest
import
time
import
subprocess
import
sys
import
psutil
import
os
import
logging
import
sqlite3
import
random
from
binascii
import
b2a_hex
from
pathlib2
import
Path
import
re6st_wrap
import
my_net
import
hmac
import
random
PING_PATH
=
str
(
Path
(
__file__
).
parent
.
resolve
()
/
"ping.py"
)
BABEL_HMAC
=
'babel_hmac0'
,
'babel_hmac1'
,
'babel_hmac2'
def
deploy_re6st
(
nm
):
def
deploy_re6st
(
nm
,
recreate
=
False
):
net
=
nm
.
registrys
nodes
=
[]
registrys
=
[]
re6st_wrap
.
Re6stRegistry
.
registry_seq
=
0
re6st_wrap
.
Re6stNode
.
node_seq
=
0
for
registry
in
net
:
reg
=
re6st_wrap
.
Re6stRegistry
(
registry
,
"2001:db8:42::"
,
recreate
=
Fals
e
)
reg
=
re6st_wrap
.
Re6stRegistry
(
registry
,
"2001:db8:42::"
,
recreate
=
recreat
e
)
reg_node
=
re6st_wrap
.
Re6stNode
(
registry
,
reg
,
name
=
reg
.
name
)
registrys
.
append
(
reg
)
reg_node
.
run
(
"--gateway"
,
"--disable-proto"
,
"none"
,
"--ip"
,
registry
.
ip
)
...
...
@@ -67,22 +65,41 @@ def wait_stable(nodes, timeout=240):
logging
.
info
(
"wait time cost: {}"
.
format
(
time
.
time
()
-
now
))
return
True
def
ping_test
(
nodes
):
"""test Re6st node connecty """
ips
=
{
node
.
ip6
:
node
.
name
for
node
in
nodes
}
logging
.
info
(
"start ping test"
)
failed
=
False
for
node
in
nodes
:
sub_ips
=
set
(
ips
)
-
{
node
.
ip6
}
node
.
ping_proc
=
node
.
node
.
Popen
(
[
"python"
,
PING_PATH
,
'-a'
]
+
list
(
sub_ips
),
stdout
=
subprocess
.
PIPE
)
out
,
_
=
node
.
ping_proc
.
communicate
()
unreached
=
[
ips
[
addr
]
for
addr
in
out
.
split
()]
if
unreached
:
logging
.
warning
(
"{} can't ping to {}"
.
format
(
node
.
name
,
","
.
join
(
unreached
)))
failed
=
True
logging
.
info
(
"ping test finish"
)
return
failed
def
getConfig
(
db
,
name
):
r
=
db
.
execute
(
"SELECT value FROM config WHERE name=?"
,
(
name
,)).
fetchone
()
if
r
:
return
b2a_hex
(
*
r
)
def
checkHMAC
(
db
,
machines
):
hmac
=
[
getConfig
(
db
,
k
)
for
k
in
BABEL_HMAC
]
rc
=
True
for
x
in
psutil
.
Process
().
children
(
True
):
if
x
.
name
()
==
'babeld'
:
sign
=
accept
=
None
args
=
x
.
cmdline
()
for
x
in
args
:
if
x
.
endswith
(
'/babeld.log'
):
if
x
[:
-
11
].
split
(
'/'
)[
-
1
]
not
in
machines
:
break
elif
x
.
startswith
(
'key '
):
x
=
x
.
split
()
if
'sign'
in
x
:
sign
=
x
[
-
1
]
elif
'accept'
in
x
:
accept
=
x
[
-
1
]
else
:
i
=
0
if
hmac
[
0
]
else
1
if
hmac
[
i
]
!=
sign
or
hmac
[
i
+
1
]
!=
accept
:
logging
.
warn
(
'HMAC config wrong for in %s'
%
args
)
logging
.
warn
(
"HMAC sign: {}, accept: {}"
.
format
(
sign
,
accept
))
rc
=
False
if
rc
:
logging
.
info
(
'All nodes use Babel with the correct HMAC configuration'
)
else
:
logging
.
warn
(
'Expected config: %s'
%
dict
(
zip
(
BABEL_HMAC
,
hmac
)))
return
rc
@
unittest
.
skipIf
(
os
.
geteuid
()
!=
0
,
"require root or create user namespace plz"
)
...
...
@@ -96,16 +113,30 @@ class TestNet(unittest.TestCase):
re6st_wrap
.
initial
()
@
classmethod
def
tearDown
(
cls
):
# logging.basicConfig(level=logging.WARNING)
def
tearDown
Class
(
cls
):
# clean all the running process
for
p
in
psutil
.
Process
().
children
():
logging
.
debug
(
"unterminate subprocess, name: {}, pid: {}, status: {}, cmd: {}"
.
format
(
p
.
name
(),
p
.
pid
,
p
.
status
(),
p
.
cmdline
()))
p
.
terminate
()
logging
.
basicConfig
(
level
=
logging
.
WARNING
)
# try:
# p.kill()
# except:
# pass
def
test_ping_router
(
self
):
"""create a network in a net segment, test the connectivity by ping
"""
nm
=
my_net
.
net_route
()
nodes
,
registrys
=
deploy_re6st
(
nm
)
wait_stable
(
nodes
,
20
)
time
.
sleep
(
10
)
self
.
assertTrue
(
wait_stable
(
nodes
,
20
),
" ping test failed"
)
def
test_ping_demo
(
self
):
"""create a network demo, test the connectivity by ping
wait at most 60 seconds, and test each node ping to other by ipv6 addr
...
...
@@ -113,39 +144,39 @@ class TestNet(unittest.TestCase):
nm
=
my_net
.
net_demo
()
nodes
,
registrys
=
deploy_re6st
(
nm
)
# wait 60, if the re6stnet stable quit wait
wait_stable
(
nodes
,
50
)
time
.
sleep
(
20
)
self
.
assertTrue
(
wait_stable
(
nodes
,
80
),
"ping test failed"
)
# stop on machine randomly and reboot it, test if network recover
# index = int(random.random() * 7) + 1
# machine = nodes[index]
# machine.proc.terminate()
# machine.proc.wait()
# time.sleep(5)
# machine.run("-i" + machine.node.out.name)
self
.
assertTrue
(
wait_stable
(
nodes
,
20
),
"ping test failed"
)
# self.assertTrue(wait_stable(nodes, 200), "second ping test failed")
def
test_ping_router
(
self
):
"""create a network in a net segment, test the connectivity by ping
def
test_reboot_one_machine
(
self
):
"""create a network demo, wait the net stable, reboot on machine,
then test if network recover, this test seems always failed
"""
nm
=
my_net
.
net_
route
()
nm
=
my_net
.
net_
demo
()
nodes
,
registrys
=
deploy_re6st
(
nm
)
wait_stable
(
nodes
,
50
)
time
.
sleep
(
10
)
self
.
assertTrue
(
wait_stable
(
nodes
,
40
),
" ping test failed"
)
wait_stable
(
nodes
,
100
)
# stop on machine randomly
index
=
int
(
random
.
random
()
*
7
)
+
1
machine
=
nodes
[
index
]
machine
.
proc
.
terminate
()
machine
.
proc
.
wait
()
time
.
sleep
(
5
)
machine
.
run
(
"-i"
+
machine
.
node
.
out
.
name
)
self
.
assertTrue
(
wait_stable
(
nodes
,
100
),
"network can't recover"
)
def
test_hmac
(
self
):
"""create a network demo, and run hmac test, this test check hmac 3 times
the third part always failed, unless deploy_re6st in no recreate mode
"""
nm
=
my_net
.
net_demo
()
nodes
,
registrys
=
deploy_re6st
(
nm
)
nodes
,
registrys
=
deploy_re6st
(
nm
,
False
)
updateHMAC
=
[
'python'
,
'-c'
,
"import urllib, sys; sys.exit("
"204 != urllib.urlopen('http://127.0.0.1/updateHMAC').code)"
]
...
...
@@ -161,26 +192,24 @@ class TestNet(unittest.TestCase):
wait_stable
(
nodes
,
100
)
logging
.
info
(
'Check that the initial HMAC config is deployed on network 1'
)
self
.
assertTrue
(
hmac
.
checkHMAC
(
reg1_db
,
m_net1
),
"first hmac check failed"
)
self
.
assertTrue
(
checkHMAC
(
reg1_db
,
m_net1
),
"first hmac check failed"
)
logging
.
info
(
'Test that a HMAC update works with nodes that are up'
)
registry
.
node
.
run
(
updateHMAC
)
time
.
sleep
(
60
)
# Checking HMAC on machines connected to registry 1...
self
.
assertTrue
(
hmac
.
checkHMAC
(
reg1_db
,
m_net1
),
"second hmac check failed: HMAC update don't work"
)
self
.
assertTrue
(
checkHMAC
(
reg1_db
,
m_net1
),
"second hmac check failed: HMAC update don't work"
)
# # check if one machine restarted
logging
.
info
(
'Test that machines can update upon reboot '
'when they were off during a HMAC update.'
)
logging
.
info
(
'Re6st on {} is stopped'
.
format
(
machine1
.
name
))
machine1
.
proc
.
terminate
()
machine1
.
proc
.
wait
()
machine1
.
stop
()
time
.
sleep
(
5
)
registry
.
node
.
run
(
updateHMAC
)
time
.
sleep
(
60
)
machine1
.
run
(
"-i"
+
machine1
.
node
.
out
.
name
)
wait_stable
(
nodes
,
100
)
self
.
assertTrue
(
hmac
.
checkHMAC
(
reg1_db
,
m_net1
),
"third hmac check failed: machine restart failed"
)
self
.
assertTrue
(
checkHMAC
(
reg1_db
,
m_net1
),
"third hmac check failed: machine restart failed"
)
logging
.
info
(
'Testing of HMAC done!'
)
reg1_db
.
close
()
...
...
re6st/tests/test_unit/test_registry.py
View file @
8b3dfc3d
...
...
@@ -403,6 +403,11 @@ class TestRegistrtServer(unittest.TestCase):
self
.
assertEqual
(
get_hmac
(),
[
None
,
key_2
,
key_1
])
#setp 5
self
.
server
.
updateHMAC
()
self
.
assertEqual
(
get_hmac
(),
[
key_2
,
None
,
None
])
def
test_getNodePrefix
(
self
):
# prefix in short format
...
...
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