Commit c51929b5 authored by zhifan huang's avatar zhifan huang Committed by Xiaowu Zhang

refactor: move connect test function, and typo

parent d288e269
...@@ -8,7 +8,8 @@ from pathlib2 import Path ...@@ -8,7 +8,8 @@ from pathlib2 import Path
DEMO_PATH = Path(__file__).resolve().parent.parent.parent.parent / "demo" DEMO_PATH = Path(__file__).resolve().parent.parent.parent.parent / "demo"
fix_file = DEMO_PATH / "fixnemu.py" fix_file = DEMO_PATH / "fixnemu.py"
execfile(str(fix_file)) # execfile(str(fix_file)) Removed in python3
exec(open(str(fix_file)).read())
IPTABLES = 'iptables-nft' IPTABLES = 'iptables-nft'
class Node(nemu.Node): class Node(nemu.Node):
...@@ -50,19 +51,13 @@ class NetManager(object): ...@@ -50,19 +51,13 @@ class NetManager(object):
def __init__(self): def __init__(self):
self.object = [] self.object = []
self.registries = {} self.registries = {}
def connectable_test(self):
def connectible_test(nm):
"""test each node can ping to their registry """test each node can ping to their registry
Args:
nm: NetManger
Raise: Raise:
AssertionError AssertionError
""" """
for reg in nm.registries: for reg, nodes in self.registries.items():
for node in nm.registries[reg]: for node in nodes:
app0 = node.Popen(["ping", "-c", "1", reg.ip], stdout=PIPE) app0 = node.Popen(["ping", "-c", "1", reg.ip], stdout=PIPE)
ret = app0.wait() ret = app0.wait()
if ret: if ret:
...@@ -71,6 +66,7 @@ def connectible_test(nm): ...@@ -71,6 +66,7 @@ def connectible_test(nm):
logging.debug("each node can ping to their registry") logging.debug("each node can ping to their registry")
def net_route(): def net_route():
"""build a network connect by a route(bridge) """build a network connect by a route(bridge)
...@@ -93,7 +89,7 @@ def net_route(): ...@@ -93,7 +89,7 @@ def net_route():
nm.object.append(switch1) nm.object.append(switch1)
nm.registries[registry] = [machine1, machine2] nm.registries[registry] = [machine1, machine2]
connectible_test(nm) nm.connectable_test()
return nm return nm
def net_demo(): def net_demo():
...@@ -177,7 +173,7 @@ def net_demo(): ...@@ -177,7 +173,7 @@ def net_demo():
stdout=PIPE, stderr=PIPE) stdout=PIPE, stderr=PIPE)
switch1.up = switch2.up = switch3.up =True switch1.up = switch2.up = switch3.up =True
connectible_test(nm) nm.connectable_test()
return nm return nm
def network_direct(): def network_direct():
......
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