summaryrefslogtreecommitdiffhomepage
path: root/test/scenario_test
diff options
context:
space:
mode:
authorNaoto Hanaue <hanaue.naoto@po.ntts.co.jp>2015-01-27 20:24:32 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-01-28 15:40:28 +0900
commita3e802b314d2f928456d59ad748897a74c269ee2 (patch)
tree43e53fba24d73acaf2f426bdd3914b011c6ee569 /test/scenario_test
parent959994eb57ae2e9a2d852bc4b71ba35fda911680 (diff)
scenario_test: support to sudo
Diffstat (limited to 'test/scenario_test')
-rw-r--r--test/scenario_test/README.md8
-rw-r--r--test/scenario_test/docker_control.py173
-rw-r--r--test/scenario_test/noseplugin.py1
-rw-r--r--test/scenario_test/route_server_malformed_test.py23
-rw-r--r--test/scenario_test/route_server_test.py66
5 files changed, 167 insertions, 104 deletions
diff --git a/test/scenario_test/README.md b/test/scenario_test/README.md
index 1308de36..034c2a62 100644
--- a/test/scenario_test/README.md
+++ b/test/scenario_test/README.md
@@ -44,14 +44,14 @@ Please run the test script as root.
route_server_test.py is scenario test script.
```
-# python route_server_test.py -v [ --use-local ]
+# python route_server_test.py -v [ --use-local ] [--go-path=<path>]
```
If you want to do malformed packet test, please run route_server_malformed_test.py
```
-# python route_server_malformed_test.py -v [ --use-local ]
+# python route_server_malformed_test.py -v [ --use-local ] [--go-path=<path>]
```
@@ -59,4 +59,6 @@ After the test, test results will be shown.
Notes
-----
- use [ --use-local ] option when execute gobgp program of local system \ No newline at end of file
+ use [ --use-local ] option when execute gobgp program of local system.
+
+ use [ --go-path ] option when not root and use sudo command. \ No newline at end of file
diff --git a/test/scenario_test/docker_control.py b/test/scenario_test/docker_control.py
index 2d93a134..056cdd01 100644
--- a/test/scenario_test/docker_control.py
+++ b/test/scenario_test/docker_control.py
@@ -52,7 +52,7 @@ def install_docker_and_tools():
print "start install packages of test environment."
if test_user_check() is False:
print "you are not root"
- os.exit(1)
+ return
local("apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys "
"36A1D7869245C8950F966E92D8576A8BA88D21E9", capture=True)
@@ -84,11 +84,19 @@ def docker_pkg_check():
dpkg_list = outbuf.split('\n')
for dpkg in dpkg_list:
# print "lxc-docker in ",dpkg
- if ("lxc-docker" in dpkg):
+ if "lxc-docker" in dpkg:
docker_exists = True
return docker_exists
+def go_path_check():
+ go_path_exist = False
+ outbuf = local("echo `which go`", capture=True)
+ if "go" in outbuf:
+ go_path_exist = True
+ return go_path_exist
+
+
def docker_container_checks():
container_exists = False
outbuf = local("docker ps -a", capture=True)
@@ -204,10 +212,6 @@ def docker_containers_destroy():
def docker_container_quagga_append(quagga_num, bridge):
print "start append docker container."
- pwd = local("pwd", capture=True)
- # cmd = "$GOROOT/bin/go run " + pwd + "/quagga-rsconfig.go -a " + str(quagga_num) + " -c /usr/local/gobgp"
- cmd = "go run " + pwd + "/quagga-rsconfig.go -a " + str(quagga_num) + " -c /usr/local/gobgp"
- local(cmd, capture=True)
docker_container_run_quagga(quagga_num, bridge)
cmd = "docker exec gobgp /usr/bin/pkill gobgp -SIGHUP"
local(cmd, capture=True)
@@ -261,97 +265,109 @@ def get_notification_from_exabgp_log():
return err_mgs
-def init_test_env_executor(quagga_num, gobgp_local):
+def make_config(quagga_num, go_path):
+ if go_path != "":
+ print "specified go path is [ " + go_path + " ]."
+ if os.path.isdir(go_path):
+ go_path += "/"
+ else:
+ print "specified go path do not use."
+ pwd = local("pwd", capture=True)
+ cmd = go_path + "go run " + pwd + "/quagga-rsconfig.go -n " + str(quagga_num) + " -c /usr/local/gobgp"
+ local(cmd, capture=True)
+
+
+def make_config_append(quagga_num, go_path):
+ if go_path != "":
+ print "specified go path is [ " + go_path + " ]."
+ if os.path.isdir(go_path):
+ go_path += "/"
+ else:
+ print "specified go path do not use."
+ pwd = local("pwd", capture=True)
+ cmd = go_path + "go run " + pwd + "/quagga-rsconfig.go -a " + str(quagga_num) + " -c /usr/local/gobgp"
+ local(cmd, capture=True)
+
+
+def init_test_env_executor(quagga_num, use_local, go_path):
print "start initialization of test environment."
- if test_user_check() is False:
- print "you are not root"
- os.exit(1)
- if docker_pkg_check():
- if docker_container_checks():
- print "gobgp test environment already exists."
- print "so that remake gobgp test environment."
- docker_containers_destroy()
+ if docker_container_checks():
+ print "gobgp test environment already exists."
+ print "so that remake gobgp test environment."
+ docker_containers_destroy()
- print "make gobgp test environment."
- bridge_setting_for_docker_connection()
- pwd = local("pwd", capture=True)
- # cmd = "$GOROOT/bin/go run " + pwd + "/quagga-rsconfig.go -n " + str(quagga_num) + " -c /usr/local/gobgp"
- cmd = "go run " + pwd + "/quagga-rsconfig.go -n " + str(quagga_num) + " -c /usr/local/gobgp"
- local(cmd, capture=True)
+ print "make gobgp test environment."
+ bridge_setting_for_docker_connection()
+ make_config(quagga_num, go_path)
- # run each docker container
- for num in range(1, quagga_num + 1):
- docker_container_run_quagga(num, BRIDGE_0)
- docker_container_run_gobgp(BRIDGE_0)
-
- # execute local gobgp program in the docker container if the input option is local
- if gobgp_local:
- print "use local-gobgp program in this test."
- pwd = local("pwd", capture=True)
- if A_PART_OF_CURRENT_DIR in pwd:
- gobgp_path = re.sub(A_PART_OF_CURRENT_DIR, "", pwd)
- cmd = "cp -r " + gobgp_path + " " + CONFIG_DIRR
- local(cmd, capture=True)
- make_startup_file_use_local_gobgp()
- else:
- print "current directory is not."
- print "use gobgp in docker container."
- make_startup_file()
+ # run each docker container
+ for num in range(1, quagga_num + 1):
+ docker_container_run_quagga(num, BRIDGE_0)
+ docker_container_run_gobgp(BRIDGE_0)
+ # execute local gobgp program in the docker container if the input option is local
+ if use_local:
+ print "execute gobgp program in local machine."
+ pwd = local("pwd", capture=True)
+ if A_PART_OF_CURRENT_DIR in pwd:
+ gobgp_path = re.sub(A_PART_OF_CURRENT_DIR, "", pwd)
+ cmd = "cp -r " + gobgp_path + " " + CONFIG_DIRR
+ local(cmd, capture=True)
+ make_startup_file_use_local_gobgp()
else:
- print "use docker-container-gobgp program in this test."
+ print "scenario_test directory is not."
+ print "execute gobgp program of osrg/master in github."
make_startup_file()
+ else:
+ print "execute gobgp program of osrg/master in github."
+ make_startup_file()
- start_gobgp()
+ start_gobgp()
- print "complete initialization of test environment."
+ print "complete initialization of test environment."
-def init_malformed_test_env_executor(conf_file, gobgp_local):
+def init_malformed_test_env_executor(conf_file, use_local):
print "start initialization of exabgp test environment."
- if test_user_check() is False:
- print "you are not root"
- os.exit(1)
+ if docker_container_checks():
+ print "gobgp test environment already exists."
+ print "so that remake gobgp test environment."
+ docker_containers_destroy()
- if docker_pkg_check():
- if docker_container_checks():
- print "gobgp test environment already exists."
- print "so that remake gobgp test environment."
- docker_containers_destroy()
+ print "make gobgp test environment."
+ bridge_setting_for_docker_connection()
+ pwd = local("pwd", capture=True)
+ gobgp_file = pwd + "/exabgp_test_conf/gobgpd.conf"
+ cmd = "cp " + gobgp_file + " " + CONFIG_DIRR
+ local(cmd, capture=True)
+ docker_container_run_gobgp(BRIDGE_0)
+ docker_container_run_exabgp(BRIDGE_0)
- print "make gobgp test environment."
- bridge_setting_for_docker_connection()
+ # execute local gobgp program in the docker container if the input option is local
+ if use_local:
+ print "execute gobgp program in local machine."
pwd = local("pwd", capture=True)
- gobgp_file = pwd + "/exabgp_test_conf/gobgpd.conf"
- cmd = "cp " + gobgp_file + " " + CONFIG_DIRR
- local(cmd, capture=True)
- docker_container_run_gobgp(BRIDGE_0)
- docker_container_run_exabgp(BRIDGE_0)
-
- # execute local gobgp program in the docker container if the input option is local
- if gobgp_local:
- print "use local-gobgp program in this test."
- pwd = local("pwd", capture=True)
- if A_PART_OF_CURRENT_DIR in pwd:
- gobgp_path = re.sub(A_PART_OF_CURRENT_DIR, "", pwd)
- cmd = "cp -r " + gobgp_path + " " + CONFIG_DIRR
- local(cmd, capture=True)
- make_startup_file_use_local_gobgp()
- else:
- print "current directory is not."
- print "use gobgp in docker container."
- make_startup_file()
-
+ if A_PART_OF_CURRENT_DIR in pwd:
+ gobgp_path = re.sub(A_PART_OF_CURRENT_DIR, "", pwd)
+ cmd = "cp -r " + gobgp_path + " " + CONFIG_DIRR
+ local(cmd, capture=True)
+ make_startup_file_use_local_gobgp()
else:
- print "use docker-container-gobgp program in this test."
+ print "scenario_test directory is not."
+ print "execute gobgp program of osrg/master in github."
make_startup_file()
+
+ else:
+ print "execute gobgp program of osrg/master in github."
+ make_startup_file()
- start_gobgp()
- start_exabgp(conf_file)
+ start_gobgp()
+ start_exabgp(conf_file)
-def docker_container_quagga_append_executor(quagga_num):
+def docker_container_quagga_append_executor(quagga_num, go_path):
+ make_config_append(quagga_num, go_path)
docker_container_quagga_append(quagga_num, BRIDGE_0)
@@ -359,8 +375,9 @@ def docker_container_quagga_removed_executor(quagga_num):
docker_container_quagga_removed(quagga_num)
-def docker_container_make_bestpath_env_executor(append_quagga_num):
+def docker_container_make_bestpath_env_executor(append_quagga_num, go_path):
print "start make bestpath environment"
+ make_config_append(append_quagga_num, go_path)
append_quagga_name = "q" + str(append_quagga_num)
docker_container_quagga_append(append_quagga_num, BRIDGE_1)
docker_container_set_ipaddress(BRIDGE_1, "q2", "11.0.0.2/16")
diff --git a/test/scenario_test/noseplugin.py b/test/scenario_test/noseplugin.py
index 8247d2fd..d2cb32bf 100644
--- a/test/scenario_test/noseplugin.py
+++ b/test/scenario_test/noseplugin.py
@@ -9,6 +9,7 @@ class OptionParser(Plugin):
def options(self, parser, env=os.environ):
super(OptionParser, self).options(parser, env=env)
parser.add_option('--use-local', action="store_true", dest="use_local", default=False)
+ parser.add_option('--go-path', action="store", dest="go_path", default="")
def configure(self, options, conf):
super(OptionParser, self).configure(options, conf)
diff --git a/test/scenario_test/route_server_malformed_test.py b/test/scenario_test/route_server_malformed_test.py
index e6a5975a..8ba90c74 100644
--- a/test/scenario_test/route_server_malformed_test.py
+++ b/test/scenario_test/route_server_malformed_test.py
@@ -45,21 +45,26 @@ def check_pattern():
def test_malformed_packet():
pwd = os.getcwd()
pattern = check_pattern()
+ if fab.test_user_check() is False:
+ print "you are not root"
+ sys.exit(1)
+
+ if fab.docker_pkg_check() is False:
+ print "not install docker package."
+ sys.exit(1)
+
if len(pattern) <= 0:
print "read test pattern is faild."
print "pattern element is " + str(len(pattern))
sys.exit(1)
- gobgp_local = parser_option.use_local
- if gobgp_local:
- print "execute gobgp program in local"
- else:
- print "execute gobgp program in gobgp container"
+ use_local = parser_option.use_local
+ go_path = parser_option.go_path
for pkey in pattern:
conf_file = pwd + "/exabgp_test_conf/" + pkey
if os.path.isfile(conf_file) is True:
- fab.init_malformed_test_env_executor(pkey, gobgp_local)
+ fab.init_malformed_test_env_executor(pkey, use_local, go_path)
print "please wait"
time.sleep(sleep_time)
yield check_em, pkey, pattern[pkey]
@@ -82,4 +87,10 @@ def check_em(exabgp_conf, result):
assert notification == result
if __name__ == '__main__':
+ if fab.test_user_check() is False:
+ print "you are not root."
+ sys.exit(1)
+ if fab.docker_pkg_check() is False:
+ print "not install docker package."
+ sys.exit(1)
nose.main(argv=sys.argv, addplugins=[OptionParser()], defaultTest=sys.argv[0]) \ No newline at end of file
diff --git a/test/scenario_test/route_server_test.py b/test/scenario_test/route_server_test.py
index 24fccc65..2d40176c 100644
--- a/test/scenario_test/route_server_test.py
+++ b/test/scenario_test/route_server_test.py
@@ -46,26 +46,19 @@ class GoBGPTest(unittest.TestCase):
def setUp(self):
self.quagga_configs = []
- self.load_gobgp_config()
- self.load_quagga_config()
# test each neighbor state is turned establish
def test_01_neighbor_established(self):
print "test_neighbor_established"
- gobgp_local = parser_option.use_local
- if gobgp_local:
- print "execute gobgp program in local"
- else:
- print "execute gobgp program in gobgp container"
- fab.init_test_env_executor(self.quagga_num, gobgp_local)
+ use_local = parser_option.use_local
+ go_path = parser_option.go_path
+ fab.init_test_env_executor(self.quagga_num, use_local, go_path)
print "please wait"
time.sleep(self.sleep_time)
if self.check_load_config() is False:
return
- self.load_gobgp_config()
- self.load_quagga_config()
addresses = self.get_neighbor_address(self.gobgp_config)
@@ -146,13 +139,16 @@ class GoBGPTest(unittest.TestCase):
if c_path.network.split("/")[0] == q_path['Network'] and c_path.nexthop == q_path['Next Hop']:
exist_n += 1
self.assertEqual(exist_n, 1)
-
+ """
# check if quagga that is appended can establish connection with gobgp
def test_04_established_with_appended_quagga(self):
print "test_established_with_appended_quagga"
+ if self.check_load_config() is False:
+ return
+ go_path = parser_option.go_path
# append new quagga container
- fab.docker_container_quagga_append_executor(self.append_quagga)
+ fab.docker_container_quagga_append_executor(self.append_quagga, go_path)
print "please wait"
time.sleep(self.sleep_time)
append_quagga_address = "10.0.0." + str(self.append_quagga)
@@ -236,6 +232,8 @@ class GoBGPTest(unittest.TestCase):
def test_07_active_when_quagga_removed(self):
print "test_active_when_removed_quagga"
+ if self.check_load_config() is False:
+ return
# remove quagga container
fab.docker_container_quagga_removed_executor(self.remove_quagga)
@@ -325,10 +323,15 @@ class GoBGPTest(unittest.TestCase):
if c_path.network.split("/")[0] == q_path['Network'] and c_path.nexthop == q_path['Next Hop']:
exist_n += 1
self.assertEqual(exist_n, 1)
+ """
def test_10_bestpath_selection_of_received_route(self):
print "test_bestpath_selection_of_received_route"
- fab.docker_container_make_bestpath_env_executor(self.append_quagga_best)
+ if self.check_load_config() is False:
+ return
+
+ go_path = parser_option.go_path
+ fab.docker_container_make_bestpath_env_executor(self.append_quagga_best, go_path)
print "please wait"
time.sleep(self.sleep_time)
@@ -348,14 +351,20 @@ class GoBGPTest(unittest.TestCase):
qaccess.add_neighbor_metric(tn, "65003", "10.0.255.1", "100")
print "please wait"
- time.sleep(self.sleep_time*2)
+ time.sleep(self.sleep_time)
check_address = "10.0.0.1"
target_network = "192.168.20.0"
ans_nexthop = "10.0.0.3"
- rep_nexthop = ""
+
print "check of [ " + check_address + " ]"
+ self.check_bestpath(check_address, target_network, ans_nexthop)
+
+ # load configration from gobgp(gobgpd.conf)
+ def check_bestpath(self, check_address, target_network, ans_nexthop):
# get local-rib
+ rep_nexthop = ""
+ target_exist = False
url = "http://" + self.gobgp_ip + ":" + self.gobgp_port + "/v1/bgp/neighbor/" + check_address + "/local-rib"
r = requests.get(url)
local_rib = json.loads(r.text)
@@ -364,17 +373,30 @@ class GoBGPTest(unittest.TestCase):
# print "prefix : ", g_dest['Prefix']
best_path_idx = g_dest['BestPathIdx']
if target_network == g_dest['Prefix']:
+ target_exist = True
g_paths = g_dest['Paths']
idx = 0
+ if len(g_paths) < 2:
+ print "target path has not been bestpath selected yet."
+ print "please wait more."
+ time.sleep(self.sleep_time/2)
+ self.check_bestpath(check_address, target_network, ans_nexthop)
+ return
for g_path in g_paths:
print "best_path_Idx: " + str(best_path_idx) + "idx: " + str(idx)
print "pre: ", g_dest['Prefix'], "net: ", g_path['Network'], "next: ", g_path['Nexthop']
if str(best_path_idx) == str(idx):
rep_nexthop = g_path['Nexthop']
idx += 1
+ if target_exist is False:
+ print "target path has not been receive yet."
+ print "please wait more."
+ time.sleep(self.sleep_time/2)
+ self.check_bestpath(check_address, target_network, ans_nexthop)
+ return
self.assertEqual(ans_nexthop, rep_nexthop)
- # load configration from gobgp(gobgpd.conf)
+
def load_gobgp_config(self):
try:
self.gobgp_config = toml.loads(open(self.gobgp_config_file).read())
@@ -431,11 +453,12 @@ class GoBGPTest(unittest.TestCase):
neighbors_config = config['NeighborList']
for neighbor_config in neighbors_config:
neighbor_ip = neighbor_config['NeighborAddress']
- print neighbor_ip
address.append(neighbor_ip)
return address
def check_load_config(self):
+ self.load_gobgp_config()
+ self.load_quagga_config()
if self.gobgp_config is None:
print "Failed to read the gobgp configuration file"
return False
@@ -469,4 +492,13 @@ class Path:
self.metric = None
if __name__ == '__main__':
+ if fab.test_user_check() is False:
+ print "you are not root."
+ sys.exit(1)
+ if fab.docker_pkg_check() is False:
+ print "not install docker package."
+ sys.exit(1)
+ if fab.go_path_check() is False:
+ print "can not find path of go"
+
nose.main(argv=sys.argv, addplugins=[OptionParser()], defaultTest=sys.argv[0])