diff options
-rw-r--r-- | server/server.go | 4 | ||||
-rw-r--r-- | test/lib/base.py | 13 | ||||
-rw-r--r-- | test/lib/exabgp.py | 2 | ||||
-rw-r--r-- | test/lib/gobgp.py | 29 | ||||
-rw-r--r-- | test/pip-requires.txt | 1 | ||||
-rw-r--r-- | test/scenario_test/ci-scripts/travis-build-script.sh | 5 | ||||
-rw-r--r-- | test/scenario_test/monitor_test.py | 112 |
7 files changed, 158 insertions, 8 deletions
diff --git a/server/server.go b/server/server.go index 7f092230..41d2a718 100644 --- a/server/server.go +++ b/server/server.go @@ -478,6 +478,10 @@ func (server *BgpServer) dropPeerAllRoutes(peer *Peer, families []bgp.RouteFamil best, withdrawn := server.globalRib.DeletePathsByPeer(ids, peer.fsm.peerInfo, rf) server.validatePaths(nil, withdrawn, true) + if !peer.isRouteServerClient() && !server.bgpConfig.Global.Collector.Enabled { + server.broadcastBests(best[table.GLOBAL_RIB_NAME]) + } + for _, targetPeer := range server.neighborMap { if peer.isRouteServerClient() != targetPeer.isRouteServerClient() || targetPeer == peer { continue diff --git a/test/lib/base.py b/test/lib/base.py index c0830a34..29920451 100644 --- a/test/lib/base.py +++ b/test/lib/base.py @@ -17,6 +17,7 @@ from fabric.api import local, lcd from fabric import colors from fabric.utils import indent from fabric.state import env, output +from docker import Client import netaddr import os @@ -208,10 +209,14 @@ class Container(object): self.ip_addrs.append((intf_name, ip_addr, bridge.name)) try_several_times(lambda :local(str(c))) - def local(self, cmd, capture=False, flag=''): - return local("docker exec {0} {1} {2}".format(flag, - self.docker_name(), - cmd), capture) + def local(self, cmd, capture=False, stream=False, detach=False): + if stream: + dckr = Client(timeout=120, version='auto') + i = dckr.exec_create(container=self.docker_name(), cmd=cmd) + return dckr.exec_start(i['Id'], tty=True, stream=stream, detach=detach) + else: + flag = '-d' if detach else '' + return local('docker exec {0} {1} {2}'.format(flag, self.docker_name(), cmd), capture) def get_pid(self): if self.is_running: diff --git a/test/lib/exabgp.py b/test/lib/exabgp.py index 5de3d65b..22eaf51f 100644 --- a/test/lib/exabgp.py +++ b/test/lib/exabgp.py @@ -32,7 +32,7 @@ class ExaBGPContainer(BGPContainer): cmd << 'env exabgp.log.destination={0}/exabgpd.log'.format(self.SHARED_VOLUME) cmd << "exabgp.tcp.bind='0.0.0.0' exabgp.tcp.port=179" cmd << './exabgp/sbin/exabgp {0}/exabgpd.conf'.format(self.SHARED_VOLUME) - self.local(str(cmd), flag='-d') + self.local(str(cmd), detach=True) def _update_exabgp(self): if self.exabgp_path == '': diff --git a/test/lib/gobgp.py b/test/lib/gobgp.py index 774113e0..b8413f40 100644 --- a/test/lib/gobgp.py +++ b/test/lib/gobgp.py @@ -17,6 +17,8 @@ from base import * import json import toml from itertools import chain +from threading import Thread +import socket def extract_path_attribute(path, typ): for a in path['attrs']: @@ -52,7 +54,7 @@ class GoBGPContainer(BGPContainer): local(cmd, capture=True) cmd = "chmod 755 {0}/start.sh".format(self.config_dir) local(cmd, capture=True) - self.local("{0}/start.sh".format(self.SHARED_VOLUME), flag='-d') + self.local("{0}/start.sh".format(self.SHARED_VOLUME), detach=True) def graceful_restart(self): self.local("pkill -INT gobgpd") @@ -61,7 +63,7 @@ class GoBGPContainer(BGPContainer): cmd = 'cp {0}/zebra.conf {1}/'.format(self.SHARED_VOLUME, self.QUAGGA_VOLUME) self.local(cmd) cmd = '/usr/lib/quagga/zebra -f {0}/zebra.conf'.format(self.QUAGGA_VOLUME) - self.local(cmd, flag='-d') + self.local(cmd, detach=True) def run(self): super(GoBGPContainer, self).run() @@ -125,6 +127,29 @@ class GoBGPContainer(BGPContainer): p["aspath"] = self._get_as_path(p) return ret + def monitor_global_rib(self, queue, rf='ipv4'): + def monitor(): + it = self.local('gobgp -j monitor global rib -a {0}'.format(rf), stream=True) + buf = '' + try: + for line in it: + if line == '\n': + p = json.loads(buf)[0] + p["nexthop"] = self._get_nexthop(p) + p["aspath"] = self._get_as_path(p) + queue.put(p) + buf = '' + else: + buf += line + except socket.timeout: + #self.local('pkill -x gobgp') + queue.put('timeout') + return + + t = Thread(target=monitor) + t.daemon = True + t.start() + def _get_adj_rib(self, adj_type, peer, prefix='', rf='ipv4'): if peer not in self.peers: raise Exception('not found peer {0}'.format(peer.router_id)) diff --git a/test/pip-requires.txt b/test/pip-requires.txt index f8157aed..85a3bbbc 100644 --- a/test/pip-requires.txt +++ b/test/pip-requires.txt @@ -6,3 +6,4 @@ pycrypto>=2.1 fabric netaddr nsenter +docker-py diff --git a/test/scenario_test/ci-scripts/travis-build-script.sh b/test/scenario_test/ci-scripts/travis-build-script.sh index afc5c89b..5fd5d150 100644 --- a/test/scenario_test/ci-scripts/travis-build-script.sh +++ b/test/scenario_test/ci-scripts/travis-build-script.sh @@ -21,7 +21,7 @@ sudo apt-get -q -y install iputils-arping bridge-utils lv sudo wget https://raw.github.com/jpetazzo/pipework/master/pipework -O /usr/local/bin/pipework sudo chmod 755 /usr/local/bin/pipework -sudo -H pip --quiet install nose toml ciscoconfparse ecdsa "pycrypto>=2.1" fabric netaddr nsenter +sudo -H pip --quiet install -r $GOBGP/test/pip-requires.txt ls -al git log | head -20 @@ -66,6 +66,9 @@ PIDS=("${PIDS[@]}" $!) sudo PYTHONPATH=$GOBGP/test python bgp_zebra_test.py --gobgp-image $GOBGP_IMAGE --test-prefix zebra -x & PIDS=("${PIDS[@]}" $!) +sudo PYTHONPATH=$GOBGP/test python monitor_test.py --gobgp-image $GOBGP_IMAGE --test-prefix mon -x & +PIDS=("${PIDS[@]}" $!) + for (( i = 0; i < ${#PIDS[@]}; ++i )) do wait ${PIDS[$i]} diff --git a/test/scenario_test/monitor_test.py b/test/scenario_test/monitor_test.py new file mode 100644 index 00000000..8b4fabe5 --- /dev/null +++ b/test/scenario_test/monitor_test.py @@ -0,0 +1,112 @@ +# 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 +from itertools import chain +import Queue + + +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) + q1 = QuaggaBGPContainer(name='q1', asn=65001, router_id='192.168.0.2') + q2 = QuaggaBGPContainer(name='q2', asn=65002, router_id='192.168.0.3') + q3 = QuaggaBGPContainer(name='q3', asn=65003, router_id='192.168.0.4') + + qs = [q1, q2, q3] + ctns = [g1, q1, q2, q3] + + # advertise a route from q1, q2, q3 + for idx, q in enumerate(qs): + route = '10.0.{0}.0/24'.format(idx+1) + q.add_route(route) + + initial_wait_time = max(ctn.run() for ctn in ctns) + + time.sleep(initial_wait_time) + + for q in qs: + g1.add_peer(q, reload_config=False, passwd='passwd') + q.add_peer(g1, passwd='passwd', passive=True) + + g1.create_config() + g1.reload_config() + + cls.gobgp = g1 + cls.quaggas = {'q1': q1, 'q2': q2, 'q3': q3} + + def test_01_monitor_initial_adv(self): + qu = Queue.Queue() + self.gobgp.monitor_global_rib(qu) + for q in self.quaggas.itervalues(): + self.gobgp.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=q) + print '{0} get established'.format(q.name) + + cnt = 0 + + while True: + try: + info = qu.get(timeout=1) + if info == 'timeout': + raise Exception('timeout') + cnt += 1 + if cnt == len(self.quaggas): + break + except Queue.Empty: + pass + + def test_02_stop_q1(self): + qu = Queue.Queue() + self.gobgp.monitor_global_rib(qu) + self.quaggas['q1'].stop() + + while True: + try: + info = qu.get(timeout=1) + if info == 'timeout': + raise Exception('timeout') + self.assertTrue(info['isWithdraw']) + break + except Queue.Empty: + pass + + +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]) |