summaryrefslogtreecommitdiffhomepage
path: root/test/scenario_test
diff options
context:
space:
mode:
Diffstat (limited to 'test/scenario_test')
-rw-r--r--test/scenario_test/README.md10
-rw-r--r--test/scenario_test/docker_control.py66
-rw-r--r--test/scenario_test/noseplugin.py22
-rw-r--r--test/scenario_test/route_server_malformed_test.py21
-rw-r--r--test/scenario_test/route_server_test.py26
5 files changed, 128 insertions, 17 deletions
diff --git a/test/scenario_test/README.md b/test/scenario_test/README.md
index c491e10d..1308de36 100644
--- a/test/scenario_test/README.md
+++ b/test/scenario_test/README.md
@@ -40,19 +40,23 @@ Please make sure following packages are installed properly inside the VM.
Start
-----
-Please run the test script using nosetests as root.
+Please run the test script as root.
route_server_test.py is scenario test script.
```
-# nosetests -v route_server_test.py
+# python route_server_test.py -v [ --use-local ]
```
+
If you want to do malformed packet test, please run route_server_malformed_test.py
```
-# nosetests -v route_server_malformed_test.py
+# python route_server_malformed_test.py -v [ --use-local ]
```
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
diff --git a/test/scenario_test/docker_control.py b/test/scenario_test/docker_control.py
index 8af4ae69..2d93a134 100644
--- a/test/scenario_test/docker_control.py
+++ b/test/scenario_test/docker_control.py
@@ -16,6 +16,7 @@
from fabric.api import local
import re
import os
+import sys
GOBGP_CONTAINER_NAME = "gobgp"
GOBGP_ADDRESS = "10.0.255.1/16"
@@ -34,6 +35,7 @@ BRIDGE_0 = {"BRIDGE_NAME": "br0", "BRIDGE_ADDRESS": "10.0.255.2"}
BRIDGE_1 = {"BRIDGE_NAME": "br1", "BRIDGE_ADDRESS": "11.0.255.2"}
BRIDGE_2 = {"BRIDGE_NAME": "br2", "BRIDGE_ADDRESS": "12.0.255.2"}
BRIDGES = [BRIDGE_0, BRIDGE_1, BRIDGE_2]
+A_PART_OF_CURRENT_DIR = "/test/scenario_test"
def test_user_check():
@@ -155,6 +157,20 @@ def make_startup_file():
local(cmd, capture=True)
+def make_startup_file_use_local_gobgp():
+ file_buff = '#!/bin/bash' + '\n'
+ file_buff += 'rm -rf /go/src/github.com/osrg/gobgp' + '\n'
+ file_buff += 'cp -r /mnt/gobgp /go/src/github.com/osrg/' + '\n'
+ file_buff += 'cd /go/src/github.com/osrg/gobgp' + '\n'
+ file_buff += 'go get -v' + '\n'
+ file_buff += 'go build' + '\n'
+ file_buff += './gobgp -f /mnt/gobgpd.conf > /mnt/gobgpd.log'
+ cmd = "echo \"" + file_buff + "\" > " + CONFIG_DIRR + STARTUP_FILE_NAME
+ local(cmd, capture=True)
+ cmd = "chmod 755 " + CONFIG_DIRR + STARTUP_FILE_NAME
+ local(cmd, capture=True)
+
+
def docker_container_stop_quagga(quagga):
cmd = "docker rm -f " + quagga
local(cmd, capture=True)
@@ -189,7 +205,8 @@ 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 = "$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"
@@ -244,7 +261,7 @@ def get_notification_from_exabgp_log():
return err_mgs
-def init_test_env_executor(quagga_num):
+def init_test_env_executor(quagga_num, gobgp_local):
print "start initialization of test environment."
if test_user_check() is False:
print "you are not root"
@@ -259,19 +276,39 @@ def init_test_env_executor(quagga_num):
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 = "$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)
+
+ # 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)
- make_startup_file()
+
+ # 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()
+
+ else:
+ print "use docker-container-gobgp program in this test."
+ make_startup_file()
start_gobgp()
print "complete initialization of test environment."
-def init_malformed_test_env_executor(conf_file):
+def init_malformed_test_env_executor(conf_file, gobgp_local):
print "start initialization of exabgp test environment."
if test_user_check() is False:
print "you are not root"
@@ -290,8 +327,25 @@ def init_malformed_test_env_executor(conf_file):
cmd = "cp " + gobgp_file + " " + CONFIG_DIRR
local(cmd, capture=True)
docker_container_run_gobgp(BRIDGE_0)
- make_startup_file()
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()
+
+ else:
+ print "use docker-container-gobgp program in this test."
+ make_startup_file()
start_gobgp()
start_exabgp(conf_file)
diff --git a/test/scenario_test/noseplugin.py b/test/scenario_test/noseplugin.py
new file mode 100644
index 00000000..8247d2fd
--- /dev/null
+++ b/test/scenario_test/noseplugin.py
@@ -0,0 +1,22 @@
+import os
+from nose.plugins import Plugin
+
+parser_option = None
+
+
+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)
+
+ def configure(self, options, conf):
+ super(OptionParser, self).configure(options, conf)
+ global parser_option
+ parser_option = options
+
+ if not self.enabled:
+ return
+
+ def finalize(self, result):
+ pass \ No newline at end of file
diff --git a/test/scenario_test/route_server_malformed_test.py b/test/scenario_test/route_server_malformed_test.py
index bfaf874c..e6a5975a 100644
--- a/test/scenario_test/route_server_malformed_test.py
+++ b/test/scenario_test/route_server_malformed_test.py
@@ -17,8 +17,12 @@ import os
import time
import re
import sys
+import nose
import collections
import docker_control as fab
+from noseplugin import OptionParser
+from noseplugin import parser_option
+
sleep_time = 20
@@ -42,14 +46,20 @@ def test_malformed_packet():
pwd = os.getcwd()
pattern = check_pattern()
if len(pattern) <= 0:
- print "read test patten is faild."
- print "csv element is " + str(len(pattern))
+ 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"
+
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)
+ fab.init_malformed_test_env_executor(pkey, gobgp_local)
print "please wait"
time.sleep(sleep_time)
yield check_em, pkey, pattern[pkey]
@@ -69,4 +79,7 @@ def check_em(exabgp_conf, result):
print " >>> " + notification_src
notification = notification_src[1:-1]
- assert notification == result \ No newline at end of file
+ assert notification == result
+
+if __name__ == '__main__':
+ 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 f1864122..24fccc65 100644
--- a/test/scenario_test/route_server_test.py
+++ b/test/scenario_test/route_server_test.py
@@ -19,9 +19,13 @@ import json
import toml
import os
import time
+import sys
+import nose
import quagga_access as qaccess
from ciscoconfparse import CiscoConfParse
import docker_control as fab
+from noseplugin import OptionParser
+from noseplugin import parser_option
class GoBGPTest(unittest.TestCase):
@@ -35,10 +39,7 @@ class GoBGPTest(unittest.TestCase):
append_quagga = 10
remove_quagga = 10
append_quagga_best = 20
- fab.init_test_env_executor(quagga_num)
- print "please wait"
sleep_time = 20
- time.sleep(sleep_time)
def __init__(self, *args, **kwargs):
super(GoBGPTest, self).__init__(*args, **kwargs)
@@ -51,8 +52,21 @@ class GoBGPTest(unittest.TestCase):
# 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)
+
+ 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)
for address in addresses:
@@ -373,6 +387,8 @@ class GoBGPTest(unittest.TestCase):
try:
content = os.listdir(self.base_dir)
for item in content:
+ if "q" != item[0]:
+ continue
if os.path.isdir(os.path.join(self.base_dir, item)):
dirs.append(item)
except OSError, (errno, strerror):
@@ -415,6 +431,7 @@ 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
@@ -451,4 +468,5 @@ class Path:
self.as_path = []
self.metric = None
-
+if __name__ == '__main__':
+ nose.main(argv=sys.argv, addplugins=[OptionParser()], defaultTest=sys.argv[0])