summaryrefslogtreecommitdiffhomepage
path: root/test/lib
diff options
context:
space:
mode:
Diffstat (limited to 'test/lib')
-rw-r--r--test/lib/base.py13
-rw-r--r--test/lib/exabgp.py2
-rw-r--r--test/lib/gobgp.py29
3 files changed, 37 insertions, 7 deletions
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))