summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/lib/gobgp.py33
-rw-r--r--test/scenario_test/monitor_test.py26
2 files changed, 25 insertions, 34 deletions
diff --git a/test/lib/gobgp.py b/test/lib/gobgp.py
index 07b2c8b0..d16610f0 100644
--- a/test/lib/gobgp.py
+++ b/test/lib/gobgp.py
@@ -20,6 +20,8 @@ import yaml
from itertools import chain
from threading import Thread
import socket
+import subprocess
+import os
def extract_path_attribute(path, typ):
for a in path['attrs']:
@@ -138,24 +140,21 @@ class GoBGPContainer(BGPContainer):
return ret
def monitor_global_rib(self, queue, rf='ipv4'):
+ host = self.ip_addrs[0][1].split('/')[0]
+
+ if not os.path.exists('{0}/gobgp'.format(self.config_dir)):
+ self.local('cp /go/bin/gobgp {0}/'.format(self.SHARED_VOLUME))
+
+ args = '{0}/gobgp -u {1} -j monitor global rib -a {2}'.format(self.config_dir, host, rf).split(' ')
+
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)
- p["local-pref"] = self._get_local_pref(p)
- queue.put(p)
- buf = ''
- else:
- buf += line
- except socket.timeout:
- #self.local('pkill -x gobgp')
- queue.put('timeout')
- return
+ process = subprocess.Popen(args, stdout=subprocess.PIPE)
+ for line in iter(process.stdout.readline, ''):
+ p = json.loads(line)[0]
+ p["nexthop"] = self._get_nexthop(p)
+ p["aspath"] = self._get_as_path(p)
+ p["local-pref"] = self._get_local_pref(p)
+ queue.put(p)
t = Thread(target=monitor)
t.daemon = True
diff --git a/test/scenario_test/monitor_test.py b/test/scenario_test/monitor_test.py
index 8b4fabe5..147391d1 100644
--- a/test/scenario_test/monitor_test.py
+++ b/test/scenario_test/monitor_test.py
@@ -73,15 +73,11 @@ class GoBGPTestBase(unittest.TestCase):
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
+ info = qu.get(timeout=120)
+ cnt += 1
+ print 'monitor got {0}, cnt = {1}'.format(info, cnt)
+ if cnt == len(self.quaggas):
+ break
def test_02_stop_q1(self):
qu = Queue.Queue()
@@ -89,14 +85,10 @@ class GoBGPTestBase(unittest.TestCase):
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
+ info = qu.get(timeout=120)
+ print 'monitor got {0}'.format(info)
+ self.assertTrue(info['isWithdraw'])
+ break
if __name__ == '__main__':