diff options
-rw-r--r-- | test/lib/base.py | 6 | ||||
-rw-r--r-- | test/lib/gobgp.py | 13 | ||||
-rw-r--r-- | test/lib/quagga.py | 2 | ||||
-rw-r--r-- | test/scenario_test/graceful_restart_test.py | 134 | ||||
-rwxr-xr-x | test/scenario_test/run_all_tests.sh | 14 |
5 files changed, 164 insertions, 5 deletions
diff --git a/test/lib/base.py b/test/lib/base.py index 5ab94d8b..37cc26f4 100644 --- a/test/lib/base.py +++ b/test/lib/base.py @@ -247,7 +247,8 @@ class BGPContainer(Container): def add_peer(self, peer, passwd=None, evpn=False, is_rs_client=False, policies=None, passive=False, is_rr_client=False, cluster_id=None, - flowspec=False, bridge='', reload_config=True, as2=False): + flowspec=False, bridge='', reload_config=True, as2=False, + graceful_restart=None): neigh_addr = '' local_addr = '' for me, you in itertools.product(self.ip_addrs, peer.ip_addrs): @@ -274,7 +275,8 @@ class BGPContainer(Container): 'policies': policies, 'passive': passive, 'local_addr': local_addr, - 'as2': as2} + 'as2': as2, + 'graceful_restart': graceful_restart} if self.is_running and reload_config: self.create_config() self.reload_config() diff --git a/test/lib/gobgp.py b/test/lib/gobgp.py index 18e7ddc8..1f956587 100644 --- a/test/lib/gobgp.py +++ b/test/lib/gobgp.py @@ -42,12 +42,11 @@ class GoBGPContainer(BGPContainer): self.default_policy = None self.zebra = zebra - def _start_gobgp(self): - zebra_op = '' + def _start_gobgp(self, graceful_restart=False): c = CmdBuffer() c << '#!/bin/bash' c << '/go/bin/gobgpd -f {0}/gobgpd.conf -l {1} -p {2} > ' \ - '{0}/gobgpd.log 2>&1'.format(self.SHARED_VOLUME, self.log_level, zebra_op) + '{0}/gobgpd.log 2>&1'.format(self.SHARED_VOLUME, self.log_level, '-r' if graceful_restart else '') cmd = 'echo "{0:s}" > {1}/start.sh'.format(c, self.config_dir) local(cmd, capture=True) @@ -55,6 +54,9 @@ class GoBGPContainer(BGPContainer): local(cmd, capture=True) self.local("{0}/start.sh".format(self.SHARED_VOLUME), flag='-d') + def graceful_restart(self): + self.local("pkill -INT gobgpd") + def _start_zebra(self): cmd = 'cp {0}/zebra.conf {1}/'.format(self.SHARED_VOLUME, self.QUAGGA_VOLUME) self.local(cmd) @@ -213,6 +215,11 @@ class GoBGPContainer(BGPContainer): if info['is_rs_client']: n['route-server'] = {'config': {'route-server-client': True}} + if info['graceful_restart'] is not None: + n['graceful-restart'] = {'config': {'enabled': True, 'restart-time': 20}} + for afi_safi in afi_safi_list: + afi_safi['mp-graceful-restart'] = {'config': {'enabled': True}} + if info['is_rr_client']: clusterId = self.router_id if 'cluster_id' in info and info['cluster_id'] is not None: diff --git a/test/lib/quagga.py b/test/lib/quagga.py index 30f036f0..81c8f666 100644 --- a/test/lib/quagga.py +++ b/test/lib/quagga.py @@ -178,6 +178,8 @@ class QuaggaBGPContainer(BGPContainer): c << 'password zebra' c << 'router bgp {0}'.format(self.asn) c << 'bgp router-id {0}'.format(self.router_id) + if any(info['graceful_restart'] for info in self.peers.itervalues()): + c << 'bgp graceful-restart' version = 4 for peer, info in self.peers.iteritems(): diff --git a/test/scenario_test/graceful_restart_test.py b/test/scenario_test/graceful_restart_test.py new file mode 100644 index 00000000..9b97b82b --- /dev/null +++ b/test/scenario_test/graceful_restart_test.py @@ -0,0 +1,134 @@ +# Copyright (C) 2016 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. + +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 +from noseplugin import OptionParser, parser_option + +class GoBGPTestBase(unittest.TestCase): + + @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) + g2 = GoBGPContainer(name='g2', asn=65001, router_id='192.168.0.2', + ctn_image_name=gobgp_ctn_image_name, + log_level=parser_option.gobgp_log_level) + ctns = [g1, g2] + + initial_wait_time = max(ctn.run() for ctn in ctns) + + time.sleep(initial_wait_time) + + g1.add_route('10.10.10.0/24') + g1.add_route('10.10.20.0/24') + + g1.add_peer(g2, graceful_restart=True) + g2.add_peer(g1, graceful_restart=True) + + cls.bgpds = {'g1': g1, 'g2': g2} + + # test each neighbor state is turned establish + def test_01_neighbor_established(self): + g1 = self.bgpds['g1'] + g2 = self.bgpds['g2'] + g1.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=g2) + + def test_02_graceful_restart(self): + g1 = self.bgpds['g1'] + g2 = self.bgpds['g2'] + g1.graceful_restart() + g2.wait_for(expected_state=BGP_FSM_ACTIVE, peer=g1) + self.assertTrue(len(g2.get_global_rib('10.10.20.0/24')) == 1) + self.assertTrue(len(g2.get_global_rib('10.10.10.0/24')) == 1) + for d in g2.get_global_rib(): + for p in d['paths']: + self.assertTrue(p['stale']) + + g1.routes = {} + g1._start_gobgp(graceful_restart=True) + time.sleep(3) + g1.add_route('10.10.20.0/24') + + def test_03_neighbor_established(self): + g1 = self.bgpds['g1'] + g2 = self.bgpds['g2'] + g1.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=g2) + time.sleep(1) + self.assertTrue(len(g2.get_global_rib('10.10.20.0/24')) == 1) + self.assertTrue(len(g2.get_global_rib('10.10.10.0/24')) == 0) + for d in g2.get_global_rib(): + for p in d['paths']: + self.assertFalse(p['stale']) + + def test_04_add_non_graceful_restart_enabled_peer(self): + g1 = self.bgpds['g1'] + g2 = self.bgpds['g2'] + gobgp_ctn_image_name = parser_option.gobgp_image + g3 = GoBGPContainer(name='g3', asn=65002, router_id='192.168.0.3', + ctn_image_name=gobgp_ctn_image_name, + log_level=parser_option.gobgp_log_level) + self.bgpds['g3'] = g3 + time.sleep(g3.run()) + g3.add_route('10.10.30.0/24') + g1.add_peer(g3) + g3.add_peer(g1) + g1.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=g3) + time.sleep(1) + self.assertTrue(len(g3.get_global_rib('10.10.20.0/24')) == 1) + + def test_05_graceful_restart(self): + g1 = self.bgpds['g1'] + g2 = self.bgpds['g2'] + g3 = self.bgpds['g3'] + g1.graceful_restart() + g2.wait_for(expected_state=BGP_FSM_ACTIVE, peer=g1) + self.assertTrue(len(g2.get_global_rib('10.10.20.0/24')) == 1) + self.assertTrue(len(g2.get_global_rib('10.10.30.0/24')) == 1) + for d in g2.get_global_rib(): + for p in d['paths']: + self.assertTrue(p['stale']) + + self.assertTrue(len(g3.get_global_rib('10.10.20.0/24')) == 0) + self.assertTrue(len(g3.get_global_rib('10.10.30.0/24')) == 1) + + def test_06_test_restart_timer_expire(self): + time.sleep(25) + g2 = self.bgpds['g2'] + self.assertTrue(len(g2.get_global_rib()) == 0) + + +if __name__ == '__main__': + if os.geteuid() is not 0: + print "you are not root." + sys.exit(1) + 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]) diff --git a/test/scenario_test/run_all_tests.sh b/test/scenario_test/run_all_tests.sh index b9d196dd..ec2dfa2e 100755 --- a/test/scenario_test/run_all_tests.sh +++ b/test/scenario_test/run_all_tests.sh @@ -71,6 +71,20 @@ PIDS=("${PIDS[@]}" $!) sudo -E PYTHONPATH=$GOBGP/test python route_server_as2_test.py --gobgp-image $GOBGP_IMAGE --test-prefix as2 -s -x --with-xunit --xunit-file=${WS}/nosetest_rs_as2.xml & PIDS=("${PIDS[@]}" $!) +# graceful restart test +sudo -E PYTHONPATH=$GOBGP/test python graceful_restart_test.py --gobgp-image $GOBGP_IMAGE --test-prefix gr -s -x --with-xunit --xunit-file=${WS}/nosetest_rs_gr.xml & +PIDS=("${PIDS[@]}" $!) + +for (( i = 0; i < ${#PIDS[@]}; ++i )) +do + wait ${PIDS[$i]} + if [ $? != 0 ]; then + exit 1 + fi +done + +PIDS=() + # route server malformed message test NUM=$(sudo -E PYTHONPATH=$GOBGP/test python route_server_malformed_test.py --test-index -1 -s 2> /dev/null | awk '/invalid/{print $NF}') PARALLEL_NUM=10 |