mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-14 10:09:17 +00:00
tests: Use run_and_expect() for rip_topo1
Avoid checking once and failing immediately. Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
This commit is contained in:
parent
5b28833d38
commit
3349754a80
@ -19,6 +19,7 @@ import re
|
|||||||
import sys
|
import sys
|
||||||
import pytest
|
import pytest
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
import functools
|
||||||
|
|
||||||
|
|
||||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||||
@ -258,58 +259,43 @@ def test_zebra_ipv4_routingTable():
|
|||||||
global fatal_error
|
global fatal_error
|
||||||
net = get_topogen().net
|
net = get_topogen().net
|
||||||
|
|
||||||
|
def _verify_ip_route(expected):
|
||||||
|
# Actual output from router
|
||||||
|
actual = (
|
||||||
|
net["r%s" % i]
|
||||||
|
.cmd('vtysh -c "show ip route" 2> /dev/null | grep "^R"')
|
||||||
|
.rstrip()
|
||||||
|
)
|
||||||
|
# Drop timers on end of line
|
||||||
|
actual = re.sub(r", [0-2][0-9]:[0-5][0-9]:[0-5][0-9]", "", actual)
|
||||||
|
# Fix newlines (make them all the same)
|
||||||
|
actual = ("\n".join(actual.splitlines()) + "\n").splitlines(1)
|
||||||
|
|
||||||
|
return topotest.get_textdiff(
|
||||||
|
actual,
|
||||||
|
expected,
|
||||||
|
title1="actual Zebra IPv4 routing table",
|
||||||
|
title2="expected Zebra IPv4 routing table",
|
||||||
|
)
|
||||||
|
|
||||||
# Skip if previous fatal error condition is raised
|
# Skip if previous fatal error condition is raised
|
||||||
if fatal_error != "":
|
if fatal_error != "":
|
||||||
pytest.skip(fatal_error)
|
pytest.skip(fatal_error)
|
||||||
|
|
||||||
thisDir = os.path.dirname(os.path.realpath(__file__))
|
thisDir = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
|
||||||
# Verify OSPFv3 Routing Table
|
|
||||||
print("\n\n** Verifing Zebra IPv4 Routing Table")
|
print("\n\n** Verifing Zebra IPv4 Routing Table")
|
||||||
print("******************************************\n")
|
print("******************************************\n")
|
||||||
failures = 0
|
|
||||||
for i in range(1, 4):
|
for i in range(1, 4):
|
||||||
refTableFile = "%s/r%s/show_ip_route.ref" % (thisDir, i)
|
refTableFile = "%s/r%s/show_ip_route.ref" % (thisDir, i)
|
||||||
if os.path.isfile(refTableFile):
|
if os.path.isfile(refTableFile):
|
||||||
# Read expected result from file
|
|
||||||
expected = open(refTableFile).read().rstrip()
|
expected = open(refTableFile).read().rstrip()
|
||||||
# Fix newlines (make them all the same)
|
# Fix newlines (make them all the same)
|
||||||
expected = ("\n".join(expected.splitlines()) + "\n").splitlines(1)
|
expected = ("\n".join(expected.splitlines()) + "\n").splitlines(1)
|
||||||
|
|
||||||
# Actual output from router
|
test_func = functools.partial(_verify_ip_route, expected)
|
||||||
actual = (
|
success, _ = topotest.run_and_expect(test_func, "", count=30, wait=1)
|
||||||
net["r%s" % i]
|
assert success, "Failed verifying IPv4 routes for r{}".format(i)
|
||||||
.cmd('vtysh -c "show ip route" 2> /dev/null | grep "^R"')
|
|
||||||
.rstrip()
|
|
||||||
)
|
|
||||||
# Drop timers on end of line
|
|
||||||
actual = re.sub(r", [0-2][0-9]:[0-5][0-9]:[0-5][0-9]", "", actual)
|
|
||||||
# Fix newlines (make them all the same)
|
|
||||||
actual = ("\n".join(actual.splitlines()) + "\n").splitlines(1)
|
|
||||||
|
|
||||||
# Generate Diff
|
|
||||||
diff = topotest.get_textdiff(
|
|
||||||
actual,
|
|
||||||
expected,
|
|
||||||
title1="actual Zebra IPv4 routing table",
|
|
||||||
title2="expected Zebra IPv4 routing table",
|
|
||||||
)
|
|
||||||
|
|
||||||
# Empty string if it matches, otherwise diff contains unified diff
|
|
||||||
if diff:
|
|
||||||
sys.stderr.write(
|
|
||||||
"r%s failed Zebra IPv4 Routing Table Check:\n%s\n" % (i, diff)
|
|
||||||
)
|
|
||||||
failures += 1
|
|
||||||
else:
|
|
||||||
print("r%s ok" % i)
|
|
||||||
|
|
||||||
assert (
|
|
||||||
failures == 0
|
|
||||||
), "Zebra IPv4 Routing Table verification failed for router r%s:\n%s" % (
|
|
||||||
i,
|
|
||||||
diff,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Make sure that all daemons are still running
|
# Make sure that all daemons are still running
|
||||||
for i in range(1, 4):
|
for i in range(1, 4):
|
||||||
|
Loading…
Reference in New Issue
Block a user