summaryrefslogtreecommitdiff
path: root/tests/topotests/lib/common_check.py
diff options
context:
space:
mode:
authorPhilippe Guibert <philippe.guibert@6wind.com>2024-06-04 18:50:26 +0200
committerPhilippe Guibert <philippe.guibert@6wind.com>2024-06-11 10:01:56 +0200
commitd0bac2796b404e3b206313c9003b770a50b45cdf (patch)
tree7060f6f434df2d75e5776f97eb2b65753c8bf7d5 /tests/topotests/lib/common_check.py
parenta6b1d38d7f038c335143d963b7b7a13377ef5f22 (diff)
topotests: add bgp duplicate nexthop test
Add a topotest that ensures that when addpath is enabled and two paths with same nexthop are received, they are sent to ZEBRA which detects 'duplicate nexthop'. Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
Diffstat (limited to 'tests/topotests/lib/common_check.py')
-rw-r--r--tests/topotests/lib/common_check.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/topotests/lib/common_check.py b/tests/topotests/lib/common_check.py
new file mode 100644
index 0000000000..be3241fd20
--- /dev/null
+++ b/tests/topotests/lib/common_check.py
@@ -0,0 +1,48 @@
+#!/usr/bin/env python
+# SPDX-License-Identifier: ISC
+#
+# common_check.py
+#
+# Copyright 2024 6WIND S.A.
+
+#
+import json
+from lib import topotest
+
+
+def ip_check_path_selection(router, ipaddr_str, expected, vrf_name=None):
+ if vrf_name:
+ cmdstr = f'show ip route vrf {vrf_name} {ipaddr_str} json'
+ else:
+ cmdstr = f'show ip route {ipaddr_str} json'
+ try:
+ output = json.loads(router.vtysh_cmd(cmdstr))
+ except:
+ output = {}
+
+ ret = topotest.json_cmp(output, expected)
+ if ret is None:
+ num_nh_expected = len(expected[ipaddr_str][0]["nexthops"])
+ num_nh_observed = len(output[ipaddr_str][0]["nexthops"])
+ if num_nh_expected == num_nh_observed:
+ return ret
+ return "{}, prefix {} does not have the correct number of nexthops : observed {}, expected {}".format(
+ router.name, ipaddr_str, num_nh_observed, num_nh_expected
+ )
+ return ret
+
+
+def iproute2_check_path_selection(router, ipaddr_str, expected, vrf_name=None):
+ if not topotest.iproute2_is_json_capable():
+ return None
+
+ if vrf_name:
+ cmdstr = f'ip -json route show vrf {vrf_name} {ipaddr_str}'
+ else:
+ cmdstr = f'ip -json route show {ipaddr_str}'
+ try:
+ output = json.loads(cmdstr)
+ except:
+ output = []
+
+ return topotest.json_cmp(output, expected)