diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/lib/base.py | 12 | ||||
-rw-r--r-- | test/lib/exabgp.py | 8 | ||||
-rw-r--r-- | test/lib/gobgp.py | 2 |
3 files changed, 16 insertions, 6 deletions
diff --git a/test/lib/base.py b/test/lib/base.py index d7d33f40..19452896 100644 --- a/test/lib/base.py +++ b/test/lib/base.py @@ -409,14 +409,24 @@ class BGPContainer(Container): def log(self): return local('cat {0}/*.log'.format(self.config_dir), capture=True) + def _extract_routes(self, families): + routes = {} + for prefix, paths in self.routes.items(): + if paths and paths[0]['rf'] in families: + routes[prefix] = paths + return routes + def add_route(self, route, rf='ipv4', attribute=None, aspath=None, community=None, med=None, extendedcommunity=None, nexthop=None, matchs=None, thens=None, local_pref=None, identifier=None, reload_config=True): if route not in self.routes: self.routes[route] = [] + prefix = route + if 'flowspec' in rf: + prefix = ' '.join(['match'] + matchs) self.routes[route].append({ - 'prefix': route, + 'prefix': prefix, 'rf': rf, 'attr': attribute, 'next-hop': nexthop, diff --git a/test/lib/exabgp.py b/test/lib/exabgp.py index efc39ac1..3bb9d207 100644 --- a/test/lib/exabgp.py +++ b/test/lib/exabgp.py @@ -15,11 +15,11 @@ from __future__ import absolute_import +from itertools import chain import time from fabric import colors from fabric.api import local -from itertools import chain from lib.base import ( BGPContainer, @@ -124,11 +124,11 @@ class ExaBGPContainer(BGPContainer): cmd << '{0};'.format(str(r)) cmd << ' }' - routes = [r for r in chain.from_iterable(self.routes.itervalues()) if 'flowspec' in r['rf']] - if len(routes) > 0: + routes = self._extract_routes(['ipv4-flowspec', 'ipv6-flowspec']) + for key, routes in routes.items(): cmd << ' flow {' for route in routes: - cmd << ' route {0}{{'.format(route['prefix']) + cmd << ' route {0} {{'.format(key) cmd << ' match {' for match in route['matchs']: cmd << ' {0};'.format(match) diff --git a/test/lib/gobgp.py b/test/lib/gobgp.py index 6422e79d..f0bff6d7 100644 --- a/test/lib/gobgp.py +++ b/test/lib/gobgp.py @@ -559,7 +559,7 @@ class GoBGPContainer(BGPContainer): cmd = 'gobgp global '\ 'rib add match {0} then {1} -a {2}'.format(' '.join(v['matchs']), ' '.join(v['thens']), v['rf']) else: - raise Exception('unsupported route faily: {0}'.format(v['rf'])) + raise Exception('unsupported route family: {0}'.format(v['rf'])) self.local(cmd) def del_route(self, route, identifier=None, reload_config=True): |