tests: Change bgp_gr_retained_routes to use json output of "ip route"

Depending on ip_route and kernel, the output might include a nhid
which causes the test to fail with a strict text output check.
Change to json output to avoid the issue

Signed-off-by: Martin Winter <mwinter@opensourcerouting.org>
This commit is contained in:
Martin Winter 2023-02-18 02:16:26 +01:00
parent 5ef2911d23
commit 6a62adabb3
No known key found for this signature in database
GPG Key ID: 05A4ECF8C0102306

View File

@ -83,18 +83,9 @@ def test_bgp_gr_restart_retain_routes():
return topotest.json_cmp(output, expected)
def _bgp_check_kernel_retained_routes():
output = (
r2.cmd("ip route show 172.16.255.1/32 proto bgp dev r2-eth0")
.replace("\n", "")
.rstrip()
)
expected = "172.16.255.1 via 192.168.255.1 metric 20"
diff = topotest.get_textdiff(
output, expected, "Actual IP Routing Table", "Expected IP RoutingTable"
)
if diff:
return False
return True
output = json.loads(r2.cmd("ip -j route show 172.16.255.1/32 proto bgp dev r2-eth0"))
expected = [{"dst":"172.16.255.1","gateway":"192.168.255.1","metric":20}]
return topotest.json_cmp(output, expected)
step("Initial BGP converge")
test_func = functools.partial(_bgp_converge)
@ -110,7 +101,7 @@ def test_bgp_gr_restart_retain_routes():
assert result is None, "Failed to see BGP retained routes on R2"
step("Check if routes (Kernel) are retained at R2")
assert _bgp_check_kernel_retained_routes() == True
assert _bgp_check_kernel_retained_routes() is None, "Failed to retain BGP routes in kernel on R2"
if __name__ == "__main__":