mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-07-09 20:15:08 +00:00
ospf-topo1: use new output compare functions
Remove duplicated code and use the new output compare code from lib. Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
This commit is contained in:
parent
9e2201b8aa
commit
38b291bca0
@ -110,17 +110,6 @@ def teardown_module(mod):
|
|||||||
tgen = get_topogen()
|
tgen = get_topogen()
|
||||||
tgen.stop_topology()
|
tgen.stop_topology()
|
||||||
|
|
||||||
# Shared test function to validate expected output.
|
|
||||||
def compare_show_ip_ospf(rname, expected):
|
|
||||||
"""
|
|
||||||
Calls 'show ip ospf route' for router `rname` and compare the obtained
|
|
||||||
result with the expected output.
|
|
||||||
"""
|
|
||||||
tgen = get_topogen()
|
|
||||||
current = tgen.gears[rname].vtysh_cmd('show ip ospf route')
|
|
||||||
return topotest.difflines(current, expected,
|
|
||||||
title1="Current output",
|
|
||||||
title2="Expected output")
|
|
||||||
|
|
||||||
def compare_show_ipv6_ospf6(rname, expected):
|
def compare_show_ipv6_ospf6(rname, expected):
|
||||||
"""
|
"""
|
||||||
@ -130,11 +119,6 @@ def compare_show_ipv6_ospf6(rname, expected):
|
|||||||
tgen = get_topogen()
|
tgen = get_topogen()
|
||||||
current = tgen.gears[rname].vtysh_cmd('show ipv6 ospf6 route')
|
current = tgen.gears[rname].vtysh_cmd('show ipv6 ospf6 route')
|
||||||
|
|
||||||
# This output has space formating and random IPv6 link addresses, we have to
|
|
||||||
# remove them first before testing.
|
|
||||||
current = topotest.normalize_text(current)
|
|
||||||
expected = topotest.normalize_text(expected)
|
|
||||||
|
|
||||||
# Remove the link addresses
|
# Remove the link addresses
|
||||||
current = re.sub(r'fe80::[^ ]+', 'fe80::xxxx:xxxx:xxxx:xxxx', current)
|
current = re.sub(r'fe80::[^ ]+', 'fe80::xxxx:xxxx:xxxx:xxxx', current)
|
||||||
expected = re.sub(r'fe80::[^ ]+', 'fe80::xxxx:xxxx:xxxx:xxxx', expected)
|
expected = re.sub(r'fe80::[^ ]+', 'fe80::xxxx:xxxx:xxxx:xxxx', expected)
|
||||||
@ -143,7 +127,8 @@ def compare_show_ipv6_ospf6(rname, expected):
|
|||||||
current = re.sub(r'\d+:\d{2}:\d{2}', '', current)
|
current = re.sub(r'\d+:\d{2}:\d{2}', '', current)
|
||||||
expected = re.sub(r'\d+:\d{2}:\d{2}', '', expected)
|
expected = re.sub(r'\d+:\d{2}:\d{2}', '', expected)
|
||||||
|
|
||||||
return topotest.difflines(current, expected,
|
return topotest.difflines(topotest.normalize_text(current),
|
||||||
|
topotest.normalize_text(expected),
|
||||||
title1="Current output",
|
title1="Current output",
|
||||||
title2="Expected output")
|
title2="Expected output")
|
||||||
|
|
||||||
@ -153,19 +138,18 @@ def test_ospf_convergence():
|
|||||||
if tgen.routers_have_failure():
|
if tgen.routers_have_failure():
|
||||||
pytest.skip('skipped because of router(s) failure')
|
pytest.skip('skipped because of router(s) failure')
|
||||||
|
|
||||||
for rnum in range(1, 5):
|
for router, rnode in tgen.routers().iteritems():
|
||||||
router = 'r{}'.format(rnum)
|
|
||||||
|
|
||||||
logger.info('Waiting for router "%s" convergence', router)
|
logger.info('Waiting for router "%s" convergence', router)
|
||||||
|
|
||||||
# Load expected results from the command
|
# Load expected results from the command
|
||||||
reffile = os.path.join(CWD, '{}/ospfroute.txt'.format(router))
|
reffile = os.path.join(CWD, '{}/ospfroute.txt'.format(router))
|
||||||
expected = open(reffile).read()
|
expected = open(reffile).read()
|
||||||
|
|
||||||
# Run test function until we get an result. Wait at most 60 seconds.
|
# Run test function until we get an result. Wait at most 80 seconds.
|
||||||
test_func = partial(compare_show_ip_ospf, router, expected)
|
test_func = partial(
|
||||||
|
topotest.router_output_cmp, rnode, 'show ip ospf route', expected)
|
||||||
result, diff = topotest.run_and_expect(test_func, '',
|
result, diff = topotest.run_and_expect(test_func, '',
|
||||||
count=25, wait=3)
|
count=160, wait=0.5)
|
||||||
assert result, 'OSPF did not converge on {}:\n{}'.format(router, diff)
|
assert result, 'OSPF did not converge on {}:\n{}'.format(router, diff)
|
||||||
|
|
||||||
def test_ospf_kernel_route():
|
def test_ospf_kernel_route():
|
||||||
@ -340,17 +324,17 @@ def test_ospf_link_down():
|
|||||||
router3.peer_link_enable('r3-eth0', False)
|
router3.peer_link_enable('r3-eth0', False)
|
||||||
|
|
||||||
# Expect convergence on all routers
|
# Expect convergence on all routers
|
||||||
for rnum in range(1, 5):
|
for router, rnode in tgen.routers().iteritems():
|
||||||
router = 'r{}'.format(rnum)
|
|
||||||
logger.info('Waiting for router "%s" convergence after link failure', router)
|
logger.info('Waiting for router "%s" convergence after link failure', router)
|
||||||
# Load expected results from the command
|
# Load expected results from the command
|
||||||
reffile = os.path.join(CWD, '{}/ospfroute_down.txt'.format(router))
|
reffile = os.path.join(CWD, '{}/ospfroute_down.txt'.format(router))
|
||||||
expected = open(reffile).read()
|
expected = open(reffile).read()
|
||||||
|
|
||||||
# Run test function until we get an result. Wait at most 60 seconds.
|
# Run test function until we get an result. Wait at most 80 seconds.
|
||||||
test_func = partial(compare_show_ip_ospf, router, expected)
|
test_func = partial(
|
||||||
|
topotest.router_output_cmp, rnode, 'show ip ospf route', expected)
|
||||||
result, diff = topotest.run_and_expect(test_func, '',
|
result, diff = topotest.run_and_expect(test_func, '',
|
||||||
count=25, wait=3)
|
count=160, wait=0.5)
|
||||||
assert result, 'OSPF did not converge on {}:\n{}'.format(router, diff)
|
assert result, 'OSPF did not converge on {}:\n{}'.format(router, diff)
|
||||||
|
|
||||||
def test_ospf_link_down_kernel_route():
|
def test_ospf_link_down_kernel_route():
|
||||||
|
Loading…
Reference in New Issue
Block a user