diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-08-05 16:04:39 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-08-08 20:56:46 +0900 |
commit | b895b7678fc796e68a27964a75b1ee2ffea5d256 (patch) | |
tree | 318b3a0278a78d9db7afbdc94bedff2bcc8f8022 /test | |
parent | bf9e135ba85cad641c3812abace9221cbf5a2615 (diff) |
test: use test/lib for route_server_test and route_server_ipv4_v6_test
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'test')
-rw-r--r-- | test/scenario_test/lib/gobgp.py | 2 | ||||
-rw-r--r-- | test/scenario_test/route_server_ipv4_v6_test.py | 280 | ||||
-rw-r--r-- | test/scenario_test/route_server_test.py | 449 |
3 files changed, 364 insertions, 367 deletions
diff --git a/test/scenario_test/lib/gobgp.py b/test/scenario_test/lib/gobgp.py index 4092882a..c7a9631e 100644 --- a/test/scenario_test/lib/gobgp.py +++ b/test/scenario_test/lib/gobgp.py @@ -142,7 +142,7 @@ class GoBGPContainer(BGPContainer): n['Transport'] = {'TransportConfig': {'PassiveMode': True}} if info['is_rs_client']: - n['RouteServer'] = {'RouteServerClient': True} + n['RouteServer'] = {'RouteServerConfig': {'RouteServerClient': True}} if info['is_rr_client']: clusterId = info['cluster_id'] diff --git a/test/scenario_test/route_server_ipv4_v6_test.py b/test/scenario_test/route_server_ipv4_v6_test.py index ce3dc36e..03033260 100644 --- a/test/scenario_test/route_server_ipv4_v6_test.py +++ b/test/scenario_test/route_server_ipv4_v6_test.py @@ -1,4 +1,4 @@ -# Copyright (C) 2014 Nippon Telegraph and Telephone Corporation. +# Copyright (C) 2015 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. @@ -13,167 +13,143 @@ # See the License for the specific language governing permissions and # limitations under the License. -import time +import unittest +from fabric.api import local +from lib import base +from lib.gobgp import * +from lib.quagga import * import sys +import os +import time import nose -import quagga_access as qaccess -import docker_control as fab -from gobgp_test import GoBGPTestBase -from gobgp_test import ADJ_RIB_IN, ADJ_RIB_OUT, LOCAL_RIB, GLOBAL_RIB -from gobgp_test import NEIGHBOR -from noseplugin import OptionParser -from noseplugin import parser_option - -class GoBGPIPv6Test(GoBGPTestBase): - quagga_num = 2 - append_quagga = 10 - remove_quagga = 10 - append_quagga_best = 20 - - def __init__(self, *args, **kwargs): - super(GoBGPIPv6Test, self).__init__(*args, **kwargs) - - # test each neighbor state is turned establish - def test_01_ipv4_ipv6_neighbor_established(self): - print "test_ipv4_ipv6_neighbor_established" - - image = parser_option.gobgp_image - go_path = parser_option.go_path - log_debug = True if parser_option.gobgp_log_level == 'debug' else False - fab.init_ipv6_test_env_executor(self.quagga_num, image, go_path, log_debug) - print "please wait (" + str(self.initial_wait_time) + " second)" - time.sleep(self.initial_wait_time) - fab.docker_container_ipv6_quagga_append_executor([3, 4], go_path) - print "please wait (" + str(self.initial_wait_time) + " second)" - time.sleep(self.initial_wait_time) - if self.check_load_config() is False: - return - - addresses = self.get_neighbor_address(self.gobgp_config) - self.retry_routine_for_state(addresses, "BGP_FSM_ESTABLISHED") - - for address in addresses: - # get neighbor state and remote ip from gobgp connections - print "check of [ " + address + " ]" - neighbor = self.ask_gobgp(NEIGHBOR, address) - state = neighbor['info']['bgp_state'] - remote_ip = neighbor['conf']['remote_ip'] - self.assertEqual(address, remote_ip) - self.assertEqual(state, "BGP_FSM_ESTABLISHED") - print "state" + state - - def test_02_ipv4_ipv6_received_route(self): - print "test_ipv4_ipv6_received_route" - if self.check_load_config() is False: - return - - for address in self.get_neighbor_address(self.gobgp_config): - print "check of [ " + address + " ]" - af = fab.IPv6 if ":" in address else fab.IPv4 - - def check_func(): - local_rib = self.ask_gobgp(LOCAL_RIB, address, af) - - for quagga_config in self.quagga_configs: - if quagga_config.peer_ip == address or quagga_config.ip_version != af: - for c_dest in quagga_config.destinations.itervalues(): - # print "config : ", c_dest.prefix, "my ip or different ip version!!!" - exist_n = 0 - for g_dest in local_rib: - if c_dest.prefix == g_dest['prefix']: - exist_n += 1 - if exist_n != 0: - return False - else: - for c_dest in quagga_config.destinations.itervalues(): - exist_n = 0 - for g_dest in local_rib: - if c_dest.prefix == g_dest['prefix']: - exist_n += 1 - if exist_n != 1: - return False - return True - - retry_count = 0 - cmp_result = False - while retry_count < self.dest_check_limit: - - cmp_result = check_func() - - if cmp_result: - print "compare OK" +from noseplugin import OptionParser, parser_option + + +class GoBGPIPv6Test(unittest.TestCase): + + wait_per_retry = 5 + retry_limit = 15 + + @classmethod + def setUpClass(cls): + gobgp_ctn_image_name = parser_option.gobgp_image + base.TEST_PREFIX = parser_option.test_prefix + + g1 = GoBGPContainer(name='g1', asn=65002, router_id='192.168.0.2', + ctn_image_name=gobgp_ctn_image_name, + log_level=parser_option.gobgp_log_level) + q1 = QuaggaBGPContainer(name='q1', asn=65003, router_id='192.168.0.3') + q2 = QuaggaBGPContainer(name='q2', asn=65004, router_id='192.168.0.4') + q3 = QuaggaBGPContainer(name='q3', asn=65005, router_id='192.168.0.5') + q4 = QuaggaBGPContainer(name='q4', asn=65006, router_id='192.168.0.6') + + ctns = [g1, q1, q2, q3, q4] + v4 = [q1, q2] + v6 = [q3, q4] + + for idx, q in enumerate(v4): + route = '10.0.{0}.0/24'.format(idx+1) + q.add_route(route) + + for idx, q in enumerate(v6): + route = '2001:{0}::/96'.format(idx+1) + q.add_route(route) + + initial_wait_time = max(ctn.run() for ctn in ctns) + + time.sleep(initial_wait_time) + + br01 = Bridge(name='br01', subnet='192.168.10.0/24') + br01.addif(g1) + for ctn in v4: + br01.addif(ctn) + g1.add_peer(ctn, is_rs_client=True) + ctn.add_peer(g1) + + br02 = Bridge(name='br02', subnet='2001::/96') + br02.addif(g1) + for ctn in v6: + br02.addif(ctn) + g1.add_peer(ctn, is_rs_client=True) + ctn.add_peer(g1) + + cls.gobgp = g1 + cls.quaggas = {'q1': q1, 'q2': q2, 'q3': q3, 'q4': q4} + cls.bridges = {'br01': br01, 'br02': br02} + cls.ipv4s = {'q1': q1, 'q2': q2} + cls.ipv6s = {'q3': q3, 'q4': q4} + + def check_gobgp_local_rib(self, ctns, rf): + for rs_client in ctns.itervalues(): + done = False + for _ in range(self.retry_limit): + if done: break - else: - retry_count += 1 - print "compare NG -> retry ( %d / %d )" % (retry_count, self.dest_check_limit) + local_rib = self.gobgp.get_local_rib(rs_client, rf) + local_rib = [p['prefix'] for p in local_rib] + if len(local_rib) < len(ctns)-1: time.sleep(self.wait_per_retry) - - self.assertEqual(cmp_result, True) - - def test_03_advertising_route(self): - print "test_advertising_route" - if self.check_load_config() is False: - return - - for address in self.get_neighbor_address(self.gobgp_config): - print "check of [ " + address + " ]" - af = fab.IPv6 if ":" in address else fab.IPv4 - - def check_func(): - tn = qaccess.login(address) - q_rib = qaccess.show_rib(tn, af) - - for quagga_config in self.quagga_configs: - if quagga_config.peer_ip == address or quagga_config.ip_version != af: - for c_dest in quagga_config.destinations.itervalues(): - exist_n = 0 - for c_path in c_dest.paths: - # print "conf : ", c_path.network, c_path.nexthop, "my ip or different ip version!!!" - for q_path in q_rib: - # print "quag : ", q_path['Network'], q_path['Next Hop'] - if "0.0.0.0" == q_path['Next Hop'] or "::" == q_path['Next Hop']: - continue - if c_path.network.split("/")[0] == q_path['Network']: - exist_n += 1 - if exist_n != 0: - return False - else: - for c_dest in quagga_config.destinations.itervalues(): - exist_n = 0 - for c_path in c_dest.paths: - # print "conf : ", c_path.network, c_path.nexthop - for q_path in q_rib: - # print "quag : ", q_path['Network'], q_path['Next Hop'] - if quagga_config.ip_version != fab.IPv6: - c_path.network = c_path.network.split("/")[0] - if c_path.network == q_path['Network'] and c_path.nexthop == q_path['Next Hop']: - exist_n += 1 - if exist_n != 1: - return False - return True - - retry_count = 0 - check_result = False - while retry_count < self.dest_check_limit: - - check_result = check_func() - - if check_result: - print "compare OK" + continue + + self.assertTrue(len(local_rib) == (len(ctns)-1)) + + for c in ctns.itervalues(): + if rs_client != c: + for r in c.routes: + self.assertTrue(r in local_rib) + + done = True + if done: + continue + # should not reach here + self.assertTrue(False) + + def check_rs_client_rib(self, ctns, rf): + for rs_client in ctns.itervalues(): + done = False + for _ in range(self.retry_limit): + if done: break - else: - retry_count += 1 - print "compare NG -> retry ( %d / %d )" % (retry_count, self.dest_check_limit) + global_rib = rs_client.get_global_rib(rf=rf) + global_rib = [p['prefix'] for p in global_rib] + if len(global_rib) < len(ctns): time.sleep(self.wait_per_retry) + continue + + self.assertTrue(len(global_rib) == len(ctns)) + + for c in ctns.itervalues(): + for r in c.routes: + self.assertTrue(r in global_rib) + + done = True + if done: + continue + # should not reach here + self.assertTrue(False) + + # test each neighbor state is turned establish + def test_01_neighbor_established(self): + for q in self.quaggas.itervalues(): + self.gobgp.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=q) + + def test_02_check_ipv4_peer_rib(self): + self.check_gobgp_local_rib(self.ipv4s, 'ipv4') + self.check_rs_client_rib(self.ipv4s, 'ipv4') + + def test_03_check_ipv6_peer_rib(self): + self.check_gobgp_local_rib(self.ipv6s, 'ipv6') + self.check_rs_client_rib(self.ipv6s, 'ipv6') - self.assertEqual(check_result, True) if __name__ == '__main__': - if fab.test_user_check() is False: + if os.geteuid() is not 0: print "you are not root." sys.exit(1) - if fab.docker_pkg_check() is False: - print "not install docker package." + output = local("which docker 2>&1 > /dev/null ; echo $?", capture=True) + if int(output) is not 0: + print "docker not found" sys.exit(1) - nose.main(argv=sys.argv, addplugins=[OptionParser()], defaultTest=sys.argv[0]) + nose.main(argv=sys.argv, addplugins=[OptionParser()], + defaultTest=sys.argv[0]) diff --git a/test/scenario_test/route_server_test.py b/test/scenario_test/route_server_test.py index db75e97d..12b4e65c 100644 --- a/test/scenario_test/route_server_test.py +++ b/test/scenario_test/route_server_test.py @@ -1,4 +1,4 @@ -# Copyright (C) 2014 Nippon Telegraph and Telephone Corporation. +# Copyright (C) 2015 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. @@ -13,232 +13,253 @@ # See the License for the specific language governing permissions and # limitations under the License. -import time +import unittest +from fabric.api import local +from lib import base +from lib.gobgp import * +from lib.quagga import * import sys +import os +import time import nose -import quagga_access as qaccess -import docker_control as fab -from gobgp_test import GoBGPTestBase -from gobgp_test import LOCAL_RIB -from gobgp_test import NEIGHBOR -from noseplugin import OptionParser -from noseplugin import parser_option - -class GoBGPTest(GoBGPTestBase): - quagga_num = 3 - append_quagga = 10 - remove_quagga = 10 - append_quagga_best = 20 - - def __init__(self, *args, **kwargs): - super(GoBGPTest, self).__init__(*args, **kwargs) +from noseplugin import OptionParser, parser_option + + +class GoBGPTestBase(unittest.TestCase): + + wait_per_retry = 5 + retry_limit = 10 + + @classmethod + def setUpClass(cls): + gobgp_ctn_image_name = parser_option.gobgp_image + base.TEST_PREFIX = parser_option.test_prefix + + g1 = GoBGPContainer(name='g1', asn=65000, router_id='192.168.0.1', + ctn_image_name=gobgp_ctn_image_name, + log_level=parser_option.gobgp_log_level) + + rs_clients = [QuaggaBGPContainer(name='q{0}'.format(i+1), asn=65001+i, + router_id='192.168.0.{0}'.format(i+2)) + for i in range(3)] + ctns = [g1] + rs_clients + q1 = rs_clients[0] + q2 = rs_clients[1] + q3 = rs_clients[2] + + # advertise a route from route-server-clients + routes = [] + for idx, rs_client in enumerate(rs_clients): + route = '10.0.{0}.0/24'.format(idx+1) + rs_client.add_route(route) + routes.append(route) + + initial_wait_time = max(ctn.run() for ctn in ctns) + + time.sleep(initial_wait_time) + + br01 = Bridge(name='br01', subnet='192.168.10.0/24') + [br01.addif(ctn) for ctn in ctns] + + for rs_client in rs_clients: + g1.add_peer(rs_client, is_rs_client=True) + rs_client.add_peer(g1) + + cls.gobgp = g1 + cls.quaggas = {'q1': q1, 'q2': q2, 'q3': q3} + cls.bridges = {'br01': br01} + + def check_gobgp_local_rib(self): + for rs_client in self.quaggas.itervalues(): + done = False + for _ in range(self.retry_limit): + if done: + break + local_rib = self.gobgp.get_local_rib(rs_client) + local_rib = [p['prefix'] for p in local_rib] + if len(local_rib) < len(self.quaggas)-1: + time.sleep(self.wait_per_retry) + continue + + self.assertTrue(len(local_rib) == (len(self.quaggas)-1)) + + for c in self.quaggas.itervalues(): + if rs_client != c: + for r in c.routes: + self.assertTrue(r in local_rib) + + done = True + if done: + continue + # should not reach here + self.assertTrue(False) + + def check_rs_client_rib(self): + for rs_client in self.quaggas.itervalues(): + done = False + for _ in range(self.retry_limit): + if done: + break + global_rib = rs_client.get_global_rib() + global_rib = [p['prefix'] for p in global_rib] + if len(global_rib) < len(self.quaggas): + time.sleep(self.wait_per_retry) + continue + + self.assertTrue(len(global_rib) == len(self.quaggas)) + + for c in self.quaggas.itervalues(): + for r in c.routes: + self.assertTrue(r in global_rib) + + done = True + if done: + continue + # should not reach here + self.assertTrue(False) # test each neighbor state is turned establish def test_01_neighbor_established(self): - print "test_neighbor_established" - - image = parser_option.gobgp_image - go_path = parser_option.go_path - log_debug = True if parser_option.gobgp_log_level == 'debug' else False - fab.init_test_env_executor(self.quagga_num, image, go_path, log_debug) - - print "please wait " + str(self.initial_wait_time) + " second" - time.sleep(self.initial_wait_time) - if self.check_load_config() is False: - return - - addresses = self.get_neighbor_address(self.gobgp_config) - self.retry_routine_for_state(addresses, "BGP_FSM_ESTABLISHED") - - for address in addresses: - # get neighbor state and remote ip from gobgp connections - print "check of [ " + address + " ]" - neighbor = self.ask_gobgp(NEIGHBOR, address) - state = neighbor['info']['bgp_state'] - remote_ip = neighbor['conf']['remote_ip'] - self.assertEqual(address, remote_ip) - self.assertEqual(state, "BGP_FSM_ESTABLISHED") - - # Test of advertised route gobgp from each quagga - def test_02_received_route(self): - print "test_received_route" - if self.check_load_config() is False: - return - - for neighbor_address in self.get_neighbor_address(self.gobgp_config): - self.assert_local_rib(neighbor_address) - - # Test of advertising route to each quagga form gobgp - def test_03_advertising_route(self): - print "test_advertising_route" - if self.check_load_config() is False: - return - - for neighbor_address in self.get_neighbor_address(self.gobgp_config): - self.assert_quagga_rib(neighbor_address) + for q in self.quaggas.itervalues(): + self.gobgp.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=q) - # 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, go_path) - print "please wait " + str(self.initial_wait_time) + " second" - time.sleep(self.initial_wait_time) - append_quagga_address = "10.0.0." + str(self.append_quagga) - self.retry_routine_for_state([append_quagga_address], "BGP_FSM_ESTABLISHED") - - # get neighbor state and remote ip of new quagga - print "check of [" + append_quagga_address + " ]" - neighbor = self.ask_gobgp(NEIGHBOR, append_quagga_address) - state = neighbor['info']['bgp_state'] - remote_ip = neighbor['conf']['remote_ip'] - self.assertEqual(append_quagga_address, remote_ip) - self.assertEqual(state, "BGP_FSM_ESTABLISHED") - - # Test of advertised route gobgp from each quagga when append quagga container - def test_05_received_route_when_appended_quagga(self): - print "test_received_route_by_appended_quagga" - if self.check_load_config() is False: - return - - for neighbor_address in self.get_neighbor_address(self.gobgp_config): - self.assert_local_rib(neighbor_address) - - # Test of advertising route to each quagga form gobgp when append quagga container - def test_06_advertising_route_when_appended_quagga(self): - print "test_advertising_route_to_appended_quagga" - if self.check_load_config() is False: - return - - for neighbor_address in self.get_neighbor_address(self.gobgp_config): - self.assert_quagga_rib(neighbor_address) - - 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) - print "please wait " + str(self.initial_wait_time) + " second" - time.sleep(self.initial_wait_time) - removed_quagga_address = "10.0.0." + str(self.remove_quagga) - self.retry_routine_for_state([removed_quagga_address], "BGP_FSM_ACTIVE") - - # get neighbor state and remote ip of removed quagga - print "check of [" + removed_quagga_address + " ]" - neighbor = self.ask_gobgp(NEIGHBOR, removed_quagga_address) - state = neighbor['info']['bgp_state'] - remote_ip = neighbor['conf']['remote_ip'] - self.assertEqual(removed_quagga_address, remote_ip) - self.assertEqual(state, "BGP_FSM_ACTIVE") - - def test_08_received_route_when_quagga_removed(self): - print "test_received_route_when_removed_quagga" - if self.check_load_config() is False: - return - - remove_quagga_address = "10.0.0." + str(self.remove_quagga) - for neighbor_address in self.get_neighbor_address(self.gobgp_config): - if remove_quagga_address == neighbor_address: - continue - self.assert_local_rib(neighbor_address) + # check advertised routes are stored in route-server's local-rib + def test_02_check_gobgp_local_rib(self): + self.check_gobgp_local_rib() - def test_09_advertising_route_when_quagga_removed(self): - print "test_advertising_route_when_removed_quagga" - if self.check_load_config() is False: - return + # check gobgp's global rib. when configured as route-server, global rib + # must be empty + def test_03_check_gobgp_global_rib(self): + self.assertTrue(len(self.gobgp.get_global_rib()) == 0) - remove_quagga_address = "10.0.0." + str(self.remove_quagga) - for neighbor_address in self.get_neighbor_address(self.gobgp_config): - if remove_quagga_address == neighbor_address: - continue - self.assert_quagga_rib(neighbor_address) - - def test_10_bestpath_selection_of_received_route(self): - print "test_bestpath_selection_of_received_route" - 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 " + str(self.initial_wait_time) + " second" - time.sleep(self.initial_wait_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 " + str(self.initial_wait_time) + " second" - time.sleep(self.initial_wait_time) - - check_address = "10.0.0.1" - target_network = "192.168.20.0/24" - ans_nexthop = "10.0.0.3" - - print "check of [ " + check_address + " ]" - self.retry_routine_for_bestpath(check_address, target_network, ans_nexthop) - - - def assert_local_rib(self, address): - print "check local_rib : neighbor address [ " + address + " ]" - # get local-rib per peer - retry_count = 0 - cmp_result = False - while retry_count < self.dest_check_limit: - local_rib = self.ask_gobgp(LOCAL_RIB, address) - cmp_result = self.compare_rib_with_quagga_configs(address, - local_rib) - if cmp_result: - print "compare OK" - break - else: - retry_count += 1 - print "compare NG -> retry ( %d / %d )" % (retry_count, self.dest_check_limit) - time.sleep(self.wait_per_retry) - self.assertTrue(cmp_result) - - - def assert_quagga_rib(self, address): - print "check quagga_rib : neighbor address [ " + address + " ]" - retry_count = 0 - cmp_result = False - while retry_count < self.dest_check_limit: - tn = qaccess.login(address) - q_rib = qaccess.show_rib(tn) - cmp_result = self.compare_route_with_quagga_configs(address, q_rib) - - if cmp_result: - print "compare OK" - break - else: - retry_count += 1 - print "compare NG -> retry ( %d / %d )" % (retry_count, self.dest_check_limit) + # check routes are properly advertised to route-server-client + def test_04_check_rs_clients_rib(self): + self.check_rs_client_rib() + + # check if quagga that is appended can establish connection with gobgp + def test_05_add_rs_client(self): + q4 = QuaggaBGPContainer(name='q4', asn=65004, router_id='192.168.0.5') + self.quaggas['q4'] = q4 + + route = '10.0.4.0/24' + q4.add_route(route) + + initial_wait_time = q4.run() + time.sleep(initial_wait_time) + self.bridges['br01'].addif(q4) + self.gobgp.add_peer(q4, is_rs_client=True) + q4.add_peer(self.gobgp) + + self.gobgp.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=q4) + + # check advertised routes are stored in gobgp's local-rib + def test_05_check_gobgp_local_rib(self): + self.check_gobgp_local_rib() + + # check routes are properly advertised to quagga + def test_06_check_rs_clients_rib(self): + self.check_rs_client_rib() + + def test_07_stop_one_rs_client(self): + q4 = self.quaggas['q4'] + q4.stop() + self.gobgp.wait_for(expected_state=BGP_FSM_ACTIVE, peer=q4) + + del self.quaggas['q4'] + + # check a route advertised from q4 is deleted from gobgp's local-rib + def test_08_check_gobgp_local_rib(self): + self.check_gobgp_local_rib() + + # check whether gobgp properly sent withdrawal message with q4's route + def test_09_check_rs_clients_rib(self): + self.check_rs_client_rib() + + def test_10_add_distant_relative(self): + q1 = self.quaggas['q1'] + q2 = self.quaggas['q2'] + q3 = self.quaggas['q3'] + q5 = QuaggaBGPContainer(name='q5', asn=65005, router_id='192.168.0.6') + + initial_wait_time = q5.run() + time.sleep(initial_wait_time) + + br02 = Bridge(name='br02', subnet='192.168.20.0/24') + br02.addif(q5) + br02.addif(q2) + + br03 = Bridge(name='br03', subnet='192.168.30.0/24') + br03.addif(q5) + br03.addif(q3) + + for q in [q2, q3]: + q5.add_peer(q) + q.add_peer(q5) + + med200 = {'name': 'med200', + 'type': 'permit', + 'match': '0.0.0.0/0', + 'direction': 'out', + 'med': 200, + 'priority': 10} + q2.add_policy(med200, self.gobgp) + med100 = {'name': 'med100', + 'type': 'permit', + 'match': '0.0.0.0/0', + 'direction': 'out', + 'med': 100, + 'priority': 10} + q3.add_policy(med100, self.gobgp) + + q5.add_route('10.0.6.0/24') + + q2.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=q5) + q3.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=q5) + self.gobgp.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=q2) + self.gobgp.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=q3) + + def check_nexthop(target_prefix, expected_nexthop): + done = False + for _ in range(self.retry_limit): + if done: + break time.sleep(self.wait_per_retry) - self.assertTrue(cmp_result) + for path in q1.get_global_rib(): + if path['prefix'] == target_prefix: + print "{0}'s nexthop is {1}".format(path['prefix'], + path['nexthop']) + n_addrs = [i[1].split('/')[0] for i in + expected_nexthop.ip_addrs] + if path['nexthop'] in n_addrs: + done = True + break + return done + + done = check_nexthop('10.0.6.0/24', q3) + self.assertTrue(done) + + med300 = {'name': 'med300', + 'type': 'permit', + 'match': '0.0.0.0/0', + 'direction': 'out', + 'med': 300, + 'priority': 5} + q3.add_policy(med300, self.gobgp) + + time.sleep(self.wait_per_retry) + + done = check_nexthop('10.0.6.0/24', q2) + self.assertTrue(done) if __name__ == '__main__': - if fab.test_user_check() is False: + if os.geteuid() is not 0: print "you are not root." sys.exit(1) - if fab.docker_pkg_check() is False: - print "not install docker package." + output = local("which docker 2>&1 > /dev/null ; echo $?", capture=True) + if int(output) is not 0: + print "docker not found" sys.exit(1) - nose.main(argv=sys.argv, addplugins=[OptionParser()], defaultTest=sys.argv[0]) + nose.main(argv=sys.argv, addplugins=[OptionParser()], + defaultTest=sys.argv[0]) |