summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--test/scenario_test/bgp_router_test.py40
-rw-r--r--test/scenario_test/bgp_zebra_test.py52
-rw-r--r--test/scenario_test/ci-scripts/build_embeded_go.py2
-rw-r--r--test/scenario_test/evpn_test.py30
-rw-r--r--test/scenario_test/flow_spec_test.py19
-rw-r--r--test/scenario_test/global_policy_test.py26
-rw-r--r--test/scenario_test/graceful_restart_test.py22
-rw-r--r--test/scenario_test/ibgp_router_test.py50
-rw-r--r--test/scenario_test/long_lived_graceful_restart_test.py30
-rw-r--r--test/scenario_test/route_reflector_test.py24
-rw-r--r--test/scenario_test/route_server_as2_test.py38
-rw-r--r--test/scenario_test/route_server_ipv4_v6_test.py33
-rw-r--r--test/scenario_test/route_server_malformed_test.py43
-rw-r--r--test/scenario_test/route_server_policy_grpc_test.py96
-rw-r--r--test/scenario_test/route_server_policy_test.py287
-rw-r--r--test/scenario_test/route_server_softreset_test.py20
-rw-r--r--test/scenario_test/route_server_test.py45
-rw-r--r--test/scenario_test/route_server_test2.py21
-rw-r--r--test/scenario_test/rtc_test.py34
-rw-r--r--test/scenario_test/vrf_neighbor_test.py24
-rw-r--r--test/scenario_test/vrf_neighbor_test2.py21
-rw-r--r--test/scenario_test/zapi_v3_test.py29
22 files changed, 586 insertions, 400 deletions
diff --git a/test/scenario_test/bgp_router_test.py b/test/scenario_test/bgp_router_test.py
index 09f5501b..24f86e77 100644
--- a/test/scenario_test/bgp_router_test.py
+++ b/test/scenario_test/bgp_router_test.py
@@ -13,23 +13,33 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+from __future__ import absolute_import
+
import json
-import unittest
-from fabric.api import local
-from lib import base
-from lib.base import wait_for_completion
-from lib.gobgp import *
-from lib.quagga import *
-from lib.exabgp import *
import sys
-import os
import time
+import unittest
+
+from fabric.api import local
import nose
+
from noseplugin import OptionParser, parser_option
-from itertools import chain
-import ryu.lib.pcaplib as pcap
-from ryu.lib.packet.packet import Packet
-from ryu.lib.packet.bgp import BGPMessage, BGPUpdate
+
+from lib import base
+from lib.base import (
+ BGP_FSM_IDLE,
+ BGP_FSM_ACTIVE,
+ BGP_FSM_ESTABLISHED,
+ BGP_ATTR_TYPE_MULTI_EXIT_DISC,
+ BGP_ATTR_TYPE_LOCAL_PREF,
+ wait_for_completion,
+)
+from lib.gobgp import (
+ GoBGPContainer,
+ extract_path_attribute,
+)
+from lib.quagga import QuaggaBGPContainer
+from lib.exabgp import ExaBGPContainer
class GoBGPTestBase(unittest.TestCase):
@@ -51,7 +61,7 @@ class GoBGPTestBase(unittest.TestCase):
# advertise a route from q1, q2, q3
for idx, q in enumerate(qs):
- route = '10.0.{0}.0/24'.format(idx+1)
+ route = '10.0.{0}.0/24'.format(idx + 1)
q.add_route(route)
initial_wait_time = max(ctn.run() for ctn in ctns)
@@ -109,7 +119,7 @@ class GoBGPTestBase(unittest.TestCase):
# check routes are properly advertised to all BGP speaker
def test_04_check_quagga_global_rib(self):
interval = 1
- timeout = int(120/interval)
+ timeout = int(120 / interval)
for q in self.quaggas.itervalues():
done = False
for _ in range(timeout):
@@ -130,7 +140,7 @@ class GoBGPTestBase(unittest.TestCase):
if done:
continue
# should not reach here
- self.assertTrue(False)
+ raise AssertionError
def test_05_add_quagga(self):
q4 = QuaggaBGPContainer(name='q4', asn=65004, router_id='192.168.0.5')
diff --git a/test/scenario_test/bgp_zebra_test.py b/test/scenario_test/bgp_zebra_test.py
index 24b1477f..8857f801 100644
--- a/test/scenario_test/bgp_zebra_test.py
+++ b/test/scenario_test/bgp_zebra_test.py
@@ -13,17 +13,25 @@
# 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 *
+from __future__ import absolute_import
+
import sys
-import os
import time
+import unittest
+
+from fabric.api import local
import nose
+
from noseplugin import OptionParser, parser_option
-from itertools import chain
+
+from lib import base
+from lib.base import (
+ Bridge,
+ BGP_FSM_ESTABLISHED,
+)
+from lib.gobgp import GoBGPContainer
+from lib.quagga import QuaggaBGPContainer
+
class GoBGPTestBase(unittest.TestCase):
@@ -65,17 +73,20 @@ class GoBGPTestBase(unittest.TestCase):
cls.gobgps = {'ipv4': g1_v4, 'ipv6': g1_v6}
cls.quaggas = {'ipv4': q1_v4, 'ipv6': q1_v6}
cls.others = {'ipv4': [o1_v4, o2_v4], 'ipv6': [o1_v6, o2_v6]}
- cls.bridges = {'br01_v4' : br01_v4,
- 'br02_v4' : br02_v4,
- 'br03_v4' : br03_v4,
- 'br01_v6' : br01_v6,
- 'br02_v6' : br02_v6,
- 'br03_v6' : br03_v6}
+ cls.bridges = {
+ 'br01_v4': br01_v4,
+ 'br02_v4': br02_v4,
+ 'br03_v4': br03_v4,
+ 'br01_v6': br01_v6,
+ 'br02_v6': br02_v6,
+ 'br03_v6': br03_v6,
+ }
"""
No.1 start up ipv4 containers and check state
each neighbor is established in ipv4 environment
"""
+
def test_01_check_neighbor_established(self):
g1 = self.gobgps['ipv4']
q1 = self.quaggas['ipv4']
@@ -99,6 +110,7 @@ class GoBGPTestBase(unittest.TestCase):
No.2 check whether the ping is reachable in container
that have previously beyond the gobpg in ipv4 environment
"""
+
def test_02_check_reachablily_beyond_gobgp_from_quagga(self):
g1 = self.gobgps['ipv4']
q1 = self.quaggas['ipv4']
@@ -108,9 +120,9 @@ class GoBGPTestBase(unittest.TestCase):
for info in g1.ip_addrs:
if 'br01_v4' in info[2]:
next_hop = info[1].split('/')[0]
- self.assertFalse(next_hop == None)
+ self.assertFalse(next_hop is None)
o1.add_static_route(self.bridges['br02_v4'].subnet, next_hop)
- addr = [e[1] for e in o1.ip_addrs if 'br01_v4' in e[2] ]
+ addr = [e[1] for e in o1.ip_addrs if 'br01_v4' in e[2]]
self.assertTrue(len(addr) == 1)
q1.get_reachablily(addr[0])
@@ -118,6 +130,7 @@ class GoBGPTestBase(unittest.TestCase):
No.3 check whether the ping is reachable in container
that have previously beyond the quagga in ipv4 environment
"""
+
def test_03_check_reachablily_beyond_quagga_from_gobgp(self):
g1 = self.gobgps['ipv4']
q1 = self.quaggas['ipv4']
@@ -125,7 +138,7 @@ class GoBGPTestBase(unittest.TestCase):
next_hop = q1.ip_addrs[2][1].split('/')[0]
o2.add_static_route(self.bridges['br02_v4'].subnet, next_hop)
- addr = [e[1] for e in o2.ip_addrs if 'br03_v4' in e[2] ]
+ addr = [e[1] for e in o2.ip_addrs if 'br03_v4' in e[2]]
self.assertTrue(len(addr) == 1)
g1.get_reachablily(addr[0])
@@ -133,6 +146,7 @@ class GoBGPTestBase(unittest.TestCase):
No.4 start up ipv4 containers and check state
each neighbor is established in ipv6 environment
"""
+
def test_04_check_neighbor_established_v6(self):
g1 = self.gobgps['ipv6']
q1 = self.quaggas['ipv6']
@@ -156,6 +170,7 @@ class GoBGPTestBase(unittest.TestCase):
No.5 check whether the ping is reachable in container
that have previously beyond the gobpg in ipv6 environment
"""
+
def test_05_check_reachablily_beyond_gobgp_from_quagga(self):
g1 = self.gobgps['ipv6']
q1 = self.quaggas['ipv6']
@@ -164,7 +179,7 @@ class GoBGPTestBase(unittest.TestCase):
next_hop = g1.ip_addrs[1][1].split('/')[0]
g1.set_ipv6_forward()
o1.add_static_route(self.bridges['br02_v6'].subnet, next_hop)
- addr = [e[1] for e in o1.ip_addrs if 'br01_v6' in e[2] ]
+ addr = [e[1] for e in o1.ip_addrs if 'br01_v6' in e[2]]
self.assertTrue(len(addr) == 1)
q1.get_reachablily(addr[0])
@@ -172,6 +187,7 @@ class GoBGPTestBase(unittest.TestCase):
No.6 check whether the ping is reachable in container
that have previously beyond the quagga in ipv6 environment
"""
+
def test_06_check_reachablily_beyond_quagga_from_gobgp(self):
g1 = self.gobgps['ipv6']
q1 = self.quaggas['ipv6']
@@ -180,7 +196,7 @@ class GoBGPTestBase(unittest.TestCase):
next_hop = q1.ip_addrs[2][1].split('/')[0]
q1.set_ipv6_forward()
o2.add_static_route(self.bridges['br02_v6'].subnet, next_hop)
- addr = [e[1] for e in o2.ip_addrs if 'br03_v6' in e[2] ]
+ addr = [e[1] for e in o2.ip_addrs if 'br03_v6' in e[2]]
self.assertTrue(len(addr) == 1)
g1.get_reachablily(addr[0])
diff --git a/test/scenario_test/ci-scripts/build_embeded_go.py b/test/scenario_test/ci-scripts/build_embeded_go.py
index 1fc70bca..e0f17e56 100644
--- a/test/scenario_test/ci-scripts/build_embeded_go.py
+++ b/test/scenario_test/ci-scripts/build_embeded_go.py
@@ -2,6 +2,7 @@ import sys
import os
from subprocess import call
+
def cut(filename, out):
with open(filename, 'r') as f:
flag = False
@@ -16,6 +17,7 @@ def cut(filename, out):
elif flag:
codes.append(line)
+
if __name__ == '__main__':
filename = sys.argv[1]
out = '/tmp/test.go'
diff --git a/test/scenario_test/evpn_test.py b/test/scenario_test/evpn_test.py
index ac83fe2d..5e2637c8 100644
--- a/test/scenario_test/evpn_test.py
+++ b/test/scenario_test/evpn_test.py
@@ -13,22 +13,30 @@
# 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 *
+from __future__ import absolute_import
+
+from itertools import combinations
import sys
-import os
import time
+import unittest
+
+from fabric.api import local
import nose
+
from noseplugin import OptionParser, parser_option
-from itertools import combinations
+
+from lib import base
+from lib.base import (
+ BGP_FSM_ESTABLISHED,
+ BGP_ATTR_TYPE_EXTENDED_COMMUNITIES,
+)
+from lib.gobgp import GoBGPContainer
+
def get_mac_mobility_sequence(pattr):
- for ecs in [p['value'] for p in pattr
- if 'type' in p and \
- p['type'] == BGP_ATTR_TYPE_EXTENDED_COMMUNITIES]:
+ for ecs in [
+ p['value'] for p in pattr
+ if 'type' in p and p['type'] == BGP_ATTR_TYPE_EXTENDED_COMMUNITIES]:
for ec in [e for e in ecs if 'type' in e and e['type'] == 6]:
if ec['subtype'] == 0:
if 'sequence' not in ec:
@@ -82,7 +90,7 @@ class GoBGPTestBase(unittest.TestCase):
self.assertTrue(path['nexthop'] == '0.0.0.0')
interval = 1
- timeout = int(30/interval)
+ timeout = int(30 / interval)
done = False
for _ in range(timeout):
if done:
diff --git a/test/scenario_test/flow_spec_test.py b/test/scenario_test/flow_spec_test.py
index 950ed0bf..89918f6b 100644
--- a/test/scenario_test/flow_spec_test.py
+++ b/test/scenario_test/flow_spec_test.py
@@ -13,17 +13,22 @@
# 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.exabgp import *
+from __future__ import absolute_import
+
+from itertools import combinations
import sys
-import os
import time
+import unittest
+
+from fabric.api import local
import nose
+
from noseplugin import OptionParser, parser_option
-from itertools import combinations
+
+from lib import base
+from lib.base import BGP_FSM_ESTABLISHED
+from lib.gobgp import GoBGPContainer
+from lib.exabgp import ExaBGPContainer
class GoBGPTestBase(unittest.TestCase):
diff --git a/test/scenario_test/global_policy_test.py b/test/scenario_test/global_policy_test.py
index 1e1b85b0..13eaabb4 100644
--- a/test/scenario_test/global_policy_test.py
+++ b/test/scenario_test/global_policy_test.py
@@ -13,17 +13,25 @@
# 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.exabgp import *
+from __future__ import absolute_import
+
import sys
-import os
import time
+import unittest
+
+from fabric.api import local
import nose
+
from noseplugin import OptionParser, parser_option
-from itertools import chain
+
+from lib import base
+from lib.base import (
+ BGP_FSM_IDLE,
+ BGP_FSM_ESTABLISHED,
+ BGP_ATTR_TYPE_COMMUNITIES,
+)
+from lib.gobgp import GoBGPContainer
+from lib.exabgp import ExaBGPContainer
def community_exists(path, com):
@@ -55,7 +63,7 @@ class GoBGPTestBase(unittest.TestCase):
# advertise a route from q1, q2, q3
for idx, q in enumerate(qs):
- route = '10.0.{0}.0/24'.format(idx+1)
+ route = '10.0.{0}.0/24'.format(idx + 1)
q.add_route(route)
initial_wait_time = max(ctn.run() for ctn in ctns)
@@ -184,7 +192,7 @@ class GoBGPTestBase(unittest.TestCase):
def test_13_check_adj_rib_out(self):
q1 = self.quaggas['q1']
for path in self.gobgp.get_adj_rib_out(q1):
- self.assertTrue(path['local-pref'] == None)
+ self.assertTrue(path['local-pref'] is None)
q5 = self.quaggas['q5']
for path in self.gobgp.get_adj_rib_out(q5):
self.assertTrue(path['local-pref'] == 300)
diff --git a/test/scenario_test/graceful_restart_test.py b/test/scenario_test/graceful_restart_test.py
index 5c8bba65..926bcbd0 100644
--- a/test/scenario_test/graceful_restart_test.py
+++ b/test/scenario_test/graceful_restart_test.py
@@ -13,17 +13,25 @@
# 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 *
+from __future__ import absolute_import
+
import sys
-import os
import time
+import unittest
+
+from fabric.api import local
import nose
+
from noseplugin import OptionParser, parser_option
+from lib import base
+from lib.base import (
+ BGP_FSM_ACTIVE,
+ BGP_FSM_ESTABLISHED,
+)
+from lib.gobgp import GoBGPContainer
+
+
class GoBGPTestBase(unittest.TestCase):
@classmethod
@@ -86,7 +94,7 @@ class GoBGPTestBase(unittest.TestCase):
def test_04_add_non_graceful_restart_enabled_peer(self):
g1 = self.bgpds['g1']
- g2 = self.bgpds['g2']
+ # 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,
diff --git a/test/scenario_test/ibgp_router_test.py b/test/scenario_test/ibgp_router_test.py
index 5eaca936..0a497278 100644
--- a/test/scenario_test/ibgp_router_test.py
+++ b/test/scenario_test/ibgp_router_test.py
@@ -13,18 +13,26 @@
# 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.base import wait_for_completion
-from lib.gobgp import *
-from lib.quagga import *
+from __future__ import absolute_import
+
+from itertools import combinations
import sys
-import os
import time
+import unittest
+
+from fabric.api import local
import nose
+
from noseplugin import OptionParser, parser_option
-from itertools import combinations
+
+from lib import base
+from lib.base import (
+ BGP_FSM_IDLE,
+ BGP_FSM_ESTABLISHED,
+)
+from lib.base import wait_for_completion
+from lib.gobgp import GoBGPContainer
+from lib.quagga import QuaggaBGPContainer
class GoBGPTestBase(unittest.TestCase):
@@ -45,7 +53,7 @@ class GoBGPTestBase(unittest.TestCase):
# advertise a route from q1, q2
for idx, c in enumerate(qs):
- route = '10.0.{0}.0/24'.format(idx+1)
+ route = '10.0.{0}.0/24'.format(idx + 1)
c.add_route(route)
initial_wait_time = max(ctn.run() for ctn in ctns)
@@ -119,7 +127,7 @@ class GoBGPTestBase(unittest.TestCase):
# check routes are properly advertised to all BGP speaker
def test_06_check_quagga_global_rib(self):
interval = 1
- timeout = int(120/interval)
+ timeout = int(120 / interval)
for q in self.quaggas.itervalues():
done = False
for _ in range(timeout):
@@ -134,7 +142,7 @@ class GoBGPTestBase(unittest.TestCase):
peer_info = self.gobgp.peers[q]
local_addr = peer_info['local_addr'].split('/')[0]
- for r in self.gobgp.routes.keys():
+ for r in self.gobgp.routes:
self.assertTrue(r in (p['prefix'] for p in global_rib))
for rr in global_rib:
if rr['prefix'] == r:
@@ -150,7 +158,7 @@ class GoBGPTestBase(unittest.TestCase):
if done:
continue
# should not reach here
- self.assertTrue(False)
+ raise AssertionError
def test_07_add_ebgp_peer(self):
q3 = QuaggaBGPContainer(name='q3', asn=65001, router_id='192.168.0.4')
@@ -174,7 +182,7 @@ class GoBGPTestBase(unittest.TestCase):
q3 = self.quaggas['q3']
paths = self.gobgp.get_adj_rib_out(q3)
total_len = len(q1.routes) + len(q2.routes) + len(self.gobgp.routes)
- assert(len(paths) == total_len)
+ assert len(paths) == total_len
for path in paths:
peer_info = self.gobgp.peers[q3]
local_addr = peer_info['local_addr'].split('/')[0]
@@ -252,9 +260,9 @@ class GoBGPTestBase(unittest.TestCase):
q1 = self.quaggas['q1']
q2 = self.quaggas['q2']
for q in [q1, q2]:
- def f():
+ def _f():
return prefix in [p['nlri']['prefix'] for p in self.gobgp.get_adj_rib_out(q)]
- wait_for_completion(f)
+ wait_for_completion(_f)
def f():
return len(q2.get_global_rib(prefix)) == 1
@@ -267,20 +275,20 @@ class GoBGPTestBase(unittest.TestCase):
prefix = '10.0.4.0/24'
q1.add_route(prefix)
- def f():
+ def f1():
l = self.gobgp.get_global_rib(prefix)
return len(l) == 1 and len(l[0]['paths']) == 2
- wait_for_completion(f)
+ wait_for_completion(f1)
- def f():
+ def f2():
return prefix not in [p['nlri']['prefix'] for p in self.gobgp.get_adj_rib_out(q2)]
- wait_for_completion(f)
+ wait_for_completion(f2)
- def f():
+ def f3():
l = q2.get_global_rib(prefix)
# route from ibgp so aspath should be empty
return len(l) == 1 and len(l[0]['aspath']) == 0
- wait_for_completion(f)
+ wait_for_completion(f3)
if __name__ == '__main__':
diff --git a/test/scenario_test/long_lived_graceful_restart_test.py b/test/scenario_test/long_lived_graceful_restart_test.py
index 53145a03..1f07af08 100644
--- a/test/scenario_test/long_lived_graceful_restart_test.py
+++ b/test/scenario_test/long_lived_graceful_restart_test.py
@@ -13,17 +13,24 @@
# 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 *
+from __future__ import absolute_import
+
+from itertools import chain
import sys
-import os
import time
+import unittest
+
+from fabric.api import local
import nose
+
from noseplugin import OptionParser, parser_option
-from itertools import chain
+
+from lib import base
+from lib.base import (
+ BGP_FSM_ACTIVE,
+ BGP_FSM_ESTABLISHED,
+)
+from lib.gobgp import GoBGPContainer
class GoBGPTestBase(unittest.TestCase):
@@ -97,7 +104,7 @@ class GoBGPTestBase(unittest.TestCase):
self.assertTrue(len(g3.get_global_rib('10.0.0.0/24')) == 1)
# check llgr-stale community is added to 10.0.0.0/24
r = g3.get_global_rib('10.0.0.0/24')[0]['paths'][0]
- comms = list(chain.from_iterable([ attr['communities'] for attr in r['attrs'] if attr['type'] == 8]))
+ comms = list(chain.from_iterable([attr['communities'] for attr in r['attrs'] if attr['type'] == 8]))
self.assertTrue(0xffff0006 in comms)
# g4 is not llgr capable, llgr-stale route must be
# withdrawn
@@ -111,8 +118,8 @@ class GoBGPTestBase(unittest.TestCase):
def test_03_neighbor_established(self):
g1 = self.bgpds['g1']
g2 = self.bgpds['g2']
- g3 = self.bgpds['g3']
- g4 = self.bgpds['g4']
+ # g3 = self.bgpds['g3']
+ # g4 = self.bgpds['g4']
g1.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=g2)
time.sleep(1)
self.assertTrue(len(g1.get_global_rib('10.0.0.0/24')) == 1)
@@ -137,7 +144,7 @@ class GoBGPTestBase(unittest.TestCase):
g1.wait_for(expected_state=BGP_FSM_ACTIVE, peer=g2)
time.sleep(1)
-
+
# llgr_stale route depreference must happend
# check g4's path is chosen as best and advertised
rib = g3.get_global_rib('10.0.0.0/24')
@@ -149,7 +156,6 @@ class GoBGPTestBase(unittest.TestCase):
self.assertTrue(len(rib) == 1)
self.assertTrue(g2.asn in rib[0]['paths'][0]['aspath'])
-
def test_05_llgr_restart_timer_expire(self):
time.sleep(35)
g3 = self.bgpds['g3']
diff --git a/test/scenario_test/route_reflector_test.py b/test/scenario_test/route_reflector_test.py
index 462bde33..28845841 100644
--- a/test/scenario_test/route_reflector_test.py
+++ b/test/scenario_test/route_reflector_test.py
@@ -13,17 +13,22 @@
# 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 *
+from __future__ import absolute_import
+
import sys
-import os
import time
+import unittest
+
+from fabric.api import local
import nose
+
from noseplugin import OptionParser, parser_option
-from itertools import combinations
+
+from lib import base
+from lib.base import BGP_FSM_ESTABLISHED
+from lib.gobgp import GoBGPContainer
+from lib.quagga import QuaggaBGPContainer
+
def wait_for(f, timeout=120):
interval = 1
@@ -58,7 +63,7 @@ class GoBGPTestBase(unittest.TestCase):
# advertise a route from q1, q2
for idx, c in enumerate(qs):
- route = '10.0.{0}.0/24'.format(idx+1)
+ route = '10.0.{0}.0/24'.format(idx + 1)
c.add_route(route)
initial_wait_time = max(ctn.run() for ctn in ctns)
@@ -98,7 +103,7 @@ class GoBGPTestBase(unittest.TestCase):
return len(routes) == 0
wait_for(f)
-
+
def test_03_check_gobgp_adj_rib_out(self):
for q in self.quaggas.itervalues():
paths = [p['nlri']['prefix'] for p in self.gobgp.get_adj_rib_out(q)]
@@ -115,6 +120,7 @@ class GoBGPTestBase(unittest.TestCase):
else:
self.assertFalse(p in paths)
+
if __name__ == '__main__':
output = local("which docker 2>&1 > /dev/null ; echo $?", capture=True)
if int(output) is not 0:
diff --git a/test/scenario_test/route_server_as2_test.py b/test/scenario_test/route_server_as2_test.py
index b391aa46..2c79a5fe 100644
--- a/test/scenario_test/route_server_as2_test.py
+++ b/test/scenario_test/route_server_as2_test.py
@@ -13,17 +13,25 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+from __future__ import absolute_import
+
import unittest
-from fabric.api import local
-from lib import base
-from lib.gobgp import *
-from lib.exabgp import *
import sys
-import os
import time
+
+from fabric.api import local
import nose
+
from noseplugin import OptionParser, parser_option
+from lib import base
+from lib.base import (
+ BGP_FSM_IDLE,
+ BGP_FSM_ESTABLISHED,
+)
+from lib.gobgp import GoBGPContainer
+from lib.exabgp import ExaBGPContainer
+
class GoBGPTestBase(unittest.TestCase):
@@ -39,18 +47,15 @@ class GoBGPTestBase(unittest.TestCase):
ctn_image_name=gobgp_ctn_image_name,
log_level=parser_option.gobgp_log_level)
- rs_clients = [ExaBGPContainer(name='q{0}'.format(i+1), asn=65001+i,
- router_id='192.168.0.{0}'.format(i+2))
- for i in range(4)]
+ rs_clients = [
+ ExaBGPContainer(name='q{0}'.format(i + 1), asn=(65001 + i),
+ router_id='192.168.0.{0}'.format(i + 2))
+ for i in range(4)]
ctns = [g1] + rs_clients
- q1 = rs_clients[0]
- q2 = rs_clients[1]
- q3 = rs_clients[2]
- q4 = rs_clients[3]
# advertise a route from route-server-clients
for idx, rs_client in enumerate(rs_clients):
- route = '10.0.{0}.0/24'.format(idx+1)
+ route = '10.0.{0}.0/24'.format(idx + 1)
rs_client.add_route(route)
if idx < 2:
route = '10.0.10.0/24'
@@ -68,8 +73,7 @@ class GoBGPTestBase(unittest.TestCase):
rs_client.add_peer(g1, as2=as2)
cls.gobgp = g1
- cls.quaggas = { x.name: x for x in rs_clients }
-
+ cls.quaggas = {x.name: x for x in rs_clients}
# test each neighbor state is turned establish
def test_01_neighbor_established(self):
@@ -87,7 +91,7 @@ class GoBGPTestBase(unittest.TestCase):
self.assertEqual(state, BGP_FSM_ESTABLISHED)
local_rib = self.gobgp.get_local_rib(rs_client)
local_rib = [p['prefix'] for p in local_rib]
- if len(local_rib) < len(self.quaggas)-1:
+ if len(local_rib) < (len(self.quaggas) - 1):
time.sleep(self.wait_per_retry)
continue
@@ -97,7 +101,7 @@ class GoBGPTestBase(unittest.TestCase):
if done:
continue
# should not reach here
- self.assertTrue(False)
+ raise AssertionError
def test_03_stop_q2_and_check_neighbor_status(self):
q2 = self.quaggas['q2']
diff --git a/test/scenario_test/route_server_ipv4_v6_test.py b/test/scenario_test/route_server_ipv4_v6_test.py
index 9b228875..8fdd05b8 100644
--- a/test/scenario_test/route_server_ipv4_v6_test.py
+++ b/test/scenario_test/route_server_ipv4_v6_test.py
@@ -13,17 +13,22 @@
# 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 *
+from __future__ import absolute_import
+
import sys
-import os
import time
+import unittest
+
+from fabric.api import local
import nose
+
from noseplugin import OptionParser, parser_option
+from lib import base
+from lib.base import BGP_FSM_ESTABLISHED
+from lib.gobgp import GoBGPContainer
+from lib.quagga import QuaggaBGPContainer
+
class GoBGPIPv6Test(unittest.TestCase):
@@ -48,11 +53,11 @@ class GoBGPIPv6Test(unittest.TestCase):
v6 = [q3, q4]
for idx, q in enumerate(v4):
- route = '10.0.{0}.0/24'.format(idx+1)
+ route = '10.0.{0}.0/24'.format(idx + 1)
q.add_route(route)
for idx, q in enumerate(v6):
- route = '2001:{0}::/96'.format(idx+1)
+ route = '2001:{0}::/96'.format(idx + 1)
q.add_route(route, rf='ipv6')
initial_wait_time = max(ctn.run() for ctn in ctns)
@@ -83,11 +88,11 @@ class GoBGPIPv6Test(unittest.TestCase):
self.assertEqual(state, BGP_FSM_ESTABLISHED)
local_rib = self.gobgp.get_local_rib(rs_client, rf=rf)
local_rib = [p['prefix'] for p in local_rib]
- if len(local_rib) < len(ctns)-1:
+ if len(local_rib) < (len(ctns) - 1):
time.sleep(self.wait_per_retry)
continue
- self.assertTrue(len(local_rib) == (len(ctns)-1))
+ self.assertTrue(len(local_rib) == (len(ctns) - 1))
for c in ctns.itervalues():
if rs_client != c:
@@ -98,7 +103,7 @@ class GoBGPIPv6Test(unittest.TestCase):
if done:
continue
# should not reach here
- self.assertTrue(False)
+ raise AssertionError
def check_rs_client_rib(self, ctns, rf):
for rs_client in ctns.itervalues():
@@ -122,7 +127,7 @@ class GoBGPIPv6Test(unittest.TestCase):
if done:
continue
# should not reach here
- self.assertTrue(False)
+ raise AssertionError
# test each neighbor state is turned establish
def test_01_neighbor_established(self):
@@ -155,12 +160,12 @@ class GoBGPIPv6Test(unittest.TestCase):
def test_08_check_rib(self):
for q in self.ipv4s.itervalues():
- self.assertTrue(all( p['filtered'] for p in self.gobgp.get_adj_rib_in(q)))
+ self.assertTrue(all(p['filtered'] for p in self.gobgp.get_adj_rib_in(q)))
self.assertTrue(len(self.gobgp.get_adj_rib_out(q)) == 0)
self.assertTrue(len(q.get_global_rib()) == len(q.routes))
for q in self.ipv6s.itervalues():
- self.assertTrue(all( p['filtered'] for p in self.gobgp.get_adj_rib_in(q, rf='ipv6')))
+ self.assertTrue(all(p['filtered'] for p in self.gobgp.get_adj_rib_in(q, rf='ipv6')))
self.assertTrue(len(self.gobgp.get_adj_rib_out(q, rf='ipv6')) == 0)
self.assertTrue(len(q.get_global_rib(rf='ipv6')) == len(q.routes))
diff --git a/test/scenario_test/route_server_malformed_test.py b/test/scenario_test/route_server_malformed_test.py
index 653d42f1..d56b5e2e 100644
--- a/test/scenario_test/route_server_malformed_test.py
+++ b/test/scenario_test/route_server_malformed_test.py
@@ -13,20 +13,23 @@
# 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 *
-from lib.exabgp import *
+from __future__ import absolute_import
+
import sys
-import os
import time
-import nose
+import unittest
import inspect
-from nose.tools import *
+
+from fabric.api import local
+import nose
+
from noseplugin import OptionParser, parser_option
+from lib import base
+from lib.base import BGP_FSM_ESTABLISHED
+from lib.gobgp import GoBGPContainer
+from lib.exabgp import ExaBGPContainer
+
counter = 1
_SCENARIOS = {}
@@ -102,11 +105,13 @@ class MalformedMpReachNlri(object):
g1 = env.g1
e1 = env.e1
e2 = env.e2
+
def f():
for line in e1.log().split('\n'):
if 'UPDATE message error / Attribute Flags Error / 0x600E0411223344' in line:
return True
return False
+
wait_for(f)
# check e2 is still established
g1.wait_for(BGP_FSM_ESTABLISHED, e2)
@@ -144,11 +149,13 @@ class MalformedMpUnReachNlri(object):
g1 = env.g1
e1 = env.e1
e2 = env.e2
+
def f():
for line in e1.log().split('\n'):
if 'UPDATE message error / Attribute Flags Error / 0x600F0411223344' in line:
return True
return False
+
wait_for(f)
# check e2 is still established
g1.wait_for(BGP_FSM_ESTABLISHED, e2)
@@ -193,11 +200,13 @@ class MalformedAsPath(object):
g1 = env.g1
e1 = env.e1
e2 = env.e2
+
def f():
for line in e1.log().split('\n'):
if 'UPDATE message error / Attribute Flags Error / 0x60020411223344' in line:
return True
return False
+
wait_for(f)
# check e2 is still established
g1.wait_for(BGP_FSM_ESTABLISHED, e2)
@@ -235,11 +244,13 @@ class MalformedAs4Path(object):
g1 = env.g1
e1 = env.e1
e2 = env.e2
+
def f():
for line in e1.log().split('\n'):
if 'UPDATE message error / Attribute Flags Error / 0x60110411223344' in line:
return True
return False
+
wait_for(f)
# check e2 is still established
g1.wait_for(BGP_FSM_ESTABLISHED, e2)
@@ -284,11 +295,13 @@ class MalformedNexthop(object):
g1 = env.g1
e1 = env.e1
e2 = env.e2
+
def f():
for line in e1.log().split('\n'):
if 'UPDATE message error / Attribute Flags Error / 0x600E08010110FFFFFF0000' in line:
return True
return False
+
wait_for(f)
# check e2 is still established
g1.wait_for(BGP_FSM_ESTABLISHED, e2)
@@ -333,11 +346,13 @@ class MalformedRouteFamily(object):
g1 = env.g1
e1 = env.e1
e2 = env.e2
+
def f():
for line in e1.log().split('\n'):
if 'UPDATE message error / Attribute Flags Error / 0x600E150002011020010DB800000000000000000000000100' in line:
return True
return False
+
wait_for(f)
# check e2 is still established
g1.wait_for(BGP_FSM_ESTABLISHED, e2)
@@ -382,11 +397,13 @@ class MalformedAsPathSegmentLengthInvalid(object):
g1 = env.g1
e1 = env.e1
e2 = env.e2
+
def f():
for line in e1.log().split('\n'):
if 'UPDATE message error / Malformed AS_PATH / 0x4002040202FFDC' in line:
return True
return False
+
wait_for(f)
# check e2 is still established
g1.wait_for(BGP_FSM_ESTABLISHED, e2)
@@ -426,11 +443,13 @@ class MalformedNexthopLoopbackAddr(object):
g1 = env.g1
e1 = env.e1
e2 = env.e2
+
def f():
for line in e1.log().split('\n'):
if 'UPDATE message error / Invalid NEXT_HOP Attribute / 0x4003047F000001' in line:
return True
return False
+
wait_for(f)
# check e2 is still established
g1.wait_for(BGP_FSM_ESTABLISHED, e2)
@@ -473,11 +492,13 @@ class MalformedOriginType(object):
g1 = env.g1
e1 = env.e1
e2 = env.e2
+
def f():
for line in e1.log().split('\n'):
if 'UPDATE message error / Invalid ORIGIN Attribute / 0x40010104' in line:
return True
return False
+
wait_for(f)
# check e2 is still established
g1.wait_for(BGP_FSM_ESTABLISHED, e2)
@@ -489,7 +510,7 @@ class MalformedOriginType(object):
lookup_scenario("MalformedOriginType").check(env)
-class TestGoBGPBase():
+class TestGoBGPBase(unittest.TestCase):
wait_per_retry = 5
retry_limit = 10
@@ -520,7 +541,7 @@ class TestGoBGPBase():
for e in self.executors:
yield e
-
+
if __name__ == '__main__':
output = local("which docker 2>&1 > /dev/null ; echo $?", capture=True)
if int(output) is not 0:
diff --git a/test/scenario_test/route_server_policy_grpc_test.py b/test/scenario_test/route_server_policy_grpc_test.py
index e858558a..582b533e 100644
--- a/test/scenario_test/route_server_policy_grpc_test.py
+++ b/test/scenario_test/route_server_policy_grpc_test.py
@@ -13,20 +13,33 @@
# 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 *
-from lib.exabgp import *
+from __future__ import absolute_import
+
import sys
-import os
import time
-import nose
+import unittest
import inspect
-from nose.tools import *
+
+from fabric.api import local
+import nose
+from nose.tools import (
+ assert_true,
+ assert_false,
+)
+
from noseplugin import OptionParser, parser_option
+from lib import base
+from lib.base import (
+ Bridge,
+ BGP_FSM_ESTABLISHED,
+ BGP_ATTR_TYPE_COMMUNITIES,
+ BGP_ATTR_TYPE_EXTENDED_COMMUNITIES,
+)
+from lib.gobgp import GoBGPContainer
+from lib.quagga import QuaggaBGPContainer
+from lib.exabgp import ExaBGPContainer
+
counter = 1
_SCENARIOS = {}
@@ -247,7 +260,7 @@ class ImportPolicyUpdate(object):
@staticmethod
def check(env):
g1 = env.g1
- e1 = env.e1
+ # e1 = env.e1
q1 = env.q1
q2 = env.q2
wait_for(lambda: len(g1.get_local_rib(q1)) == 3)
@@ -261,8 +274,8 @@ class ImportPolicyUpdate(object):
def setup2(env):
g1 = env.g1
e1 = env.e1
- q1 = env.q1
- q2 = env.q2
+ # q1 = env.q1
+ # q2 = env.q2
g1.local('gobgp policy prefix del ps0 192.168.200.0/24')
g1.softreset(e1)
@@ -270,7 +283,7 @@ class ImportPolicyUpdate(object):
@staticmethod
def check2(env):
g1 = env.g1
- e1 = env.e1
+ # e1 = env.e1
q1 = env.q1
q2 = env.q2
wait_for(lambda: len(g1.get_local_rib(q1)) == 3)
@@ -347,7 +360,7 @@ class ExportPolicyUpdate(object):
@staticmethod
def check(env):
g1 = env.g1
- e1 = env.e1
+ # e1 = env.e1
q1 = env.q1
q2 = env.q2
wait_for(lambda: len(g1.get_local_rib(q1)) == 3)
@@ -374,7 +387,7 @@ class ExportPolicyUpdate(object):
@staticmethod
def check2(env):
g1 = env.g1
- e1 = env.e1
+ # e1 = env.e1
q1 = env.q1
q2 = env.q2
wait_for(lambda: len(g1.get_local_rib(q1)) == 3)
@@ -392,6 +405,7 @@ class ExportPolicyUpdate(object):
lookup_scenario("ExportPolicyUpdate").setup2(env)
lookup_scenario("ExportPolicyUpdate").check2(env)
+
@register_scenario
class ExportPolicyUpdateRouteRefresh(object):
"""
@@ -457,6 +471,7 @@ class ExportPolicyUpdateRouteRefresh(object):
lookup_scenario("ExportPolicyUpdateRouteRefresh").setup2(env)
lookup_scenario("ExportPolicyUpdateRouteRefresh").check2(env)
+
@register_scenario
class ImportPolicyIPV6(object):
"""
@@ -661,8 +676,8 @@ class ImportPolicyIPV6Update(object):
def setup2(env):
g1 = env.g1
e1 = env.e1
- q1 = env.q1
- q2 = env.q2
+ # q1 = env.q1
+ # q2 = env.q2
g1.local('gobgp policy prefix del ps0 2001:0:10:20::/64')
g1.softreset(e1, rf='ipv6')
@@ -807,9 +822,9 @@ class ImportPolicyAsPathLengthCondition(object):
g1.local('gobgp neighbor {0} policy import add policy0'.format(g1.peers[q2]['neigh_addr'].split('/')[0]))
# this will be blocked
- e1.add_route('192.168.100.0/24', aspath=range(e1.asn, e1.asn-10, -1))
+ e1.add_route('192.168.100.0/24', aspath=range(e1.asn, e1.asn - 10, -1))
# this will pass
- e1.add_route('192.168.200.0/24', aspath=range(e1.asn, e1.asn-8, -1))
+ e1.add_route('192.168.200.0/24', aspath=range(e1.asn, e1.asn - 8, -1))
for c in [e1, q1, q2]:
g1.wait_for(BGP_FSM_ESTABLISHED, c)
@@ -817,7 +832,7 @@ class ImportPolicyAsPathLengthCondition(object):
@staticmethod
def check(env):
g1 = env.g1
- e1 = env.e1
+ # e1 = env.e1
q1 = env.q1
q2 = env.q2
wait_for(lambda: len(g1.get_local_rib(q1)) == 2)
@@ -863,9 +878,9 @@ class ImportPolicyAsPathCondition(object):
g1.local('gobgp neighbor {0} policy import add policy0'.format(g1.peers[q2]['neigh_addr'].split('/')[0]))
# this will be blocked
- e1.add_route('192.168.100.0/24', aspath=range(e1.asn, e1.asn-10, -1))
+ e1.add_route('192.168.100.0/24', aspath=range(e1.asn, e1.asn - 10, -1))
# this will pass
- e1.add_route('192.168.200.0/24', aspath=range(e1.asn-1, e1.asn-10, -1))
+ e1.add_route('192.168.200.0/24', aspath=range(e1.asn - 1, e1.asn - 10, -1))
for c in [e1, q1, q2]:
g1.wait_for(BGP_FSM_ESTABLISHED, c)
@@ -1066,7 +1081,7 @@ class ImportPolicyAsPathMismatchCondition(object):
@staticmethod
def check(env):
g1 = env.g1
- e1 = env.e1
+ # e1 = env.e1
q1 = env.q1
q2 = env.q2
wait_for(lambda: len(g1.get_local_rib(q1)) == 2)
@@ -1119,8 +1134,6 @@ class ImportPolicyCommunityCondition(object):
for c in [e1, q1, q2]:
g1.wait_for(BGP_FSM_ESTABLISHED, c)
-
-
@staticmethod
def check(env):
lookup_scenario("ImportPolicy").check(env)
@@ -1224,7 +1237,7 @@ class ImportPolicyCommunityAction(object):
@staticmethod
def check(env):
g1 = env.g1
- e1 = env.e1
+ # e1 = env.e1
q1 = env.q1
q2 = env.q2
wait_for(lambda: len(g1.get_local_rib(q1)) == 1)
@@ -1269,7 +1282,6 @@ class ImportPolicyCommunityReplace(object):
def boot(env):
lookup_scenario("ImportPolicy").boot(env)
-
@staticmethod
def setup(env):
g1 = env.g1
@@ -1290,7 +1302,6 @@ class ImportPolicyCommunityReplace(object):
for c in [e1, q1, q2]:
g1.wait_for(BGP_FSM_ESTABLISHED, c)
-
@staticmethod
def check(env):
lookup_scenario('ImportPolicyCommunityAction').check(env)
@@ -1298,7 +1309,7 @@ class ImportPolicyCommunityReplace(object):
@staticmethod
def check2(env):
g1 = env.g1
- e1 = env.e1
+ # e1 = env.e1
q1 = env.q1
q2 = env.q2
path = g1.get_adj_rib_out(q1)[0]
@@ -1356,7 +1367,7 @@ class ImportPolicyCommunityRemove(object):
@staticmethod
def check(env):
g1 = env.g1
- e1 = env.e1
+ # e1 = env.e1
q1 = env.q1
q2 = env.q2
wait_for(lambda: len(g1.get_local_rib(q1)) == 3)
@@ -1369,7 +1380,7 @@ class ImportPolicyCommunityRemove(object):
@staticmethod
def check2(env):
g1 = env.g1
- e1 = env.e1
+ # e1 = env.e1
q1 = env.q1
q2 = env.q2
adj_out = g1.get_adj_rib_out(q1)
@@ -2277,8 +2288,8 @@ class InPolicyUpdate(object):
def setup2(env):
g1 = env.g1
e1 = env.e1
- q1 = env.q1
- q2 = env.q2
+ # q1 = env.q1
+ # q2 = env.q2
g1.clear_policy()
g1.local('gobgp policy prefix del ps0 192.168.200.0/24')
@@ -2373,7 +2384,7 @@ class ExportPolicyAsPathPrepend(object):
assert_true(path['aspath'] == [e1.asn])
path = g1.get_adj_rib_out(q2, prefix='192.168.20.0/24')[0]
- assert_true(path['aspath'] == [65005]*5 + [e1.asn])
+ assert_true(path['aspath'] == ([65005] * 5) + [e1.asn])
path = g1.get_adj_rib_out(q2, prefix='192.168.200.0/24')[0]
assert_true(path['aspath'] == [e1.asn])
@@ -2439,10 +2450,10 @@ class ImportPolicyAsPathPrependLastAS(object):
assert_true(path['aspath'] == [e1.asn])
path = g1.get_local_rib(q2, prefix='192.168.20.0/24')[0]['paths'][0]
- assert_true(path['aspath'] == [e1.asn]*5 + [e1.asn])
+ assert_true(path['aspath'] == ([e1.asn] * 5) + [e1.asn])
path = g1.get_adj_rib_out(q2, prefix='192.168.20.0/24')[0]
- assert_true(path['aspath'] == [e1.asn]*5 + [e1.asn])
+ assert_true(path['aspath'] == ([e1.asn] * 5) + [e1.asn])
path = g1.get_adj_rib_out(q2, prefix='192.168.200.0/24')[0]
assert_true(path['aspath'] == [e1.asn])
@@ -2511,7 +2522,7 @@ class ExportPolicyAsPathPrependLastAS(object):
assert_true(path['aspath'] == [e1.asn])
path = g1.get_adj_rib_out(q2, prefix='192.168.20.0/24')[0]
- assert_true(path['aspath'] == [e1.asn]*5 + [e1.asn])
+ assert_true(path['aspath'] == ([e1.asn] * 5) + [e1.asn])
path = g1.get_adj_rib_out(q2, prefix='192.168.200.0/24')[0]
assert_true(path['aspath'] == [e1.asn])
@@ -2710,7 +2721,7 @@ class ImportPolicyExCommunityAdd(object):
@staticmethod
def check2(env):
g1 = env.g1
- e1 = env.e1
+ # e1 = env.e1
q1 = env.q1
q2 = env.q2
path = g1.get_adj_rib_out(q1)[0]
@@ -2725,6 +2736,7 @@ class ImportPolicyExCommunityAdd(object):
lookup_scenario("ImportPolicyExCommunityAdd").check(env)
lookup_scenario("ImportPolicyExCommunityAdd").check2(env)
+
@register_scenario
class ImportPolicyExCommunityAdd2(object):
"""
@@ -2766,7 +2778,7 @@ class ImportPolicyExCommunityAdd2(object):
@staticmethod
def check2(env):
g1 = env.g1
- e1 = env.e1
+ # e1 = env.e1
q1 = env.q1
q2 = env.q2
path = g1.get_adj_rib_out(q1)[0]
@@ -2828,7 +2840,7 @@ class ImportPolicyExCommunityMultipleAdd(object):
@staticmethod
def check2(env):
g1 = env.g1
- e1 = env.e1
+ # e1 = env.e1
q1 = env.q1
q2 = env.q2
path = g1.get_adj_rib_out(q1)[0]
@@ -2890,7 +2902,7 @@ class ExportPolicyExCommunityAdd(object):
@staticmethod
def check2(env):
g1 = env.g1
- e1 = env.e1
+ # e1 = env.e1
q1 = env.q1
q2 = env.q2
path = g1.get_adj_rib_out(q1)[0]
@@ -2908,7 +2920,7 @@ class ExportPolicyExCommunityAdd(object):
lookup_scenario("ExportPolicyExCommunityAdd").check2(env)
-class TestGoBGPBase():
+class TestGoBGPBase(unittest.TestCase):
wait_per_retry = 5
retry_limit = 10
diff --git a/test/scenario_test/route_server_policy_test.py b/test/scenario_test/route_server_policy_test.py
index 34cfde0e..d1968fcd 100644
--- a/test/scenario_test/route_server_policy_test.py
+++ b/test/scenario_test/route_server_policy_test.py
@@ -13,20 +13,33 @@
# 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 *
-from lib.exabgp import *
+from __future__ import absolute_import
+
import sys
-import os
import time
-import nose
+import unittest
import inspect
-from nose.tools import *
+
+from fabric.api import local
+import nose
+from nose.tools import (
+ assert_true,
+ assert_false,
+)
+
from noseplugin import OptionParser, parser_option
+from lib import base
+from lib.base import (
+ Bridge,
+ BGP_FSM_ESTABLISHED,
+ BGP_ATTR_TYPE_COMMUNITIES,
+ BGP_ATTR_TYPE_EXTENDED_COMMUNITIES,
+)
+from lib.gobgp import GoBGPContainer
+from lib.quagga import QuaggaBGPContainer
+from lib.exabgp import ExaBGPContainer
+
counter = 1
_SCENARIOS = {}
@@ -112,8 +125,8 @@ class ImportPolicy(object):
st0 = {'name': 'st0',
'conditions': {
- 'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
- 'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
+ 'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
+ 'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
'actions': {'route-disposition': 'reject-route'}}
policy = {'name': 'policy0',
@@ -178,8 +191,8 @@ class ExportPolicy(object):
st0 = {'name': 'st0',
'conditions': {
- 'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
- 'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
+ 'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
+ 'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
'actions': {'route-disposition': 'reject-route'}}
policy = {'name': 'policy0',
@@ -264,8 +277,8 @@ class ImportPolicyUpdate(object):
st0 = {'name': 'st0',
'conditions': {
- 'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
- 'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
+ 'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
+ 'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
'actions': {'route-disposition': 'reject-route'}}
policy = {'name': 'policy0',
@@ -282,7 +295,7 @@ class ImportPolicyUpdate(object):
@staticmethod
def check(env):
g1 = env.g1
- e1 = env.e1
+ # e1 = env.e1
q1 = env.q1
q2 = env.q2
wait_for(lambda: len(g1.get_local_rib(q1)) == 3)
@@ -296,7 +309,7 @@ class ImportPolicyUpdate(object):
def setup2(env):
g1 = env.g1
e1 = env.e1
- q1 = env.q1
+ # q1 = env.q1
q2 = env.q2
g1.clear_policy()
@@ -311,8 +324,9 @@ class ImportPolicyUpdate(object):
g1.set_neighbor_set(ns0)
st0 = {'name': 'st0',
- 'conditions': {'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
- 'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
+ 'conditions': {
+ 'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
+ 'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
'actions': {'route-disposition': 'reject-route'}}
policy = {'name': 'policy0',
@@ -323,7 +337,7 @@ class ImportPolicyUpdate(object):
@staticmethod
def check2(env):
g1 = env.g1
- e1 = env.e1
+ # e1 = env.e1
q1 = env.q1
q2 = env.q2
wait_for(lambda: len(g1.get_local_rib(q1)) == 3)
@@ -391,8 +405,9 @@ class ExportPolicyUpdate(object):
g1.set_neighbor_set(ns0)
st0 = {'name': 'st0',
- 'conditions': {'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
- 'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
+ 'conditions': {
+ 'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
+ 'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
'actions': {'route-disposition': 'reject-route'}}
policy = {'name': 'policy0',
@@ -409,7 +424,7 @@ class ExportPolicyUpdate(object):
@staticmethod
def check(env):
g1 = env.g1
- e1 = env.e1
+ # e1 = env.e1
q1 = env.q1
q2 = env.q2
wait_for(lambda: len(g1.get_local_rib(q1)) == 3)
@@ -438,8 +453,9 @@ class ExportPolicyUpdate(object):
g1.set_neighbor_set(ns0)
st0 = {'name': 'st0',
- 'conditions': {'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
- 'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
+ 'conditions': {
+ 'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
+ 'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
'actions': {'route-disposition': 'reject-route'}}
policy = {'name': 'policy0',
@@ -455,7 +471,7 @@ class ExportPolicyUpdate(object):
@staticmethod
def check2(env):
g1 = env.g1
- e1 = env.e1
+ # e1 = env.e1
q1 = env.q1
q2 = env.q2
wait_for(lambda: len(g1.get_local_rib(q1)) == 3)
@@ -534,8 +550,8 @@ class ImportPolicyIPV6(object):
st0 = {'name': 'st0',
'conditions': {
- 'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
- 'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
+ 'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
+ 'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
'actions': {'route-disposition': 'reject-route'}}
policy = {'name': 'policy0',
@@ -603,8 +619,8 @@ class ExportPolicyIPV6(object):
st0 = {'name': 'st0',
'conditions': {
- 'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
- 'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
+ 'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
+ 'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
'actions': {'route-disposition': 'reject-route'}}
policy = {'name': 'policy0',
@@ -685,8 +701,8 @@ class ImportPolicyIPV6Update(object):
st0 = {'name': 'st0',
'conditions': {
- 'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
- 'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
+ 'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
+ 'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
'actions': {'route-disposition': 'reject-route'}}
policy = {'name': 'policy0',
@@ -713,7 +729,7 @@ class ImportPolicyIPV6Update(object):
def setup2(env):
g1 = env.g1
e1 = env.e1
- q1 = env.q1
+ # q1 = env.q1
q2 = env.q2
p0 = {'ip-prefix': '2001:0:10:2::/64'}
@@ -728,8 +744,8 @@ class ImportPolicyIPV6Update(object):
st0 = {'name': 'st0',
'conditions': {
- 'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
- 'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
+ 'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
+ 'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
'actions': {
'route-disposition': 'reject-route'}}
@@ -806,8 +822,8 @@ class ExportPolicyIPv6Update(object):
st0 = {'name': 'st0',
'conditions': {
- 'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
- 'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
+ 'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
+ 'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
'actions': {'route-disposition': 'reject-route'}}
policy = {'name': 'policy0',
@@ -849,8 +865,8 @@ class ExportPolicyIPv6Update(object):
st0 = {'name': 'st0',
'conditions': {
- 'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
- 'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
+ 'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
+ 'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
'actions': {'route-disposition': 'reject-route'}}
policy = {'name': 'policy0',
@@ -909,9 +925,9 @@ class ImportPolicyAsPathLengthCondition(object):
g1.add_policy(policy, q2, 'import')
# this will be blocked
- e1.add_route('192.168.100.0/24', aspath=range(e1.asn, e1.asn-10, -1))
+ e1.add_route('192.168.100.0/24', aspath=range(e1.asn, e1.asn - 10, -1))
# this will pass
- e1.add_route('192.168.200.0/24', aspath=range(e1.asn, e1.asn-8, -1))
+ e1.add_route('192.168.200.0/24', aspath=range(e1.asn, e1.asn - 8, -1))
for c in [e1, q1, q2]:
g1.wait_for(BGP_FSM_ESTABLISHED, c)
@@ -919,7 +935,7 @@ class ImportPolicyAsPathLengthCondition(object):
@staticmethod
def check(env):
g1 = env.g1
- e1 = env.e1
+ # e1 = env.e1
q1 = env.q1
q2 = env.q2
wait_for(lambda: len(g1.get_local_rib(q1)) == 2)
@@ -969,9 +985,9 @@ class ImportPolicyAsPathCondition(object):
g1.add_policy(policy, q2, 'import')
# this will be blocked
- e1.add_route('192.168.100.0/24', aspath=range(e1.asn, e1.asn-10, -1))
+ e1.add_route('192.168.100.0/24', aspath=range(e1.asn, e1.asn - 10, -1))
# this will pass
- e1.add_route('192.168.200.0/24', aspath=range(e1.asn-1, e1.asn-10, -1))
+ e1.add_route('192.168.200.0/24', aspath=range(e1.asn - 1, e1.asn - 10, -1))
for c in [e1, q1, q2]:
g1.wait_for(BGP_FSM_ESTABLISHED, c)
@@ -1189,7 +1205,7 @@ class ImportPolicyAsPathMismatchCondition(object):
@staticmethod
def check(env):
g1 = env.g1
- e1 = env.e1
+ # e1 = env.e1
q1 = env.q1
q2 = env.q2
wait_for(lambda: len(g1.get_local_rib(q1)) == 2)
@@ -1246,8 +1262,6 @@ class ImportPolicyCommunityCondition(object):
for c in [e1, q1, q2]:
g1.wait_for(BGP_FSM_ESTABLISHED, c)
-
-
@staticmethod
def check(env):
lookup_scenario("ImportPolicy").check(env)
@@ -1345,10 +1359,12 @@ class ImportPolicyCommunityAction(object):
g1.set_bgp_defined_set(cs0)
st0 = {'name': 'st0',
- 'conditions': {'bgp-conditions': {'match-community-set': {'community-set': 'cs0', 'match-set-options': 'any'}}},
+ 'conditions': {'bgp-conditions': {'match-community-set': {'community-set': 'cs0', 'match-set-options': 'any'}}},
'actions': {'route-disposition': 'accept-route',
- 'bgp-actions': {'set-community': {'options': 'add',
- 'set-community-method': {'communities-list': ['65100:20']}}}}}
+ 'bgp-actions': {
+ 'set-community': {
+ 'options': 'add',
+ 'set-community-method': {'communities-list': ['65100:20']}}}}}
policy = {'name': 'policy0',
'statements': [st0]}
@@ -1362,7 +1378,7 @@ class ImportPolicyCommunityAction(object):
@staticmethod
def check(env):
g1 = env.g1
- e1 = env.e1
+ # e1 = env.e1
q1 = env.q1
q2 = env.q2
wait_for(lambda: len(g1.get_local_rib(q1)) == 1)
@@ -1407,7 +1423,6 @@ class ImportPolicyCommunityReplace(object):
def boot(env):
lookup_scenario("ImportPolicy").boot(env)
-
@staticmethod
def setup(env):
g1 = env.g1
@@ -1419,10 +1434,12 @@ class ImportPolicyCommunityReplace(object):
g1.set_bgp_defined_set(cs0)
st0 = {'name': 'st0',
- 'conditions':{'bgp-conditions':{'match-community-set':{'community-set': 'cs0'}}},
+ 'conditions': {'bgp-conditions': {'match-community-set': {'community-set': 'cs0'}}},
'actions': {'route-disposition': 'accept-route',
- 'bgp-actions': {'set-community': {'options': 'REPLACE',
- 'set-community-method': {'communities-list': ['65100:20']}}}}}
+ 'bgp-actions': {
+ 'set-community': {
+ 'options': 'REPLACE',
+ 'set-community-method': {'communities-list': ['65100:20']}}}}}
policy = {'name': 'policy0',
'statements': [st0]}
@@ -1433,7 +1450,6 @@ class ImportPolicyCommunityReplace(object):
for c in [e1, q1, q2]:
g1.wait_for(BGP_FSM_ESTABLISHED, c)
-
@staticmethod
def check(env):
lookup_scenario('ImportPolicyCommunityAction').check(env)
@@ -1441,7 +1457,7 @@ class ImportPolicyCommunityReplace(object):
@staticmethod
def check2(env):
g1 = env.g1
- e1 = env.e1
+ # e1 = env.e1
q1 = env.q1
q2 = env.q2
path = g1.get_adj_rib_out(q1)[0]
@@ -1485,10 +1501,12 @@ class ImportPolicyCommunityRemove(object):
g1.set_bgp_defined_set(cs0)
st0 = {'name': 'st0',
- 'conditions':{'bgp-conditions':{'match-community-set':{'community-set': 'cs0'}}},
+ 'conditions': {'bgp-conditions': {'match-community-set': {'community-set': 'cs0'}}},
'actions': {'route-disposition': 'accept-route',
- 'bgp-actions': {'set-community': {'options': 'REMOVE',
- 'set-community-method': {'communities-list': ['65100:10', '65100:20']}}}}}
+ 'bgp-actions': {
+ 'set-community': {
+ 'options': 'REMOVE',
+ 'set-community-method': {'communities-list': ['65100:10', '65100:20']}}}}}
policy = {'name': 'policy0',
'statements': [st0]}
@@ -1504,7 +1522,7 @@ class ImportPolicyCommunityRemove(object):
@staticmethod
def check(env):
g1 = env.g1
- e1 = env.e1
+ # e1 = env.e1
q1 = env.q1
q2 = env.q2
wait_for(lambda: len(g1.get_local_rib(q1)) == 3)
@@ -1517,7 +1535,7 @@ class ImportPolicyCommunityRemove(object):
@staticmethod
def check2(env):
g1 = env.g1
- e1 = env.e1
+ # e1 = env.e1
q1 = env.q1
q2 = env.q2
adj_out = g1.get_adj_rib_out(q1)
@@ -1569,10 +1587,12 @@ class ImportPolicyCommunityNull(object):
g1.set_bgp_defined_set(cs0)
st0 = {'name': 'st0',
- 'conditions':{'bgp-conditions':{'match-community-set':{'community-set': 'cs0'}}},
+ 'conditions': {'bgp-conditions': {'match-community-set': {'community-set': 'cs0'}}},
'actions': {'route-disposition': 'accept-route',
- 'bgp-actions': {'set-community': {'options': 'REPLACE',
- 'set-community-method': {'communities-list': []}}}}}
+ 'bgp-actions': {
+ 'set-community': {
+ 'options': 'REPLACE',
+ 'set-community-method': {'communities-list': []}}}}}
policy = {'name': 'policy0',
'statements': [st0]}
@@ -1643,10 +1663,12 @@ class ExportPolicyCommunityAdd(object):
g1.set_bgp_defined_set(cs0)
st0 = {'name': 'st0',
- 'conditions':{'bgp-conditions':{'match-community-set':{'community-set': 'cs0'}}},
+ 'conditions': {'bgp-conditions': {'match-community-set': {'community-set': 'cs0'}}},
'actions': {'route-disposition': 'accept-route',
- 'bgp-actions': {'set-community': {'options': 'add',
- 'set-community-method': {'communities-list': ['65100:20']}}}}}
+ 'bgp-actions': {
+ 'set-community': {
+ 'options': 'add',
+ 'set-community-method': {'communities-list': ['65100:20']}}}}}
policy = {'name': 'policy0',
'statements': [st0]}
@@ -1716,10 +1738,12 @@ class ExportPolicyCommunityReplace(object):
g1.set_bgp_defined_set(cs0)
st0 = {'name': 'st0',
- 'conditions':{'bgp-conditions':{'match-community-set':{'community-set': 'cs0'}}},
+ 'conditions': {'bgp-conditions': {'match-community-set': {'community-set': 'cs0'}}},
'actions': {'route-disposition': 'accept-route',
- 'bgp-actions': {'set-community': {'options': 'REPLACE',
- 'set-community-method': {'communities-list': ['65100:20']}}}}}
+ 'bgp-actions': {
+ 'set-community': {
+ 'options': 'REPLACE',
+ 'set-community-method': {'communities-list': ['65100:20']}}}}}
policy = {'name': 'policy0',
'statements': [st0]}
@@ -1789,10 +1813,12 @@ class ExportPolicyCommunityRemove(object):
g1.set_bgp_defined_set(cs0)
st0 = {'name': 'st0',
- 'conditions':{'bgp-conditions':{'match-community-set':{'community-set': 'cs0'}}},
+ 'conditions': {'bgp-conditions': {'match-community-set': {'community-set': 'cs0'}}},
'actions': {'route-disposition': 'accept-route',
- 'bgp-actions': {'set-community': {'options': 'REMOVE',
- 'set-community-method': {'communities-list': ['65100:20', '65100:30']}}}}}
+ 'bgp-actions': {
+ 'set-community': {
+ 'options': 'REMOVE',
+ 'set-community-method': {'communities-list': ['65100:20', '65100:30']}}}}}
policy = {'name': 'policy0',
'statements': [st0]}
@@ -1860,15 +1886,17 @@ class ExportPolicyCommunityNull(object):
e1 = env.e1
q1 = env.q1
q2 = env.q2
- cs0 = {'community-sets': [{'community-set-name': 'cs0', 'community-list': ['65100:10']}]}
+ cs0 = {'community-sets': [{'community-set-name': 'cs0', 'community-list': ['65100:10']}]}
g1.set_bgp_defined_set(cs0)
st0 = {'name': 'st0',
- 'conditions':{'bgp-conditions':{'match-community-set':{'community-set': 'cs0'}}},
+ 'conditions': {'bgp-conditions': {'match-community-set': {'community-set': 'cs0'}}},
'actions': {'route-disposition': 'accept-route',
- 'bgp-actions': {'set-community': {'options': 'REPLACE',
- 'set-community-method': {'communities-list': []}}}}}
+ 'bgp-actions': {
+ 'set-community': {
+ 'options': 'REPLACE',
+ 'set-community-method': {'communities-list': []}}}}}
policy = {'name': 'policy0',
'statements': [st0]}
@@ -2313,7 +2341,7 @@ class InPolicyReject(object):
g1.set_bgp_defined_set(cs0)
st0 = {'name': 'st0',
- 'conditions':{'bgp-conditions':{'match-community-set':{'community-set': 'cs0'}}},
+ 'conditions': {'bgp-conditions': {'match-community-set': {'community-set': 'cs0'}}},
'actions': {'route-disposition': 'reject-route'}}
policy = {'name': 'policy0',
@@ -2372,8 +2400,8 @@ class InPolicyAccept(object):
g1.set_bgp_defined_set(cs0)
st0 = {'name': 'st0',
- 'conditions':{'bgp-conditions':{'match-community-set':{'community-set': 'cs0'}}},
- 'actions':{'route-disposition': 'accept-route'}}
+ 'conditions': {'bgp-conditions': {'match-community-set': {'community-set': 'cs0'}}},
+ 'actions': {'route-disposition': 'accept-route'}}
policy = {'name': 'policy0',
'statements': [st0]}
@@ -2446,8 +2474,8 @@ class InPolicyUpdate(object):
st0 = {'name': 'st0',
'conditions': {
- 'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
- 'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
+ 'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
+ 'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
'actions': {'route-disposition': 'reject-route'}}
policy = {'name': 'policy0',
@@ -2479,8 +2507,8 @@ class InPolicyUpdate(object):
def setup2(env):
g1 = env.g1
e1 = env.e1
- q1 = env.q1
- q2 = env.q2
+ # q1 = env.q1
+ # q2 = env.q2
g1.clear_policy()
p0 = {'ip-prefix': '192.168.20.0/24'}
@@ -2494,8 +2522,9 @@ class InPolicyUpdate(object):
g1.set_neighbor_set(ns0)
st0 = {'name': 'st0',
- 'conditions': {'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
- 'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
+ 'conditions': {
+ 'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
+ 'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
'actions': {'route-disposition': 'reject-route'}}
policy = {'name': 'policy0',
@@ -2600,7 +2629,7 @@ class ExportPolicyAsPathPrepend(object):
assert_true(path['aspath'] == [e1.asn])
path = g1.get_adj_rib_out(q2, prefix='192.168.20.0/24')[0]
- assert_true(path['aspath'] == [65005]*5 + [e1.asn])
+ assert_true(path['aspath'] == ([65005] * 5) + [e1.asn])
path = g1.get_adj_rib_out(q2, prefix='192.168.200.0/24')[0]
assert_true(path['aspath'] == [e1.asn])
@@ -2674,10 +2703,10 @@ class ImportPolicyAsPathPrependLastAS(object):
assert_true(path['aspath'] == [e1.asn])
path = g1.get_local_rib(q2, prefix='192.168.20.0/24')[0]['paths'][0]
- assert_true(path['aspath'] == [e1.asn]*5 + [e1.asn])
+ assert_true(path['aspath'] == ([e1.asn] * 5) + [e1.asn])
path = g1.get_adj_rib_out(q2, prefix='192.168.20.0/24')[0]
- assert_true(path['aspath'] == [e1.asn]*5 + [e1.asn])
+ assert_true(path['aspath'] == ([e1.asn] * 5) + [e1.asn])
path = g1.get_adj_rib_out(q2, prefix='192.168.200.0/24')[0]
assert_true(path['aspath'] == [e1.asn])
@@ -2754,7 +2783,7 @@ class ExportPolicyAsPathPrependLastAS(object):
assert_true(path['aspath'] == [e1.asn])
path = g1.get_adj_rib_out(q2, prefix='192.168.20.0/24')[0]
- assert_true(path['aspath'] == [e1.asn]*5 + [e1.asn])
+ assert_true(path['aspath'] == ([e1.asn] * 5) + [e1.asn])
path = g1.get_adj_rib_out(q2, prefix='192.168.200.0/24')[0]
assert_true(path['aspath'] == [e1.asn])
@@ -2794,7 +2823,7 @@ class ImportPolicyExCommunityOriginCondition(object):
g1.set_bgp_defined_set(es0)
st0 = {'name': 'st0',
- 'conditions': {'bgp-conditions':{'match-ext-community-set':{'ext-community-set': 'es0'}}},
+ 'conditions': {'bgp-conditions': {'match-ext-community-set': {'ext-community-set': 'es0'}}},
'actions': {'route-disposition': 'reject-route'}}
policy = {'name': 'policy0',
@@ -2845,7 +2874,7 @@ class ImportPolicyExCommunityTargetCondition(object):
g1.set_bgp_defined_set(es0)
st0 = {'name': 'st0',
- 'conditions': {'bgp-conditions':{'match-ext-community-set':{'ext-community-set': 'es0'}}},
+ 'conditions': {'bgp-conditions': {'match-ext-community-set': {'ext-community-set': 'es0'}}},
'actions': {'route-disposition': 'reject-route'}}
policy = {'name': 'policy0',
@@ -2897,8 +2926,7 @@ class InPolicyPrefixCondition(object):
g1.set_prefix_set(ps0)
st0 = {'name': 'st0',
- 'conditions': {
- 'match-prefix-set': {'prefix-set': ps0['prefix-set-name']}},
+ 'conditions': {'match-prefix-set': {'prefix-set': ps0['prefix-set-name']}},
'actions': {'route-disposition': 'reject-route'}}
policy = {'name': 'policy0',
@@ -2968,8 +2996,8 @@ class ImportPolicyExCommunityAdd(object):
'conditions': {
'match-prefix-set': {
'prefix-set': ps0['prefix-set-name']
- }
- },
+ }
+ },
'actions': {
'route-disposition': 'accept-route',
'bgp-actions': {
@@ -2977,11 +3005,11 @@ class ImportPolicyExCommunityAdd(object):
'options': 'add',
'set-ext-community-method': {
'communities-list': ['rt:65000:1'],
- }
- },
- }
+ }
+ },
}
}
+ }
policy = {'name': 'policy0',
'statements': [st0]}
@@ -2999,7 +3027,7 @@ class ImportPolicyExCommunityAdd(object):
@staticmethod
def check2(env):
g1 = env.g1
- e1 = env.e1
+ # e1 = env.e1
q1 = env.q1
q2 = env.q2
path = g1.get_adj_rib_out(q1)[0]
@@ -3048,8 +3076,8 @@ class ImportPolicyExCommunityAdd2(object):
'conditions': {
'match-prefix-set': {
'prefix-set': ps0['prefix-set-name']
- }
- },
+ }
+ },
'actions': {
'route-disposition': 'accept-route',
'bgp-actions': {
@@ -3057,11 +3085,11 @@ class ImportPolicyExCommunityAdd2(object):
'options': 'add',
'set-ext-community-method': {
'communities-list': ['rt:65100:100'],
- }
- },
- }
+ }
+ },
}
}
+ }
policy = {'name': 'policy0',
'statements': [st0]}
@@ -3079,7 +3107,7 @@ class ImportPolicyExCommunityAdd2(object):
@staticmethod
def check2(env):
g1 = env.g1
- e1 = env.e1
+ # e1 = env.e1
q1 = env.q1
q2 = env.q2
path = g1.get_adj_rib_out(q1)[0]
@@ -3133,8 +3161,8 @@ class ImportPolicyExCommunityMultipleAdd(object):
'conditions': {
'match-prefix-set': {
'prefix-set': ps0['prefix-set-name']
- }
- },
+ }
+ },
'actions': {
'route-disposition': 'accept-route',
'bgp-actions': {
@@ -3142,11 +3170,11 @@ class ImportPolicyExCommunityMultipleAdd(object):
'options': 'add',
'set-ext-community-method': {
'communities-list': ['rt:65100:100', 'rt:100:100'],
- }
- },
- }
+ }
+ },
}
}
+ }
policy = {'name': 'policy0',
'statements': [st0]}
@@ -3164,7 +3192,7 @@ class ImportPolicyExCommunityMultipleAdd(object):
@staticmethod
def check2(env):
g1 = env.g1
- e1 = env.e1
+ # e1 = env.e1
q1 = env.q1
q2 = env.q2
path = g1.get_adj_rib_out(q1)[0]
@@ -3218,8 +3246,8 @@ class ExportPolicyExCommunityAdd(object):
'conditions': {
'match-prefix-set': {
'prefix-set': ps0['prefix-set-name']
- }
- },
+ }
+ },
'actions': {
'route-disposition': 'accept-route',
'bgp-actions': {
@@ -3227,11 +3255,11 @@ class ExportPolicyExCommunityAdd(object):
'options': 'add',
'set-ext-community-method': {
'communities-list': ['rt:65000:1'],
- }
- },
- }
+ }
+ },
}
}
+ }
policy = {'name': 'policy0',
'statements': [st0]}
@@ -3249,7 +3277,7 @@ class ExportPolicyExCommunityAdd(object):
@staticmethod
def check2(env):
g1 = env.g1
- e1 = env.e1
+ # e1 = env.e1
q1 = env.q1
q2 = env.q2
path = g1.get_adj_rib_out(q1)[0]
@@ -3316,8 +3344,8 @@ class InPolicyUpdate2(object):
st0 = {'name': 'st0',
'conditions': {
- 'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
- 'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
+ 'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
+ 'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
'actions': {'route-disposition': 'reject-route'}}
policy = {'name': 'policy0',
@@ -3349,8 +3377,8 @@ class InPolicyUpdate2(object):
def setup2(env):
g1 = env.g1
e1 = env.e1
- q1 = env.q1
- q2 = env.q2
+ # q1 = env.q1
+ # q2 = env.q2
g1.clear_policy()
p0 = {'ip-prefix': '192.168.20.0/24'}
@@ -3365,8 +3393,9 @@ class InPolicyUpdate2(object):
g1.set_neighbor_set(ns0)
st0 = {'name': 'st0',
- 'conditions': {'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
- 'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
+ 'conditions': {
+ 'match-prefix-set': {'prefix-set': ps0['prefix-set-name']},
+ 'match-neighbor-set': {'neighbor-set': ns0['neighbor-set-name']}},
'actions': {'route-disposition': 'reject-route'}}
policy = {'name': 'policy0',
@@ -3470,7 +3499,7 @@ class InPolicyRejectImplicitWithdraw(object):
def setup(env):
g1 = env.g1
g2 = env.g2
- g3 = env.g3
+ # g3 = env.g3
g4 = env.g4
as0 = {'as-path-sets': [{'as-path-set-name': 'as0', 'as-path-list': ['_65002$']}]}
@@ -3492,11 +3521,10 @@ class InPolicyRejectImplicitWithdraw(object):
g2.wait_for(BGP_FSM_ESTABLISHED, g1)
-
@staticmethod
def check(env):
g1 = env.g1
- g2 = env.g2
+ # g2 = env.g2
g4 = env.g4
wait_for(lambda: len(g1.get_local_rib(g4)) == 1)
wait_for(lambda: len(g1.get_local_rib(g4)[0]['paths']) == 1)
@@ -3537,7 +3565,6 @@ class InPolicyRejectImplicitWithdraw(object):
wait_for(lambda: len(g1.get_local_rib(g4)) == 0)
wait_for(lambda: len(g4.get_global_rib()) == 0)
-
@staticmethod
def executor(env):
lookup_scenario("InPolicyRejectImplicitWithdraw").boot(env)
@@ -3549,7 +3576,7 @@ class InPolicyRejectImplicitWithdraw(object):
lookup_scenario("InPolicyRejectImplicitWithdraw").check3(env)
-class TestGoBGPBase():
+class TestGoBGPBase(unittest.TestCase):
wait_per_retry = 5
retry_limit = 10
diff --git a/test/scenario_test/route_server_softreset_test.py b/test/scenario_test/route_server_softreset_test.py
index 181274c7..172d3827 100644
--- a/test/scenario_test/route_server_softreset_test.py
+++ b/test/scenario_test/route_server_softreset_test.py
@@ -13,17 +13,21 @@
# 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.exabgp import *
+from __future__ import absolute_import
+
import sys
-import os
import time
+import unittest
+
+from fabric.api import local
import nose
+
from noseplugin import OptionParser, parser_option
+from lib import base
+from lib.base import BGP_FSM_ESTABLISHED
+from lib.gobgp import GoBGPContainer
+
class GoBGPTestBase(unittest.TestCase):
@@ -84,7 +88,7 @@ class GoBGPTestBase(unittest.TestCase):
pol0 = {'name': 'pol0', 'statements': [st0]}
- filename = g1.add_policy(pol0, g3, 'in', 'reject')
+ _filename = g1.add_policy(pol0, g3, 'in', 'reject')
g3.add_route('10.0.10.0/24')
g3.add_route('10.0.20.0/24')
@@ -102,7 +106,7 @@ class GoBGPTestBase(unittest.TestCase):
time.sleep(1)
num2 = g2.get_neighbor(g1)['state']['messages']['received']['update']
- self.assertTrue(num+1 == num2)
+ self.assertTrue((num + 1) == num2)
g3.softreset(g1, type='out')
diff --git a/test/scenario_test/route_server_test.py b/test/scenario_test/route_server_test.py
index 5949f615..e83812a1 100644
--- a/test/scenario_test/route_server_test.py
+++ b/test/scenario_test/route_server_test.py
@@ -13,17 +13,25 @@
# 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 *
+from __future__ import absolute_import
+
import sys
-import os
import time
+import unittest
+
+from fabric.api import local
import nose
+
from noseplugin import OptionParser, parser_option
+from lib import base
+from lib.base import (
+ BGP_FSM_ACTIVE,
+ BGP_FSM_ESTABLISHED,
+)
+from lib.gobgp import GoBGPContainer
+from lib.quagga import QuaggaBGPContainer
+
class GoBGPTestBase(unittest.TestCase):
@@ -39,9 +47,10 @@ class GoBGPTestBase(unittest.TestCase):
ctn_image_name=gobgp_ctn_image_name,
log_level=parser_option.gobgp_log_level)
- rs_clients = [QuaggaBGPContainer(name='q{0}'.format(i+1), asn=65001+i,
- router_id='192.168.0.{0}'.format(i+2))
- for i in range(3)]
+ rs_clients = [
+ QuaggaBGPContainer(name='q{0}'.format(i + 1), asn=(65001 + i),
+ router_id='192.168.0.{0}'.format(i + 2))
+ for i in range(3)]
ctns = [g1] + rs_clients
q1 = rs_clients[0]
q2 = rs_clients[1]
@@ -50,7 +59,7 @@ class GoBGPTestBase(unittest.TestCase):
# advertise a route from route-server-clients
routes = []
for idx, rs_client in enumerate(rs_clients):
- route = '10.0.{0}.0/24'.format(idx+1)
+ route = '10.0.{0}.0/24'.format(idx + 1)
rs_client.add_route(route)
routes.append(route)
@@ -76,11 +85,11 @@ class GoBGPTestBase(unittest.TestCase):
state = self.gobgp.get_neighbor_state(rs_client)
self.assertEqual(state, BGP_FSM_ESTABLISHED)
- if len(local_rib) < len(self.quaggas)-1:
+ if len(local_rib) < (len(self.quaggas) - 1):
time.sleep(self.wait_per_retry)
continue
- self.assertTrue(len(local_rib) == (len(self.quaggas)-1))
+ self.assertTrue(len(local_rib) == (len(self.quaggas) - 1))
for c in self.quaggas.itervalues():
if rs_client != c:
@@ -91,7 +100,7 @@ class GoBGPTestBase(unittest.TestCase):
if done:
continue
# should not reach here
- self.assertTrue(False)
+ raise AssertionError
def check_rs_client_rib(self):
for rs_client in self.quaggas.itervalues():
@@ -115,7 +124,7 @@ class GoBGPTestBase(unittest.TestCase):
if done:
continue
# should not reach here
- self.assertTrue(False)
+ raise AssertionError
# test each neighbor state is turned establish
def test_01_neighbor_established(self):
@@ -208,9 +217,9 @@ class GoBGPTestBase(unittest.TestCase):
self.gobgp.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=q3)
def check_nexthop(target_prefix, expected_nexthop):
- done = False
+ is_done = False
for _ in range(self.retry_limit):
- if done:
+ if is_done:
break
time.sleep(self.wait_per_retry)
for path in q1.get_global_rib():
@@ -220,9 +229,9 @@ class GoBGPTestBase(unittest.TestCase):
n_addrs = [i[1].split('/')[0] for i in
expected_nexthop.ip_addrs]
if path['nexthop'] in n_addrs:
- done = True
+ is_done = True
break
- return done
+ return is_done
done = check_nexthop('10.0.6.0/24', q3)
self.assertTrue(done)
diff --git a/test/scenario_test/route_server_test2.py b/test/scenario_test/route_server_test2.py
index f1b3ba63..ef61a6b9 100644
--- a/test/scenario_test/route_server_test2.py
+++ b/test/scenario_test/route_server_test2.py
@@ -13,17 +13,22 @@
# 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.exabgp import *
+from __future__ import absolute_import
+
import sys
-import os
import time
+import unittest
+
+from fabric.api import local
import nose
+
from noseplugin import OptionParser, parser_option
+from lib import base
+from lib.base import BGP_FSM_ESTABLISHED
+from lib.gobgp import GoBGPContainer
+from lib.exabgp import ExaBGPContainer
+
class GoBGPTestBase(unittest.TestCase):
@@ -87,8 +92,8 @@ class GoBGPTestBase(unittest.TestCase):
time.sleep(1)
info = self.gobgp.get_neighbor(self.clients['g2'])['state']['adj-table']
self.assertTrue(info['advertised'] == 1)
- self.assertTrue('accepted' not in info) # means info['accepted'] == 0
- self.assertTrue('received' not in info) # means info['received'] == 0
+ self.assertTrue('accepted' not in info) # means info['accepted'] == 0
+ self.assertTrue('received' not in info) # means info['received'] == 0
if __name__ == '__main__':
diff --git a/test/scenario_test/rtc_test.py b/test/scenario_test/rtc_test.py
index 3e1a2520..84b8b333 100644
--- a/test/scenario_test/rtc_test.py
+++ b/test/scenario_test/rtc_test.py
@@ -13,17 +13,21 @@
# 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 *
+from __future__ import absolute_import
+
+from itertools import combinations
import sys
-import os
import time
+import unittest
+
+from fabric.api import local
import nose
+
from noseplugin import OptionParser, parser_option
-from itertools import combinations
+
+from lib import base
+from lib.base import BGP_FSM_ESTABLISHED
+from lib.gobgp import GoBGPContainer
class GoBGPTestBase(unittest.TestCase):
@@ -124,7 +128,8 @@ class GoBGPTestBase(unittest.TestCase):
g5.local("gobgp vrf add vrf1 rd 100:100 rt both 100:100")
time.sleep(1)
- def check(client):
+
+ def check_rtc(client):
rib = g3.get_adj_rib_out(client, rf='rtc')
self.assertTrue(len(rib) == 1)
path = rib[0]
@@ -132,13 +137,15 @@ class GoBGPTestBase(unittest.TestCase):
ids = [attr['value'] for attr in path['attrs'] if attr['type'] == base.BGP_ATTR_TYPE_ORIGINATOR_ID]
self.assertTrue(len(ids) == 1)
self.assertTrue(ids[0] == g3.router_id)
- check(g4)
- check(g5)
+
+ check_rtc(g4)
+ check_rtc(g5)
g4.local("gobgp vrf vrf1 rib add 40.0.0.0/24")
g5.local("gobgp vrf vrf1 rib add 50.0.0.0/24")
time.sleep(1)
- def check(client):
+
+ def check_ipv4_l3vpn(client):
rib = g3.get_adj_rib_out(client, rf='ipv4-l3vpn')
self.assertTrue(len(rib) == 1)
path = rib[0]
@@ -146,8 +153,9 @@ class GoBGPTestBase(unittest.TestCase):
ids = [attr['value'] for attr in path['attrs'] if attr['type'] == base.BGP_ATTR_TYPE_ORIGINATOR_ID]
self.assertTrue(len(ids) == 1)
self.assertTrue(ids[0] != client.router_id)
- check(g4)
- check(g5)
+
+ check_ipv4_l3vpn(g4)
+ check_ipv4_l3vpn(g5)
def test_08_rr_setup2(self):
g1 = self.ctns['g1']
diff --git a/test/scenario_test/vrf_neighbor_test.py b/test/scenario_test/vrf_neighbor_test.py
index de2b0e41..78125169 100644
--- a/test/scenario_test/vrf_neighbor_test.py
+++ b/test/scenario_test/vrf_neighbor_test.py
@@ -13,17 +13,21 @@
# 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 *
+from __future__ import absolute_import
+
import sys
-import os
import time
+import unittest
+
+from fabric.api import local
import nose
+
from noseplugin import OptionParser, parser_option
+from lib import base
+from lib.base import BGP_FSM_ESTABLISHED
+from lib.gobgp import GoBGPContainer
+
class GoBGPTestBase(unittest.TestCase):
@@ -126,13 +130,13 @@ class GoBGPTestBase(unittest.TestCase):
self.assertTrue(len(dst) == 1)
self.assertTrue(len(dst[0]['paths']) == 1)
path = dst[0]['paths'][0]
- self.assertTrue([self.g1.asn] == path['aspath'])
+ self.assertTrue([self.g1.asn] == path['aspath'])
dst = self.g6.get_global_rib('10.0.0.0/24')
self.assertTrue(len(dst) == 1)
self.assertTrue(len(dst[0]['paths']) == 1)
path = dst[0]['paths'][0]
- self.assertTrue([self.g5.asn, self.g4.asn, self.g1.asn] == path['aspath'])
+ self.assertTrue([self.g5.asn, self.g4.asn, self.g1.asn] == path['aspath'])
dst = self.g7.get_global_rib('10.0.0.0/24')
self.assertTrue(len(dst) == 0)
@@ -155,13 +159,13 @@ class GoBGPTestBase(unittest.TestCase):
self.assertTrue(len(dst) == 1)
self.assertTrue(len(dst[0]['paths']) == 1)
path = dst[0]['paths'][0]
- self.assertTrue([self.g5.asn, self.g4.asn, self.g1.asn] == path['aspath'])
+ self.assertTrue([self.g5.asn, self.g4.asn, self.g1.asn] == path['aspath'])
dst = self.g7.get_global_rib('10.0.0.0/24')
self.assertTrue(len(dst) == 1)
self.assertTrue(len(dst[0]['paths']) == 1)
path = dst[0]['paths'][0]
- self.assertTrue([self.g5.asn, self.g4.asn, self.g3.asn] == path['aspath'])
+ self.assertTrue([self.g5.asn, self.g4.asn, self.g3.asn] == path['aspath'])
if __name__ == '__main__':
diff --git a/test/scenario_test/vrf_neighbor_test2.py b/test/scenario_test/vrf_neighbor_test2.py
index 13596f26..cee3bf76 100644
--- a/test/scenario_test/vrf_neighbor_test2.py
+++ b/test/scenario_test/vrf_neighbor_test2.py
@@ -13,18 +13,25 @@
# 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.base import wait_for_completion
-from lib.gobgp import *
-from lib.quagga import *
+from __future__ import absolute_import
+
import sys
-import os
import time
+import unittest
+
+from fabric.api import local
import nose
+
from noseplugin import OptionParser, parser_option
+from lib import base
+from lib.base import (
+ BGP_FSM_ACTIVE,
+ BGP_FSM_ESTABLISHED,
+ wait_for_completion,
+)
+from lib.gobgp import GoBGPContainer
+
class GoBGPTestBase(unittest.TestCase):
diff --git a/test/scenario_test/zapi_v3_test.py b/test/scenario_test/zapi_v3_test.py
index a08550ec..f11d98e7 100644
--- a/test/scenario_test/zapi_v3_test.py
+++ b/test/scenario_test/zapi_v3_test.py
@@ -13,17 +13,20 @@
# 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 *
+from __future__ import absolute_import
+
import sys
-import os
import time
+import unittest
+
+from fabric.api import local
import nose
+
from noseplugin import OptionParser, parser_option
-from itertools import chain
+
+from lib import base
+from lib.base import BGP_FSM_ESTABLISHED
+from lib.gobgp import GoBGPContainer
class GoBGPTestBase(unittest.TestCase):
@@ -34,14 +37,14 @@ class GoBGPTestBase(unittest.TestCase):
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,
- zebra=True, zapi_version=3)
+ ctn_image_name=gobgp_ctn_image_name,
+ log_level=parser_option.gobgp_log_level,
+ zebra=True, zapi_version=3)
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,
- zebra=True, zapi_version=3)
+ ctn_image_name=gobgp_ctn_image_name,
+ log_level=parser_option.gobgp_log_level,
+ zebra=True, zapi_version=3)
initial_wait_time = max(ctn.run() for ctn in [g1, g2])