summaryrefslogtreecommitdiffhomepage
path: root/test/scenario_test
diff options
context:
space:
mode:
authorNaoto Hanaue <hanaue.naoto@po.ntts.co.jp>2015-01-21 19:22:53 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-01-22 20:31:35 +0900
commit9ab4bb000ae0fa2ebe15c088baa0abcf2e726c7c (patch)
tree5148c023c3886d84e7b4f924a20c2eeb8609303f /test/scenario_test
parent94ed82255d6d7cc9d5c7aee9f9c71837bfd2e907 (diff)
scenario_test: support test of best path selection and fixed following the display format of the rest
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'test/scenario_test')
-rw-r--r--test/scenario_test/README.md56
-rw-r--r--test/scenario_test/docker_control.py282
-rw-r--r--test/scenario_test/quagga_access.py45
-rw-r--r--test/scenario_test/route_server_test.py81
4 files changed, 347 insertions, 117 deletions
diff --git a/test/scenario_test/README.md b/test/scenario_test/README.md
new file mode 100644
index 00000000..a0a78a9b
--- /dev/null
+++ b/test/scenario_test/README.md
@@ -0,0 +1,56 @@
+Route Server test
+========================
+
+Preparation
+-----------
+Set up Ubuntu 14.04 Server Edition Virtual Machine environment.
+
+and Please prepare in go language execution environment.
+
+Setup
+-----
+Open a terminal and execute the following commands:
+
+We will install the python library required to run the test program.
+```
+% sudo su -
+# apt-get install python-pip
+# apt-get install python-dev
+# git clone https://github.com/osrg/gobgp.git
+# cd ./gobgp
+# go get -v
+# cd ./test/scenario_test
+# pip install -r pip-requires.txt
+```
+
+
+We will install the package, such as Docker required to perform the test.
+```
+# fab -f docker_control.py install_docker_and_tools
+
+```
+
+Please following package is sure that it is installed.
+
+ ・docker
+
+ ・bridge-utils
+
+ ・pipework
+
+
+Start
+-----
+Please run the command nosetests.
+```
+# nosetests -v route_server_test.py
+
+```
+
+if you run the test of malformed when execute this command.
+```
+# nosetests -v route_server_malformed_test.py
+
+```
+
+After the end of the test, gobgp is normally if OK is displayed.
diff --git a/test/scenario_test/docker_control.py b/test/scenario_test/docker_control.py
index f1881b6b..8af4ae69 100644
--- a/test/scenario_test/docker_control.py
+++ b/test/scenario_test/docker_control.py
@@ -1,20 +1,40 @@
+# Copyright (C) 2014 Nippon Telegraph and Telephone Corporation.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
from fabric.api import local
-import time
+import re
import os
GOBGP_CONTAINER_NAME = "gobgp"
GOBGP_ADDRESS = "10.0.255.1/16"
GOBGP_CONFIG_FILE = "gobgpd.conf"
+EXABGP_CONTAINER_NAME = "exabgp"
+EXABGP_ADDRESS = "10.0.0.100/16"
+EXABGP_CONFDIR = "/etc/exabgp/"
+EXABGP_LOG_FILE = "exabgpd.log"
BRIDGE_ADDRESS = "10.0.255.2"
CONFIG_DIR = "/usr/local/gobgp"
CONFIG_DIRR = "/usr/local/gobgp/"
+CONFIG_DIRRR = "/usr/local/gobgp/*"
STARTUP_FILE_NAME = "gobgp_startup.sh"
STARTUP_FILE = "/mnt/" + STARTUP_FILE_NAME
-BRIDGE_0 = "br0"
-BRIDGE_1 = "br1"
-BRIDGE_2 = "br2"
+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]
-sleep_time = 40
def test_user_check():
root = False
@@ -26,9 +46,16 @@ def test_user_check():
return root
-def docker_related_installation():
- local("apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9", capture=True)
- local('sh -c "echo deb https://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list"', capture=True)
+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)
+
+ local("apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys "
+ "36A1D7869245C8950F966E92D8576A8BA88D21E9", capture=True)
+ local('sh -c "echo deb https://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list"',
+ capture=True)
local("apt-get update", capture=True)
local("apt-get install -y --force-yes lxc-docker-1.3.2", capture=True)
local("ln -sf /usr/bin/docker.io /usr/local/bin/docker", capture=True)
@@ -39,12 +66,14 @@ def docker_related_installation():
local("apt-get install -y --force-yes bridge-utils", capture=True)
local("apt-get install -y --force-yes tcpdump", capture=True)
local("apt-get install -y --force-yes lv", capture=True)
- local("wget https://raw.github.com/jpetazzo/pipework/master/pipework -O /usr/local/bin/pipework", capture=True)
+ local("wget https://raw.github.com/jpetazzo/pipework/master/pipework -O /usr/local/bin/pipework",
+ capture=True)
local("chmod 755 /usr/local/bin/pipework", capture=True)
local("docker pull osrg/quagga", capture=True)
local("docker pull osrg/gobgp", capture=True)
+ local("docker pull osrg/exabgp", capture=True)
local("mkdir /usr/local/gobgp", capture=True)
- local("docker run --privileged=true -v /usr/local/gobgp:/mnt --name gobgp --rm osrg/gobgp go run /root/gobgp/tools/route-server/quagga-rsconfig.go -c /mnt", capture=True)
+ # local("docker run --privileged=true -v /usr/local/gobgp:/mnt --name gobgp --rm osrg/gobgp go run /root/gobgp/tools/route-server/quagga-rsconfig.go -c /mnt", capture=True)
def docker_pkg_check():
@@ -58,20 +87,21 @@ def docker_pkg_check():
return docker_exists
-def docker_container_check():
+def docker_container_checks():
container_exists = False
- outbuf = local("docker ps", capture=True)
+ outbuf = local("docker ps -a", capture=True)
docker_ps = outbuf.split('\n')
for container in docker_ps:
container_name = container.split()[-1]
- if container_name == GOBGP_CONTAINER_NAME:
+ if (container_name == GOBGP_CONTAINER_NAME) or \
+ (container_name == EXABGP_CONTAINER_NAME) or ("q" in container_name):
container_exists = True
return container_exists
-def get_docker_containers():
+def docker_containers_get():
containers = []
- cmd = "docker ps | awk '{print $NF}' | grep -e '^[q][0-9][0-9]*$'"
+ cmd = "docker ps -a | awk '{print $NF}'"
outbuf = local(cmd, capture=True)
docker_ps = outbuf.split('\n')
for container in docker_ps:
@@ -80,156 +110,206 @@ def get_docker_containers():
return containers
-def docker_run_quagga(quagga_num):
- quagga_name = "q" + str(quagga_num)
- cmd = "docker run --privileged=true -v " + CONFIG_DIR + "/" + quagga_name + ":/etc/quagga --name " + quagga_name + " -id osrg/quagga"
+def docker_container_set_ipaddress(bridge, quagga_name, address):
+ cmd = "pipework " + bridge["BRIDGE_NAME"] + " -i eth-" + bridge["BRIDGE_NAME"]\
+ + " " + quagga_name + " " + address
local(cmd, capture=True)
- quagga_address = "10.0.0." + str(quagga_num) + "/16"
- cmd = "pipework " + BRIDGE_0 + " " + quagga_name + " " + quagga_address
+
+
+def docker_container_run_quagga(quagga_num, bridge):
+ quagga_name = "q" + str(quagga_num)
+ cmd = "docker run --privileged=true -v " + CONFIG_DIR + "/" + quagga_name +\
+ ":/etc/quagga --name " + quagga_name + " -id osrg/quagga"
local(cmd, capture=True)
+ aff_net = bridge["BRIDGE_NAME"][-1]
+ quagga_address = "1" + aff_net + ".0.0." + str(quagga_num) + "/16"
+ docker_container_set_ipaddress(bridge, quagga_name, quagga_address)
-def docker_run_gobgp():
- cmd = "docker run --privileged=true -v " + CONFIG_DIR + ":/mnt -d --name " + GOBGP_CONTAINER_NAME + " -id osrg/gobgp"
+def docker_container_run_gobgp(bridge):
+ cmd = "docker run --privileged=true -v " + CONFIG_DIR + ":/mnt -d --name "\
+ + GOBGP_CONTAINER_NAME + " -id osrg/gobgp"
local(cmd, capture=True)
- cmd = "pipework " + BRIDGE_0 + " " + GOBGP_CONTAINER_NAME + " " + GOBGP_ADDRESS
+ docker_container_set_ipaddress(bridge, GOBGP_CONTAINER_NAME, GOBGP_ADDRESS)
+
+
+def docker_container_run_exabgp(bridge):
+ pwd = local("pwd", capture=True)
+ test_pattern_dir = pwd + "/exabgp_test_conf"
+ cmd = "docker run --privileged=true -v " + test_pattern_dir + ":/etc/exabgp -v " \
+ + CONFIG_DIR + ":/mnt -d --name " + EXABGP_CONTAINER_NAME + " -id osrg/exabgp"
local(cmd, capture=True)
+ docker_container_set_ipaddress(bridge, EXABGP_CONTAINER_NAME, EXABGP_ADDRESS)
def make_startup_file():
file_buff = '#!/bin/bash' + '\n'
- file_buff += 'cd /root/gobgp' + '\n'
+ file_buff += 'cd /go/src/github.com/osrg/gobgp' + '\n'
file_buff += 'git pull origin master' + '\n'
file_buff += 'go get -v' + '\n'
file_buff += 'go build' + '\n'
- file_buff += './gobgp -f /mnt/gobgpd.conf'
+ 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_containers_create(quagga_num):
- bridge_setting_for_docker_connection(BRIDGE_0)
- pwd = local("pwd", capture=True)
- cmd = "go run " + pwd + "/quagga-rsconfig.go -n " + str(quagga_num) + " -c /usr/local/gobgp"
- local(cmd, capture=True)
- for num in range(1, quagga_num + 1):
- docker_run_quagga(num)
- docker_run_gobgp()
- make_startup_file()
-
-
-def docker_stop_quagga(quagga):
+def docker_container_stop_quagga(quagga):
cmd = "docker rm -f " + quagga
local(cmd, capture=True)
cmd = "rm -rf " + CONFIG_DIRR + quagga
local(cmd, capture=True)
-def docker_stop_gobgp():
+def docker_container_stop_gobgp():
cmd = "docker rm -f " + GOBGP_CONTAINER_NAME
local(cmd, capture=True)
-def docker_containers_destroy():
- if docker_container_check() is True:
- containers = get_docker_containers()
- for container in containers:
- docker_stop_quagga(container)
- docker_stop_gobgp()
- bridge_unsetting_for_docker_connection(BRIDGE_0)
- cmd = "rm -rf " + CONFIG_DIRR + GOBGP_CONFIG_FILE
- local(cmd, capture=True)
- cmd = "rm -rf " + CONFIG_DIRR + STARTUP_FILE_NAME
- local(cmd, capture=True)
- else:
- print "docker containers not exists."
- os.exit(1)
+def docker_container_stop_exabgp():
+ cmd = "docker rm -f " + EXABGP_CONTAINER_NAME
+ local(cmd, capture=True)
-def docker_containers_recreate(quagga_num):
- docker_containers_destroy()
- docker_containers_create(quagga_num)
+def docker_containers_destroy():
+ containers = docker_containers_get()
+ for container in containers:
+ if re.match(r'q[0-9][0-9]*', container) is not None:
+ docker_container_stop_quagga(container)
+ if container == GOBGP_CONTAINER_NAME:
+ docker_container_stop_gobgp()
+ if container == EXABGP_CONTAINER_NAME:
+ docker_container_stop_exabgp()
+ bridge_unsetting_for_docker_connection()
+ cmd = "rm -rf " + CONFIG_DIRRR
+ local(cmd, capture=True)
-def docker_container_append(quagga_num):
+def docker_container_quagga_append(quagga_num, bridge):
print "start append docker container."
pwd = local("pwd", capture=True)
- cmd = "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"
local(cmd, capture=True)
- docker_run_quagga(quagga_num)
+ docker_container_run_quagga(quagga_num, bridge)
cmd = "docker exec gobgp /usr/bin/pkill gobgp -SIGHUP"
local(cmd, capture=True)
- print "please wait"
- time.sleep(sleep_time)
print "complete append docker container."
-def docker_container_removed(quagga_num):
- print "start remove docker container."
+def docker_container_quagga_removed(quagga_num):
+ print "start removed docker container."
quagga = "q" + str(quagga_num)
- docker_stop_quagga(quagga)
- print "please wait"
- time.sleep(sleep_time)
- print "complete remove docker container."
-
-
-def bridge_setting_for_docker_connection(bridge):
- sysfs_name = "/sys/class/net/" + bridge
- if os.path.exists(sysfs_name):
- bridge_unsetting_for_docker_connection(bridge)
- bridge_setting_for_docker_connection(bridge)
- else:
- cmd = "brctl addbr " + bridge
+ docker_container_stop_quagga(quagga)
+ print "complete removed docker container."
+
+
+def bridge_setting_for_docker_connection():
+ bridge_unsetting_for_docker_connection()
+ for bridge in BRIDGES:
+ cmd = "brctl addbr " + bridge["BRIDGE_NAME"]
local(cmd, capture=True)
- cmd = "ifconfig " + bridge + " " + BRIDGE_ADDRESS
+ cmd = "ifconfig " + bridge["BRIDGE_NAME"] + " " + bridge["BRIDGE_ADDRESS"]
local(cmd, capture=True)
- cmd = "ifconfig " + bridge + " up"
+ cmd = "ifconfig " + bridge["BRIDGE_NAME"] + " up"
local(cmd, capture=True)
-def bridge_unsetting_for_docker_connection(bridge):
- sysfs_name = "/sys/class/net/" + bridge
- if os.path.exists(sysfs_name):
- cmd = "ifconfig " + bridge + " down"
- local(cmd, capture=True)
- cmd = "brctl delbr " + bridge
- local(cmd, capture=True)
+def bridge_unsetting_for_docker_connection():
+ for bridge in BRIDGES:
+ sysfs_name = "/sys/class/net/" + bridge["BRIDGE_NAME"]
+ if os.path.exists(sysfs_name):
+ cmd = "ifconfig " + bridge["BRIDGE_NAME"] + " down"
+ local(cmd, capture=True)
+ cmd = "brctl delbr " + bridge["BRIDGE_NAME"]
+ local(cmd, capture=True)
-def gobgp_start():
+def start_gobgp():
cmd = "docker exec gobgp " + STARTUP_FILE + " > /dev/null 2>&1 &"
# cmd = "docker exec gobgp " + STARTUP_FILE
local(cmd, capture=True)
+def start_exabgp(conf_file):
+ conf_path = EXABGP_CONFDIR + conf_file
+ cmd = "docker exec exabgp /usr/local/exabgp/sbin/exabgp " + conf_path + " > /dev/null 2>&1 &"
+ local(cmd, capture=True)
+
+
+def get_notification_from_exabgp_log():
+ log_path = CONFIG_DIRR + EXABGP_LOG_FILE
+ cmd = "grep notification " + log_path + " | head -1"
+ err_mgs = local(cmd, capture=True)
+ return err_mgs
+
+
def init_test_env_executor(quagga_num):
print "start initialization of test environment."
if test_user_check() is False:
print "you are not root"
- print "please run the test after you login as root"
- return
+ os.exit(1)
if docker_pkg_check():
- if docker_container_check():
+ if docker_container_checks():
print "gobgp test environment already exists."
print "so that remake gobgp test environment."
- docker_containers_recreate(quagga_num)
- else:
- print "make gobgp test environment."
- docker_containers_create(quagga_num)
- gobgp_start()
+ 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"
+ local(cmd, capture=True)
+ for num in range(1, quagga_num + 1):
+ docker_container_run_quagga(num, BRIDGE_0)
+ docker_container_run_gobgp(BRIDGE_0)
+ make_startup_file()
- print "please wait"
- time.sleep(sleep_time)
- print "complete initialization of test environment."
+ start_gobgp()
+ print "complete initialization of test environment."
-def docker_related_install_executor():
- print "start install of docker related"
+
+def init_malformed_test_env_executor(conf_file):
+ print "start initialization of exabgp test environment."
if test_user_check() is False:
print "you are not root"
- print "please run the test after you login as root"
- return
- docker_related_installation()
+ 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()
+
+ 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)
+ make_startup_file()
+ docker_container_run_exabgp(BRIDGE_0)
+
+ start_gobgp()
+ start_exabgp(conf_file)
+
+
+def docker_container_quagga_append_executor(quagga_num):
+ docker_container_quagga_append(quagga_num, BRIDGE_0)
+
+
+def docker_container_quagga_removed_executor(quagga_num):
+ docker_container_quagga_removed(quagga_num)
+
+
+def docker_container_make_bestpath_env_executor(append_quagga_num):
+ print "start make bestpath environment"
+ 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")
+ docker_container_set_ipaddress(BRIDGE_2, append_quagga_name, "12.0.0.20/16")
+ docker_container_set_ipaddress(BRIDGE_2, "q3", "12.0.0.3/16")
+
diff --git a/test/scenario_test/quagga_access.py b/test/scenario_test/quagga_access.py
index 87152c02..df2eb938 100644
--- a/test/scenario_test/quagga_access.py
+++ b/test/scenario_test/quagga_access.py
@@ -17,17 +17,37 @@ import sys
import telnetlib
PASSWORD = "zebra"
+CONN_PASSWORD = "hogehoge"
QLPORT = 2605
+
def login(host):
tn = telnetlib.Telnet(host, QLPORT)
tn.read_until("Password: ")
tn.write(PASSWORD + "\n")
-
tn.write("enable\n")
- #print tn.read_all()
return tn
+
+def add_neighbor(tn, as_number, neighbor_address, remote_as):
+ tn.write("configure terminal\n")
+ tn.write("router bgp "+str(as_number)+"\n")
+ tn.write("neighbor " + neighbor_address + " remote-as " + remote_as + "\n")
+ tn.write("neighbor " + neighbor_address + " password " + CONN_PASSWORD + "\n")
+ tn.write("exit\n")
+ tn.write("exit\n")
+ tn.read_until("bgpd#")
+
+
+def add_neighbor_metric(tn, as_number, neighbor_address, metric):
+ tn.write("configure terminal\n")
+ tn.write("router bgp "+str(as_number)+"\n")
+ tn.write("neighbor " + neighbor_address + " route-map MED" + metric + " out\n")
+ tn.write("exit\n")
+ tn.write("exit\n")
+ tn.read_until("bgpd#")
+
+
def add_network(tn, as_number, network):
tn.write("configure terminal\n")
tn.write("router bgp "+str(as_number)+"\n")
@@ -36,12 +56,28 @@ def add_network(tn, as_number, network):
tn.write("exit\n")
print tn.read_until("bgpd#")
+
+def add_metric(tn, metric, network):
+ tn.write("configure terminal\n")
+ tn.write("access-list 1 permit " + network + " 0.0.0.255\n")
+ tn.write("route-map MED" + metric + " permit 10\n")
+ tn.write("match ip address 1\n")
+ tn.write("set metric " + metric + "\n")
+ tn.write("route-map MED" + metric + " permit 10\n")
+ tn.write("set metric\n")
+ tn.read_until("bgpd(config-route-map)#")
+ tn.write("exit\n")
+ tn.write("exit\n")
+ return tn
+
+
def show_config(tn):
tn.write("show run\n")
print tn.read_until("bgpd#")
tn.write("exit\n")
print tn.read_all()
+
def show_rib(tn):
tn.write("show ip bgp\n")
tn.read_until(" Network Next Hop Metric LocPrf Weight Path")
@@ -49,6 +85,11 @@ def show_rib(tn):
# print header
return rib_parser(rib)
+
+def clear_ip_bgp(tn):
+ tn.write("clear ip bgp *\n")
+ tn.read_until("bgpd#")
+
def rib_parser(rib):
lines = rib.split("\n")
paths = []
diff --git a/test/scenario_test/route_server_test.py b/test/scenario_test/route_server_test.py
index 8915d8f8..f1864122 100644
--- a/test/scenario_test/route_server_test.py
+++ b/test/scenario_test/route_server_test.py
@@ -18,6 +18,7 @@ import requests
import json
import toml
import os
+import time
import quagga_access as qaccess
from ciscoconfparse import CiscoConfParse
import docker_control as fab
@@ -31,10 +32,13 @@ class GoBGPTest(unittest.TestCase):
gobgp_config_file = "/usr/local/gobgp/gobgpd.conf"
gobgp_config = None
quagga_num = 3
- appending_quagga = 10
- deleting_quagga = 10
- appending_quagga_best = 20
+ 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)
@@ -134,8 +138,10 @@ class GoBGPTest(unittest.TestCase):
print "test_established_with_appended_quagga"
# append new quagga container
- fab.docker_container_append(self.appending_quagga)
- append_quagga_address = "10.0.0." + str(self.appending_quagga)
+ fab.docker_container_quagga_append_executor(self.append_quagga)
+ print "please wait"
+ time.sleep(self.sleep_time)
+ append_quagga_address = "10.0.0." + str(self.append_quagga)
# get neighbor state and remote ip of new quagga
print "check of [" + append_quagga_address + " ]"
@@ -218,8 +224,10 @@ class GoBGPTest(unittest.TestCase):
print "test_active_when_removed_quagga"
# remove quagga container
- fab.docker_container_removed(self.deleting_quagga)
- removed_quagga_address = "10.0.0." + str(self.deleting_quagga)
+ fab.docker_container_quagga_removed_executor(self.remove_quagga)
+ print "please wait"
+ time.sleep(self.sleep_time)
+ removed_quagga_address = "10.0.0." + str(self.remove_quagga)
# get neighbor state and remote ip of removed quagga
print "check of [" + removed_quagga_address + " ]"
@@ -236,9 +244,9 @@ class GoBGPTest(unittest.TestCase):
if self.check_load_config() is False:
return
- deleting_quagga_address = "10.0.0." + str(self.deleting_quagga)
+ remove_quagga_address = "10.0.0." + str(self.remove_quagga)
for address in self.get_neighbor_address(self.gobgp_config):
- if deleting_quagga_address == address:
+ if remove_quagga_address == address:
continue
print "check of [ " + address + " ]"
@@ -260,7 +268,7 @@ class GoBGPTest(unittest.TestCase):
self.assertEqual(exist_n, 0)
else:
for c_dest in quagga_config.destinations.itervalues():
- # print "config : ", c_dest.prefix,"
+ # print "config : ", c_dest.prefix
g_dests = local_rib['Destinations']
exist_n = 0
for g_dest in g_dests:
@@ -274,9 +282,9 @@ class GoBGPTest(unittest.TestCase):
if self.check_load_config() is False:
return
- deleting_quagga_address = "10.0.0." + str(self.deleting_quagga)
+ remove_quagga_address = "10.0.0." + str(self.remove_quagga)
for address in self.get_neighbor_address(self.gobgp_config):
- if deleting_quagga_address == address:
+ if remove_quagga_address == address:
continue
print "check of [ " + address + " ]"
@@ -304,8 +312,53 @@ class GoBGPTest(unittest.TestCase):
exist_n += 1
self.assertEqual(exist_n, 1)
- def test_10_bestpath_selection_by_received_route(self):
- pass
+ 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)
+ print "please wait"
+ time.sleep(self.sleep_time)
+
+ print "add neighbor setting"
+ tn = qaccess.login("11.0.0.20")
+ qaccess.add_neighbor(tn, "65020", "11.0.0.2", "65002")
+ qaccess.add_neighbor(tn, "65020", "12.0.0.3", "65003")
+
+ tn = qaccess.login("10.0.0.2")
+ tn = qaccess.add_metric(tn, "200", "192.168.20.0")
+ qaccess.add_neighbor(tn, "65002", "11.0.0.20", "65020")
+ qaccess.add_neighbor_metric(tn, "65002", "10.0.255.1", "200")
+
+ tn = qaccess.login("10.0.0.3")
+ tn = qaccess.add_metric(tn, "100", "192.168.20.0")
+ qaccess.add_neighbor(tn, "65003", "12.0.0.20", "65020")
+ qaccess.add_neighbor_metric(tn, "65003", "10.0.255.1", "100")
+
+ print "please wait"
+ time.sleep(self.sleep_time*2)
+
+ 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 + " ]"
+ # get local-rib
+ 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)
+ g_dests = local_rib['Destinations']
+ for g_dest in g_dests:
+ # print "prefix : ", g_dest['Prefix']
+ best_path_idx = g_dest['BestPathIdx']
+ if target_network == g_dest['Prefix']:
+ g_paths = g_dest['Paths']
+ idx = 0
+ 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
+ self.assertEqual(ans_nexthop, rep_nexthop)
# load configration from gobgp(gobgpd.conf)
def load_gobgp_config(self):