summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorCarl Baldwin <carl@ecbaldwin.net>2018-10-29 20:01:39 +0000
committerCarl Baldwin <carl@ecbaldwin.net>2018-10-29 20:10:19 +0000
commit8bccb4278a1c6cb291a9635a4b2252372f074b7e (patch)
treed1f9d1061a1db670fea7af527e10add4a2b09e59 /test
parentc8694bc8a7dccd663689f8d134b89fe3a1f37d70 (diff)
Use assertEqual in python tests
In trying to run the local tests, I found that changing these assertTrue calls to assertEqual helped me out. With this, a failure shows the actual and expected values rather than just saying "True is not False" which is less helpful.
Diffstat (limited to 'test')
-rw-r--r--test/scenario_test/bgp_malformed_msg_handling_test.py8
-rw-r--r--test/scenario_test/bgp_router_test.py50
-rw-r--r--test/scenario_test/bgp_unnumbered_test.py2
-rw-r--r--test/scenario_test/bgp_zebra_test.py4
-rw-r--r--test/scenario_test/evpn_test.py22
-rw-r--r--test/scenario_test/global_policy_test.py46
-rw-r--r--test/scenario_test/graceful_restart_test.py12
-rw-r--r--test/scenario_test/ibgp_router_test.py40
-rw-r--r--test/scenario_test/long_lived_graceful_restart_test.py20
-rw-r--r--test/scenario_test/route_server_as2_test.py2
-rw-r--r--test/scenario_test/route_server_ipv4_v6_test.py12
-rw-r--r--test/scenario_test/route_server_softreset_test.py6
-rw-r--r--test/scenario_test/route_server_test.py6
-rw-r--r--test/scenario_test/route_server_test2.py10
-rw-r--r--test/scenario_test/vrf_neighbor_test.py42
-rw-r--r--test/scenario_test/zapi_v3_test.py8
16 files changed, 145 insertions, 145 deletions
diff --git a/test/scenario_test/bgp_malformed_msg_handling_test.py b/test/scenario_test/bgp_malformed_msg_handling_test.py
index feaac264..b5af69e2 100644
--- a/test/scenario_test/bgp_malformed_msg_handling_test.py
+++ b/test/scenario_test/bgp_malformed_msg_handling_test.py
@@ -68,9 +68,9 @@ class GoBGPTestBase(unittest.TestCase):
# Confirm the path is added
dests = self.g1.get_global_rib()
- self.assertTrue(len(dests) == 1)
+ self.assertEqual(len(dests), 1)
routes = dests[0]['paths']
- self.assertTrue(len(routes) == 1)
+ self.assertEqual(len(routes), 1)
# Confirm the attribute 'AGGREGATOR(type=7)' is discarded
for d in routes[0]['attrs']:
@@ -94,8 +94,8 @@ class GoBGPTestBase(unittest.TestCase):
# Confirm the number of path in RIB is only one
dests = self.g1.get_global_rib()
- self.assertTrue(len(dests) == 1)
- self.assertTrue(dests[0]['paths'][0]['nlri']['prefix'] == '20.0.0.0/24')
+ self.assertEqual(len(dests), 1)
+ self.assertEqual(dests[0]['paths'][0]['nlri']['prefix'], '20.0.0.0/24')
if __name__ == '__main__':
diff --git a/test/scenario_test/bgp_router_test.py b/test/scenario_test/bgp_router_test.py
index a69aa3f7..e7ac9ec1 100644
--- a/test/scenario_test/bgp_router_test.py
+++ b/test/scenario_test/bgp_router_test.py
@@ -128,7 +128,7 @@ class GoBGPTestBase(unittest.TestCase):
time.sleep(interval)
continue
- self.assertTrue(len(global_rib) == len(self.quaggas))
+ self.assertEqual(len(global_rib), len(self.quaggas))
for c in self.quaggas.itervalues():
for r in c.routes:
@@ -222,21 +222,21 @@ class GoBGPTestBase(unittest.TestCase):
def test_10_originate_path(self):
self.gobgp.add_route('10.10.0.0/24')
dst = self.gobgp.get_global_rib('10.10.0.0/24')
- self.assertTrue(len(dst) == 1)
- self.assertTrue(len(dst[0]['paths']) == 1)
+ self.assertEqual(len(dst), 1)
+ self.assertEqual(len(dst[0]['paths']), 1)
path = dst[0]['paths'][0]
- self.assertTrue(path['nexthop'] == '0.0.0.0')
- self.assertTrue(len(path['aspath']) == 0)
+ self.assertEqual(path['nexthop'], '0.0.0.0')
+ self.assertEqual(len(path['aspath']), 0)
def test_11_check_adj_rib_out(self):
for q in self.quaggas.itervalues():
paths = self.gobgp.get_adj_rib_out(q, '10.10.0.0/24')
- self.assertTrue(len(paths) == 1)
+ self.assertEqual(len(paths), 1)
path = paths[0]
peer_info = self.gobgp.peers[q]
local_addr = peer_info['local_addr'].split('/')[0]
- self.assertTrue(path['nexthop'] == local_addr)
- self.assertTrue(path['aspath'] == [self.gobgp.asn])
+ self.assertEqual(path['nexthop'], local_addr)
+ self.assertEqual(path['aspath'], [self.gobgp.asn])
def test_12_disable_peer(self):
q1 = self.quaggas['q1']
@@ -247,13 +247,13 @@ class GoBGPTestBase(unittest.TestCase):
for route in q1.routes.iterkeys():
dst = self.gobgp.get_global_rib(route)
- self.assertTrue(len(dst) == 0)
+ self.assertEqual(len(dst), 0)
for q in self.quaggas.itervalues():
if q is q1:
continue
paths = self.gobgp.get_adj_rib_out(q, route)
- self.assertTrue(len(paths) == 0)
+ self.assertEqual(len(paths), 0)
def test_13_enable_peer(self):
q1 = self.quaggas['q1']
@@ -280,24 +280,24 @@ class GoBGPTestBase(unittest.TestCase):
# iBGP peer
g2 = self.quaggas['g2']
paths = g2.get_global_rib('10.20.0.0/24')
- self.assertTrue(len(paths) == 1)
- self.assertTrue(len(paths[0]['paths']) == 1)
+ self.assertEqual(len(paths), 1)
+ self.assertEqual(len(paths[0]['paths']), 1)
path = paths[0]['paths'][0]
local_pref = extract_path_attribute(path, BGP_ATTR_TYPE_LOCAL_PREF)
- self.assertTrue(local_pref['value'] == 1000)
+ self.assertEqual(local_pref['value'], 1000)
med = extract_path_attribute(path, BGP_ATTR_TYPE_MULTI_EXIT_DISC)
- self.assertTrue(med['metric'] == 2000)
+ self.assertEqual(med['metric'], 2000)
# eBGP peer
q1 = self.quaggas['q1']
paths = q1.get_global_rib('10.20.0.0/24')
- self.assertTrue(len(paths) == 1)
+ self.assertEqual(len(paths), 1)
path = paths[0]
local_pref = extract_path_attribute(path, BGP_ATTR_TYPE_LOCAL_PREF)
# local_pref's default value is 100
- self.assertTrue(local_pref['value'] == 100)
+ self.assertEqual(local_pref['value'], 100)
med = extract_path_attribute(path, BGP_ATTR_TYPE_MULTI_EXIT_DISC)
- self.assertTrue(med['metric'] == 2000)
+ self.assertEqual(med['metric'], 2000)
def test_17_check_shutdown(self):
g1 = self.gobgp
@@ -398,7 +398,7 @@ class GoBGPTestBase(unittest.TestCase):
wait_for_completion(lambda: len(g2.get_global_rib(prefix)) == 0)
ret = json.loads(r.next())
- self.assertTrue(ret[0]['nlri']['prefix'] == prefix)
+ self.assertEqual(ret[0]['nlri']['prefix'], prefix)
self.assertTrue('withdrawal' in ret[0])
def test_22_check_cli_sorted(self):
@@ -425,7 +425,7 @@ class GoBGPTestBase(unittest.TestCase):
except StopIteration:
break
- self.assertTrue(cnt == cnt2)
+ self.assertEqual(cnt, cnt2)
def test_23_check_withdrawal3(self):
gobgp_ctn_image_name = parser_option.gobgp_image
@@ -456,18 +456,18 @@ class GoBGPTestBase(unittest.TestCase):
g4.local('gobgp global rib add 50.0.0.0/24 med 10')
paths = g1.get_adj_rib_out(g3, '50.0.0.0/24')
- self.assertTrue(len(paths) == 0)
+ self.assertEqual(len(paths), 0)
paths = g1.get_adj_rib_out(g4, '50.0.0.0/24')
- self.assertTrue(len(paths) == 1)
- self.assertTrue(paths[0]['source-id'] == '192.168.0.8')
+ self.assertEqual(len(paths), 1)
+ self.assertEqual(paths[0]['source-id'], '192.168.0.8')
g3.local('gobgp global rib del 50.0.0.0/24')
paths = g1.get_adj_rib_out(g3, '50.0.0.0/24')
- self.assertTrue(len(paths) == 1)
- self.assertTrue(paths[0]['source-id'] == '192.168.0.9')
+ self.assertEqual(len(paths), 1)
+ self.assertEqual(paths[0]['source-id'], '192.168.0.9')
paths = g1.get_adj_rib_out(g4, '50.0.0.0/24')
- self.assertTrue(len(paths) == 0)
+ self.assertEqual(len(paths), 0)
if __name__ == '__main__':
diff --git a/test/scenario_test/bgp_unnumbered_test.py b/test/scenario_test/bgp_unnumbered_test.py
index 3971c269..42aec3b9 100644
--- a/test/scenario_test/bgp_unnumbered_test.py
+++ b/test/scenario_test/bgp_unnumbered_test.py
@@ -86,7 +86,7 @@ class GoBGPTestBase(unittest.TestCase):
time.sleep(1)
rib = self.g2.get_global_rib(rf='ipv4')
- self.assertTrue(len(rib) == 1)
+ self.assertEqual(len(rib), 1)
if __name__ == '__main__':
diff --git a/test/scenario_test/bgp_zebra_test.py b/test/scenario_test/bgp_zebra_test.py
index 5b40c109..a8787e22 100644
--- a/test/scenario_test/bgp_zebra_test.py
+++ b/test/scenario_test/bgp_zebra_test.py
@@ -150,7 +150,7 @@ class GoBGPTestBase(unittest.TestCase):
# test reachability between o1 and o2
addrs = [e[1] for e in o2.ip_addrs if 'br03_v4' in e[2]]
- self.assertTrue(len(addrs) == 1)
+ self.assertEqual(len(addrs), 1)
o2_addr = addrs[0]
o1.get_reachability(o2_addr)
@@ -199,7 +199,7 @@ class GoBGPTestBase(unittest.TestCase):
# test reachability between o1 and o2
addrs = [e[1] for e in o2.ip6_addrs if 'br03_v6' in e[2]]
- self.assertTrue(len(addrs) == 1)
+ self.assertEqual(len(addrs), 1)
o2_addr = addrs[0]
o1.get_reachability(o2_addr)
diff --git a/test/scenario_test/evpn_test.py b/test/scenario_test/evpn_test.py
index b3d290bc..7e227b05 100644
--- a/test/scenario_test/evpn_test.py
+++ b/test/scenario_test/evpn_test.py
@@ -83,11 +83,11 @@ class GoBGPTestBase(unittest.TestCase):
'-a evpn macadv 11:22:33:44:55:66 10.0.0.1 esi AS 1 1 1 etag 1000 label 1000 '
'rd 10:10 rt 10:10')
grib = self.g1.get_global_rib(rf='evpn')
- self.assertTrue(len(grib) == 1)
+ self.assertEqual(len(grib), 1)
dst = grib[0]
- self.assertTrue(len(dst['paths']) == 1)
+ self.assertEqual(len(dst['paths']), 1)
path = dst['paths'][0]
- self.assertTrue(path['nexthop'] == '0.0.0.0')
+ self.assertEqual(path['nexthop'], '0.0.0.0')
interval = 1
timeout = int(30 / interval)
@@ -101,9 +101,9 @@ class GoBGPTestBase(unittest.TestCase):
time.sleep(interval)
continue
- self.assertTrue(len(grib) == 1)
+ self.assertEqual(len(grib), 1)
dst = grib[0]
- self.assertTrue(len(dst['paths']) == 1)
+ self.assertEqual(len(dst['paths']), 1)
path = dst['paths'][0]
n_addrs = [i[1].split('/')[0] for i in self.g1.ip_addrs]
self.assertTrue(path['nexthop'] in n_addrs)
@@ -117,13 +117,13 @@ class GoBGPTestBase(unittest.TestCase):
time.sleep(3)
grib = self.g1.get_global_rib(rf='evpn')
- self.assertTrue(len(grib) == 1)
+ self.assertEqual(len(grib), 1)
dst = grib[0]
- self.assertTrue(len(dst['paths']) == 1)
+ self.assertEqual(len(dst['paths']), 1)
path = dst['paths'][0]
n_addrs = [i[1].split('/')[0] for i in self.g2.ip_addrs]
self.assertTrue(path['nexthop'] in n_addrs)
- self.assertTrue(get_mac_mobility_sequence(path['attrs']) == 0)
+ self.assertEqual(get_mac_mobility_sequence(path['attrs']), 0)
def test_04_check_mac_mobility_again(self):
self.g1.local('gobgp global rib add '
@@ -133,13 +133,13 @@ class GoBGPTestBase(unittest.TestCase):
time.sleep(3)
grib = self.g2.get_global_rib(rf='evpn')
- self.assertTrue(len(grib) == 1)
+ self.assertEqual(len(grib), 1)
dst = grib[0]
- self.assertTrue(len(dst['paths']) == 1)
+ self.assertEqual(len(dst['paths']), 1)
path = dst['paths'][0]
n_addrs = [i[1].split('/')[0] for i in self.g1.ip_addrs]
self.assertTrue(path['nexthop'] in n_addrs)
- self.assertTrue(get_mac_mobility_sequence(path['attrs']) == 1)
+ self.assertEqual(get_mac_mobility_sequence(path['attrs']), 1)
if __name__ == '__main__':
diff --git a/test/scenario_test/global_policy_test.py b/test/scenario_test/global_policy_test.py
index 34a96d48..5c1aea87 100644
--- a/test/scenario_test/global_policy_test.py
+++ b/test/scenario_test/global_policy_test.py
@@ -85,7 +85,7 @@ class GoBGPTestBase(unittest.TestCase):
def test_02_check_adj_rib_out(self):
for q in self.quaggas.itervalues():
- self.assertTrue(len(self.gobgp.get_adj_rib_out(q)) == 0)
+ self.assertEqual(len(self.gobgp.get_adj_rib_out(q)), 0)
def test_03_add_peer(self):
q = ExaBGPContainer(name='q4', asn=65004, router_id='192.168.0.5')
@@ -96,7 +96,7 @@ class GoBGPTestBase(unittest.TestCase):
self.gobgp.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=q)
self.quaggas['q4'] = q
for q in self.quaggas.itervalues():
- self.assertTrue(len(self.gobgp.get_adj_rib_out(q)) == 0)
+ self.assertEqual(len(self.gobgp.get_adj_rib_out(q)), 0)
def test_04_disable_peer(self):
q3 = self.quaggas['q3']
@@ -106,7 +106,7 @@ class GoBGPTestBase(unittest.TestCase):
for q in self.quaggas.itervalues():
if q.name == 'q3':
continue
- self.assertTrue(len(self.gobgp.get_adj_rib_out(q)) == 0)
+ self.assertEqual(len(self.gobgp.get_adj_rib_out(q)), 0)
def test_05_enable_peer(self):
q3 = self.quaggas['q3']
@@ -114,7 +114,7 @@ class GoBGPTestBase(unittest.TestCase):
self.gobgp.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=q3)
for q in self.quaggas.itervalues():
- self.assertTrue(len(self.gobgp.get_adj_rib_out(q)) == 0)
+ self.assertEqual(len(self.gobgp.get_adj_rib_out(q)), 0)
def test_06_disable_peer2(self):
q3 = self.quaggas['q3']
@@ -130,7 +130,7 @@ class GoBGPTestBase(unittest.TestCase):
for q in self.quaggas.itervalues():
if q.name == 'q3':
continue
- self.assertTrue(len(self.gobgp.get_adj_rib_out(q)) == 0)
+ self.assertEqual(len(self.gobgp.get_adj_rib_out(q)), 0)
def test_07_adv_to_one_peer(self):
self.gobgp.local('gobgp policy neighbor add ns0 {0}'.format(self.gobgp.peers[self.quaggas['q1']]['neigh_addr'].split('/')[0]))
@@ -148,9 +148,9 @@ class GoBGPTestBase(unittest.TestCase):
continue
paths = self.gobgp.get_adj_rib_out(q)
if q == self.quaggas['q1']:
- self.assertTrue(len(paths) == 2)
+ self.assertEqual(len(paths), 2)
else:
- self.assertTrue(len(paths) == 0)
+ self.assertEqual(len(paths), 0)
def test_09_change_global_policy(self):
self.gobgp.local('gobgp policy statement st0 add action community add 65100:10')
@@ -164,7 +164,7 @@ class GoBGPTestBase(unittest.TestCase):
continue
paths = self.gobgp.get_adj_rib_out(q)
if q != self.quaggas['q3']:
- self.assertTrue(len(paths) == 2)
+ self.assertEqual(len(paths), 2)
for path in paths:
if q == self.quaggas['q1']:
self.assertTrue(community_exists(path, '65100:10'))
@@ -194,7 +194,7 @@ class GoBGPTestBase(unittest.TestCase):
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)
+ self.assertEqual(path['local-pref'], 300)
def test_14_route_type_condition_local(self):
self.gobgp.local('gobgp policy statement st2 add action accept')
@@ -205,14 +205,14 @@ class GoBGPTestBase(unittest.TestCase):
self.gobgp.softreset(q, type='out')
q1 = self.quaggas['q1']
- self.assertTrue(len(self.gobgp.get_adj_rib_out(q1)) == 0)
+ self.assertEqual(len(self.gobgp.get_adj_rib_out(q1)), 0)
self.gobgp.add_route('10.20.0.0/24')
time.sleep(1)
- self.assertTrue(len(self.gobgp.get_adj_rib_out(q1)) == 1)
- self.assertTrue(self.gobgp.get_adj_rib_out(q1)[0]['nlri']['prefix'] == u'10.20.0.0/24')
+ self.assertEqual(len(self.gobgp.get_adj_rib_out(q1)), 1)
+ self.assertEqual(self.gobgp.get_adj_rib_out(q1)[0]['nlri']['prefix'], u'10.20.0.0/24')
def test_15_route_type_condition_internal(self):
self.gobgp.local('gobgp policy statement st22 add action accept')
@@ -223,15 +223,15 @@ class GoBGPTestBase(unittest.TestCase):
self.gobgp.softreset(q, type='out')
q1 = self.quaggas['q1']
- self.assertTrue(len(self.gobgp.get_adj_rib_out(q1)) == 0)
+ self.assertEqual(len(self.gobgp.get_adj_rib_out(q1)), 0)
q5 = self.quaggas['q5']
q5.add_route('10.30.0.0/24')
time.sleep(1)
- self.assertTrue(len(self.gobgp.get_adj_rib_out(q1)) == 1)
- self.assertTrue(self.gobgp.get_adj_rib_out(q1)[0]['nlri']['prefix'] == u'10.30.0.0/24')
+ self.assertEqual(len(self.gobgp.get_adj_rib_out(q1)), 1)
+ self.assertEqual(self.gobgp.get_adj_rib_out(q1)[0]['nlri']['prefix'], u'10.30.0.0/24')
def test_16_route_type_condition_external(self):
self.gobgp.local('gobgp policy statement st222 add action accept')
@@ -247,19 +247,19 @@ class GoBGPTestBase(unittest.TestCase):
self.gobgp.add_route('10.40.0.0/24')
time.sleep(1)
num2 = len(self.gobgp.get_adj_rib_out(q1))
- self.assertTrue(num1 == num2)
+ self.assertEqual(num1, num2)
q5 = self.quaggas['q5']
q5.add_route('10.50.0.0/24')
time.sleep(1)
num3 = len(self.gobgp.get_adj_rib_out(q1))
- self.assertTrue(num1 == num3)
+ self.assertEqual(num1, num3)
q2 = self.quaggas['q2']
q2.add_route('10.60.0.0/24')
time.sleep(1)
num4 = len(self.gobgp.get_adj_rib_out(q1))
- self.assertTrue(num1 + 1 == num4)
+ self.assertEqual(num1 + 1, num4)
def test_17_multi_statement(self):
self.gobgp.local('gobgp policy statement st3 add action med set 100')
@@ -270,11 +270,11 @@ class GoBGPTestBase(unittest.TestCase):
self.gobgp.add_route('10.70.0.0/24')
time.sleep(1)
rib = self.gobgp.get_global_rib('10.70.0.0/24')
- self.assertTrue(len(rib) == 1)
- self.assertTrue(len(rib[0]['paths']) == 1)
+ self.assertEqual(len(rib), 1)
+ self.assertEqual(len(rib[0]['paths']), 1)
path = rib[0]['paths'][0]
- self.assertTrue(path['med'] == 100)
- self.assertTrue(path['local-pref'] == 100)
+ self.assertEqual(path['med'], 100)
+ self.assertEqual(path['local-pref'], 100)
def test_18_reject_policy(self):
self.gobgp.local('gobgp global policy import set default reject')
@@ -286,7 +286,7 @@ class GoBGPTestBase(unittest.TestCase):
# them
for v in self.gobgp.get_global_rib():
for p in v['paths']:
- self.assertTrue(p['nexthop'] == '0.0.0.0')
+ self.assertEqual(p['nexthop'], '0.0.0.0')
if __name__ == '__main__':
diff --git a/test/scenario_test/graceful_restart_test.py b/test/scenario_test/graceful_restart_test.py
index ab2eec1e..a97c9642 100644
--- a/test/scenario_test/graceful_restart_test.py
+++ b/test/scenario_test/graceful_restart_test.py
@@ -129,7 +129,7 @@ class GoBGPTestBase(unittest.TestCase):
g3.add_peer(g1)
g1.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=g3)
time.sleep(1)
- self.assertTrue(len(g3.get_global_rib('10.10.20.0/24')) == 1)
+ self.assertEqual(len(g3.get_global_rib('10.10.20.0/24')), 1)
def test_05_graceful_restart(self):
g1 = self.bgpds['g1']
@@ -137,19 +137,19 @@ class GoBGPTestBase(unittest.TestCase):
g3 = self.bgpds['g3']
g1.stop_gobgp()
g2.wait_for(expected_state=BGP_FSM_ACTIVE, peer=g1)
- self.assertTrue(len(g2.get_global_rib('10.10.20.0/24')) == 1)
- self.assertTrue(len(g2.get_global_rib('10.10.30.0/24')) == 1)
+ self.assertEqual(len(g2.get_global_rib('10.10.20.0/24')), 1)
+ self.assertEqual(len(g2.get_global_rib('10.10.30.0/24')), 1)
for d in g2.get_global_rib():
for p in d['paths']:
self.assertTrue(p['stale'])
- self.assertTrue(len(g3.get_global_rib('10.10.20.0/24')) == 0)
- self.assertTrue(len(g3.get_global_rib('10.10.30.0/24')) == 1)
+ self.assertEqual(len(g3.get_global_rib('10.10.20.0/24')), 0)
+ self.assertEqual(len(g3.get_global_rib('10.10.30.0/24')), 1)
def test_06_test_restart_timer_expire(self):
time.sleep(GRACEFUL_RESTART_TIME + 5)
g2 = self.bgpds['g2']
- self.assertTrue(len(g2.get_global_rib()) == 0)
+ self.assertEqual(len(g2.get_global_rib()), 0)
def test_07_multineighbor_established(self):
g1 = self.bgpds['g1']
diff --git a/test/scenario_test/ibgp_router_test.py b/test/scenario_test/ibgp_router_test.py
index 59815e6e..4b709681 100644
--- a/test/scenario_test/ibgp_router_test.py
+++ b/test/scenario_test/ibgp_router_test.py
@@ -101,27 +101,27 @@ class GoBGPTestBase(unittest.TestCase):
for q in self.quaggas.itervalues():
paths = self.gobgp.get_adj_rib_out(q)
# bgp speaker mustn't forward iBGP routes to iBGP peers
- self.assertTrue(len(paths) == 0)
+ self.assertEqual(len(paths), 0)
def test_04_originate_path(self):
self.gobgp.add_route('10.10.0.0/24')
dst = self.gobgp.get_global_rib('10.10.0.0/24')
- self.assertTrue(len(dst) == 1)
- self.assertTrue(len(dst[0]['paths']) == 1)
+ self.assertEqual(len(dst), 1)
+ self.assertEqual(len(dst[0]['paths']), 1)
path = dst[0]['paths'][0]
- self.assertTrue(path['nexthop'] == '0.0.0.0')
- self.assertTrue(len(path['aspath']) == 0)
+ self.assertEqual(path['nexthop'], '0.0.0.0')
+ self.assertEqual(len(path['aspath']), 0)
def test_05_check_gobgp_adj_rib_out(self):
for q in self.quaggas.itervalues():
paths = self.gobgp.get_adj_rib_out(q)
- self.assertTrue(len(paths) == len(self.gobgp.routes))
+ self.assertEqual(len(paths), len(self.gobgp.routes))
path = paths[0]
- self.assertTrue(path['nlri']['prefix'] == '10.10.0.0/24')
+ self.assertEqual(path['nlri']['prefix'], '10.10.0.0/24')
peer_info = self.gobgp.peers[q]
local_addr = peer_info['local_addr'].split('/')[0]
- self.assertTrue(path['nexthop'] == local_addr)
- self.assertTrue(len(path['aspath']) == 0)
+ self.assertEqual(path['nexthop'], local_addr)
+ self.assertEqual(len(path['aspath']), 0)
# check routes are properly advertised to all BGP speaker
def test_06_check_quagga_global_rib(self):
@@ -145,13 +145,13 @@ class GoBGPTestBase(unittest.TestCase):
self.assertTrue(r in (p['prefix'] for p in global_rib))
for rr in global_rib:
if rr['prefix'] == r:
- self.assertTrue(rr['nexthop'] == local_addr)
+ self.assertEqual(rr['nexthop'], local_addr)
for r in q.routes.keys():
self.assertTrue(r in (p['prefix'] for p in global_rib))
for rr in global_rib:
if rr['prefix'] == r:
- self.assertTrue(rr['nexthop'] == '0.0.0.0')
+ self.assertEqual(rr['nexthop'], '0.0.0.0')
done = True
if done:
@@ -185,8 +185,8 @@ class GoBGPTestBase(unittest.TestCase):
for path in paths:
peer_info = self.gobgp.peers[q3]
local_addr = peer_info['local_addr'].split('/')[0]
- self.assertTrue(path['nexthop'] == local_addr)
- self.assertTrue(path['aspath'] == [self.gobgp.asn])
+ self.assertEqual(path['nexthop'], local_addr)
+ self.assertEqual(path['aspath'], [self.gobgp.asn])
def test_10_check_gobgp_ibgp_adj_rib_out(self):
q1 = self.quaggas['q1']
@@ -196,14 +196,14 @@ class GoBGPTestBase(unittest.TestCase):
for prefix in q3.routes.iterkeys():
paths = self.gobgp.get_adj_rib_out(q1, prefix)
- self.assertTrue(len(paths) == 1)
+ self.assertEqual(len(paths), 1)
path = paths[0]
# bgp router mustn't change nexthop of routes from eBGP peers
# which are sent to iBGP peers
- self.assertTrue(path['nexthop'] == neigh_addr)
+ self.assertEqual(path['nexthop'], neigh_addr)
# bgp router mustn't change aspath of routes from eBGP peers
# which are sent to iBGP peers
- self.assertTrue(path['aspath'] == [q3.asn])
+ self.assertEqual(path['aspath'], [q3.asn])
# disable ebgp peer, check ebgp routes are removed
def test_11_disable_ebgp_peer(self):
@@ -214,13 +214,13 @@ class GoBGPTestBase(unittest.TestCase):
for route in q3.routes.iterkeys():
dst = self.gobgp.get_global_rib(route)
- self.assertTrue(len(dst) == 0)
+ self.assertEqual(len(dst), 0)
for q in self.quaggas.itervalues():
paths = self.gobgp.get_adj_rib_out(q)
# only gobgp's locally generated routes must exists
print paths
- self.assertTrue(len(paths) == len(self.gobgp.routes))
+ self.assertEqual(len(paths), len(self.gobgp.routes))
def test_12_disable_ibgp_peer(self):
q1 = self.quaggas['q1']
@@ -229,7 +229,7 @@ class GoBGPTestBase(unittest.TestCase):
for route in q1.routes.iterkeys():
dst = self.gobgp.get_global_rib(route)
- self.assertTrue(len(dst) == 0)
+ self.assertEqual(len(dst), 0)
def test_13_enable_ibgp_peer(self):
q1 = self.quaggas['q1']
@@ -240,7 +240,7 @@ class GoBGPTestBase(unittest.TestCase):
for q in self.quaggas.itervalues():
paths = self.gobgp.get_adj_rib_out(q)
# only gobgp's locally generated routes must exists
- self.assertTrue(len(paths) == len(self.gobgp.routes))
+ self.assertEqual(len(paths), len(self.gobgp.routes))
def test_15_add_ebgp_peer(self):
q4 = QuaggaBGPContainer(name='q4', asn=65001, router_id='192.168.0.5')
diff --git a/test/scenario_test/long_lived_graceful_restart_test.py b/test/scenario_test/long_lived_graceful_restart_test.py
index 44f4a45b..171f204d 100644
--- a/test/scenario_test/long_lived_graceful_restart_test.py
+++ b/test/scenario_test/long_lived_graceful_restart_test.py
@@ -94,22 +94,22 @@ class GoBGPTestBase(unittest.TestCase):
time.sleep(1)
- self.assertTrue(len(g1.get_global_rib('10.0.0.0/24')) == 1)
+ self.assertEqual(len(g1.get_global_rib('10.0.0.0/24')), 1)
# 10.10.0.0/24 is announced with no-llgr community
# must not exist in the rib
- self.assertTrue(len(g1.get_global_rib('10.10.0.0/24')) == 0)
+ self.assertEqual(len(g1.get_global_rib('10.10.0.0/24')), 0)
for d in g1.get_global_rib():
for p in d['paths']:
self.assertTrue(p['stale'])
- self.assertTrue(len(g3.get_global_rib('10.0.0.0/24')) == 1)
+ self.assertEqual(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]))
self.assertTrue(0xffff0006 in comms)
# g4 is not llgr capable, llgr-stale route must be
# withdrawn
- self.assertTrue(len(g4.get_global_rib('10.0.0.0/24')) == 0)
+ self.assertEqual(len(g4.get_global_rib('10.0.0.0/24')), 0)
g2.start_gobgp(graceful_restart=True)
g2.local('gobgp global rib add 10.0.0.0/24')
@@ -122,8 +122,8 @@ class GoBGPTestBase(unittest.TestCase):
# 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)
- self.assertTrue(len(g1.get_global_rib('10.10.0.0/24')) == 1)
+ self.assertEqual(len(g1.get_global_rib('10.0.0.0/24')), 1)
+ self.assertEqual(len(g1.get_global_rib('10.10.0.0/24')), 1)
for d in g1.get_global_rib():
for p in d['paths']:
self.assertFalse(p.get('stale', False))
@@ -137,7 +137,7 @@ class GoBGPTestBase(unittest.TestCase):
time.sleep(1)
# check g2's path is chosen as best and advertised
rib = g3.get_global_rib('10.0.0.0/24')
- self.assertTrue(len(rib) == 1)
+ self.assertEqual(len(rib), 1)
self.assertTrue(g2.asn in rib[0]['paths'][0]['aspath'])
g2.stop_gobgp()
@@ -148,19 +148,19 @@ class GoBGPTestBase(unittest.TestCase):
# 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')
- self.assertTrue(len(rib) == 1)
+ self.assertEqual(len(rib), 1)
self.assertTrue(g4.asn in rib[0]['paths'][0]['aspath'])
# if no candidate exists, llgr_stale route will be chosen as best
rib = g3.get_global_rib('10.10.0.0/24')
- self.assertTrue(len(rib) == 1)
+ self.assertEqual(len(rib), 1)
self.assertTrue(g2.asn in rib[0]['paths'][0]['aspath'])
def test_05_llgr_restart_timer_expire(self):
time.sleep(LONG_LIVED_GRACEFUL_RESTART_TIME + 5)
g3 = self.bgpds['g3']
rib = g3.get_global_rib('10.10.0.0/24')
- self.assertTrue(len(rib) == 0)
+ self.assertEqual(len(rib), 0)
if __name__ == '__main__':
diff --git a/test/scenario_test/route_server_as2_test.py b/test/scenario_test/route_server_as2_test.py
index d60b4b21..75babb15 100644
--- a/test/scenario_test/route_server_as2_test.py
+++ b/test/scenario_test/route_server_as2_test.py
@@ -94,7 +94,7 @@ class GoBGPTestBase(unittest.TestCase):
time.sleep(self.wait_per_retry)
continue
- self.assertTrue(len(local_rib) == 4)
+ self.assertEqual(len(local_rib), 4)
done = True
if done:
diff --git a/test/scenario_test/route_server_ipv4_v6_test.py b/test/scenario_test/route_server_ipv4_v6_test.py
index ce17e18c..28b438d2 100644
--- a/test/scenario_test/route_server_ipv4_v6_test.py
+++ b/test/scenario_test/route_server_ipv4_v6_test.py
@@ -91,7 +91,7 @@ class GoBGPIPv6Test(unittest.TestCase):
time.sleep(self.wait_per_retry)
continue
- self.assertTrue(len(local_rib) == (len(ctns) - 1))
+ self.assertEqual(len(local_rib), (len(ctns) - 1))
for c in ctns.itervalues():
if rs_client != c:
@@ -116,7 +116,7 @@ class GoBGPIPv6Test(unittest.TestCase):
time.sleep(self.wait_per_retry)
continue
- self.assertTrue(len(global_rib) == len(ctns))
+ self.assertEqual(len(global_rib), len(ctns))
for c in ctns.itervalues():
for r in c.routes:
@@ -159,12 +159,12 @@ class GoBGPIPv6Test(unittest.TestCase):
def test_08_check_rib(self):
for q in self.ipv4s.itervalues():
- self.assertTrue(len(self.gobgp.get_adj_rib_out(q)) == 0)
- self.assertTrue(len(q.get_global_rib()) == len(q.routes))
+ self.assertEqual(len(self.gobgp.get_adj_rib_out(q)), 0)
+ self.assertEqual(len(q.get_global_rib()), len(q.routes))
for q in self.ipv6s.itervalues():
- 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))
+ self.assertEqual(len(self.gobgp.get_adj_rib_out(q, rf='ipv6')), 0)
+ self.assertEqual(len(q.get_global_rib(rf='ipv6')), len(q.routes))
if __name__ == '__main__':
diff --git a/test/scenario_test/route_server_softreset_test.py b/test/scenario_test/route_server_softreset_test.py
index 90096be0..8e0fe374 100644
--- a/test/scenario_test/route_server_softreset_test.py
+++ b/test/scenario_test/route_server_softreset_test.py
@@ -107,14 +107,14 @@ class GoBGPTestBase(unittest.TestCase):
time.sleep(1)
num2 = g2.get_neighbor(g1)['state']['messages']['received'].get('update', 0)
- self.assertTrue((num + 1) == num2)
+ self.assertEqual((num + 1), num2)
g3.softreset(g1, type='out')
time.sleep(1)
num3 = g2.get_neighbor(g1)['state']['messages']['received'].get('update', 0)
- self.assertTrue(num2 == num3)
+ self.assertEqual(num2, num3)
def test_03_softresetin_test2(self):
g1 = self.gobgp
@@ -131,7 +131,7 @@ class GoBGPTestBase(unittest.TestCase):
num1 = g2.get_neighbor(g1)['state']['messages']['received'].get('update', 0)
- self.assertTrue(num == num1)
+ self.assertEqual(num, num1)
if __name__ == '__main__':
diff --git a/test/scenario_test/route_server_test.py b/test/scenario_test/route_server_test.py
index 149adfd2..58630881 100644
--- a/test/scenario_test/route_server_test.py
+++ b/test/scenario_test/route_server_test.py
@@ -88,7 +88,7 @@ class GoBGPTestBase(unittest.TestCase):
time.sleep(self.wait_per_retry)
continue
- self.assertTrue(len(local_rib) == (len(self.quaggas) - 1))
+ self.assertEqual(len(local_rib), (len(self.quaggas) - 1))
for c in self.quaggas.itervalues():
if rs_client != c:
@@ -113,7 +113,7 @@ class GoBGPTestBase(unittest.TestCase):
time.sleep(self.wait_per_retry)
continue
- self.assertTrue(len(global_rib) == len(self.quaggas))
+ self.assertEqual(len(global_rib), len(self.quaggas))
for c in self.quaggas.itervalues():
for r in c.routes:
@@ -137,7 +137,7 @@ class GoBGPTestBase(unittest.TestCase):
# check gobgp's global rib. when configured as route-server, global rib
# must be empty
def test_03_check_gobgp_global_rib(self):
- self.assertTrue(len(self.gobgp.get_global_rib()) == 0)
+ self.assertEqual(len(self.gobgp.get_global_rib()), 0)
# check routes are properly advertised to route-server-client
def test_04_check_rs_clients_rib(self):
diff --git a/test/scenario_test/route_server_test2.py b/test/scenario_test/route_server_test2.py
index 3bbfeada..82c0656f 100644
--- a/test/scenario_test/route_server_test2.py
+++ b/test/scenario_test/route_server_test2.py
@@ -81,8 +81,8 @@ class GoBGPTestBase(unittest.TestCase):
def test_03_check_neighbor_rib(self):
rib = self.gobgp.get_local_rib(self.clients['e2'])
- self.assertTrue(len(rib) == 1)
- self.assertTrue(len(rib[0]['paths']) == 1)
+ self.assertEqual(len(rib), 1)
+ self.assertEqual(len(rib[0]['paths']), 1)
path = rib[0]['paths'][0]
self.assertTrue(65001 not in path['aspath'])
@@ -90,9 +90,9 @@ class GoBGPTestBase(unittest.TestCase):
self.clients['g2'].local('gobgp global rib del 10.0.0.0/24')
time.sleep(1)
s = self.gobgp.get_neighbor(self.clients['g2'])['state']
- self.assertTrue(s.get('advertised', 0) == 1)
- self.assertTrue(s.get('accepted') == None) # means info['accepted'] == 0
- self.assertTrue(s.get('received') == None) # means info['received'] == 0
+ self.assertEqual(s.get('advertised', 0), 1)
+ self.assertEqual(s.get('accepted'), None) # means info['accepted'] == 0
+ self.assertEqual(s.get('received'), None) # means info['received'] == 0
if __name__ == '__main__':
diff --git a/test/scenario_test/vrf_neighbor_test.py b/test/scenario_test/vrf_neighbor_test.py
index f0c6de70..333b14f6 100644
--- a/test/scenario_test/vrf_neighbor_test.py
+++ b/test/scenario_test/vrf_neighbor_test.py
@@ -118,28 +118,28 @@ class GoBGPTestBase(unittest.TestCase):
time.sleep(1)
dst = self.g2.get_global_rib('10.0.0.0/24')
- self.assertTrue(len(dst) == 1)
- self.assertTrue(len(dst[0]['paths']) == 1)
+ self.assertEqual(len(dst), 1)
+ self.assertEqual(len(dst[0]['paths']), 1)
path = dst[0]['paths'][0]
- self.assertTrue([self.g4.asn, self.g1.asn] == path['aspath'])
+ self.assertEqual([self.g4.asn, self.g1.asn], path['aspath'])
dst = self.g3.get_global_rib('10.0.0.0/24')
- self.assertTrue(len(dst) == 0)
+ self.assertEqual(len(dst), 0)
dst = self.g4.get_global_rib(rf='vpnv4')
- self.assertTrue(len(dst) == 1)
- self.assertTrue(len(dst[0]['paths']) == 1)
+ self.assertEqual(len(dst), 1)
+ self.assertEqual(len(dst[0]['paths']), 1)
path = dst[0]['paths'][0]
- self.assertTrue([self.g1.asn] == path['aspath'])
+ self.assertEqual([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)
+ self.assertEqual(len(dst), 1)
+ self.assertEqual(len(dst[0]['paths']), 1)
path = dst[0]['paths'][0]
- self.assertTrue([self.g5.asn, self.g4.asn, self.g1.asn] == path['aspath'])
+ self.assertEqual([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)
+ self.assertEqual(len(dst), 0)
def test_03_inject_from_vrf_blue(self):
self.g3.local('gobgp global rib add 10.0.0.0/24')
@@ -147,25 +147,25 @@ class GoBGPTestBase(unittest.TestCase):
time.sleep(1)
dst = self.g2.get_global_rib('10.0.0.0/24')
- self.assertTrue(len(dst) == 1)
- self.assertTrue(len(dst[0]['paths']) == 1)
+ self.assertEqual(len(dst), 1)
+ self.assertEqual(len(dst[0]['paths']), 1)
path = dst[0]['paths'][0]
- self.assertTrue([self.g4.asn, self.g1.asn] == path['aspath'])
+ self.assertEqual([self.g4.asn, self.g1.asn], path['aspath'])
dst = self.g4.get_global_rib(rf='vpnv4')
- self.assertTrue(len(dst) == 2)
+ self.assertEqual(len(dst), 2)
dst = self.g6.get_global_rib('10.0.0.0/24')
- self.assertTrue(len(dst) == 1)
- self.assertTrue(len(dst[0]['paths']) == 1)
+ self.assertEqual(len(dst), 1)
+ self.assertEqual(len(dst[0]['paths']), 1)
path = dst[0]['paths'][0]
- self.assertTrue([self.g5.asn, self.g4.asn, self.g1.asn] == path['aspath'])
+ self.assertEqual([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)
+ self.assertEqual(len(dst), 1)
+ self.assertEqual(len(dst[0]['paths']), 1)
path = dst[0]['paths'][0]
- self.assertTrue([self.g5.asn, self.g4.asn, self.g3.asn] == path['aspath'])
+ self.assertEqual([self.g5.asn, self.g4.asn, self.g3.asn], path['aspath'])
if __name__ == '__main__':
diff --git a/test/scenario_test/zapi_v3_test.py b/test/scenario_test/zapi_v3_test.py
index 09c73329..b312e876 100644
--- a/test/scenario_test/zapi_v3_test.py
+++ b/test/scenario_test/zapi_v3_test.py
@@ -86,12 +86,12 @@ class GoBGPTestBase(unittest.TestCase):
time.sleep(2)
lines = self.g2.local("ip netns exec ns01 ip r", capture=True).split('\n')
- self.assertTrue(len(lines) == 1)
- self.assertTrue(lines[0].split(' ')[0] == '10.0.0.0/24')
+ self.assertEqual(len(lines), 1)
+ self.assertEqual(lines[0].split(' ')[0], '10.0.0.0/24')
lines = self.g2.local("ip netns exec ns02 ip r", capture=True).split('\n')
- self.assertTrue(len(lines) == 1)
- self.assertTrue(lines[0].split(' ')[0] == '20.0.0.0/24')
+ self.assertEqual(len(lines), 1)
+ self.assertEqual(lines[0].split(' ')[0], '20.0.0.0/24')
if __name__ == '__main__':