From: Martin Winter Date: Tue, 12 Sep 2017 23:36:38 +0000 (-0700) Subject: eigrp-topo1: Change Route verification to use json X-Git-Tag: frr-7.0.1~164^2~216 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=ee4523a2157ef1af7fb74f8c92e5e1f613e4cb44;p=mirror_frr.git eigrp-topo1: Change Route verification to use json Signed-off-by: Martin Winter --- diff --git a/tests/topotests/eigrp-topo1/r1/show_ip_route.json_ref b/tests/topotests/eigrp-topo1/r1/show_ip_route.json_ref new file mode 100644 index 000000000..d1216d7f3 --- /dev/null +++ b/tests/topotests/eigrp-topo1/r1/show_ip_route.json_ref @@ -0,0 +1,94 @@ +{ + "192.168.1.0/24":[ + { + "prefix":"192.168.1.0/24", + "protocol":"eigrp", + "distance":0, + "metric":0, + "nexthops":[ + { + "directlyConnected":true, + "interfaceName":"r1-eth0", + "active":true + } + ] + }, + { + "prefix":"192.168.1.0/24", + "protocol":"connected", + "selected":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"r1-eth0", + "active":true + } + ] + } + ], + "192.168.3.0/24":[ + { + "prefix":"192.168.3.0/24", + "protocol":"eigrp", + "selected":true, + "distance":0, + "metric":0, + "nexthops":[ + { + "fib":true, + "ip":"193.1.1.2", + "afi":"ipv4", + "interfaceName":"r1-eth1", + "active":true + } + ] + } + ], + "193.1.1.0/26":[ + { + "prefix":"193.1.1.0/26", + "protocol":"eigrp", + "distance":0, + "metric":0, + "nexthops":[ + { + "directlyConnected":true, + "interfaceName":"r1-eth1", + "active":true + } + ] + }, + { + "prefix":"193.1.1.0/26", + "protocol":"connected", + "selected":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"r1-eth1", + "active":true + } + ] + } + ], + "193.1.2.0/24":[ + { + "prefix":"193.1.2.0/24", + "protocol":"eigrp", + "selected":true, + "distance":0, + "metric":0, + "nexthops":[ + { + "fib":true, + "ip":"193.1.1.2", + "afi":"ipv4", + "interfaceName":"r1-eth1", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/eigrp-topo1/r1/show_ip_route.ref b/tests/topotests/eigrp-topo1/r1/show_ip_route.ref deleted file mode 100644 index 7f7a2fff9..000000000 --- a/tests/topotests/eigrp-topo1/r1/show_ip_route.ref +++ /dev/null @@ -1,11 +0,0 @@ -Codes: K - kernel route, C - connected, S - static, R - RIP, - O - OSPF, I - IS-IS, B - BGP, P - PIM, E - EIGRP, N - NHRP, - T - Table, v - VNC, V - VNC-Direct, A - Babel, - > - selected route, * - FIB route - -E 192.168.1.0/24 [0/0] is directly connected, r1-eth0 -C>* 192.168.1.0/24 is directly connected, r1-eth0 -E>* 192.168.3.0/24 [0/0] via 193.1.1.2, r1-eth1 -E 193.1.1.0/26 [0/0] is directly connected, r1-eth1 -C>* 193.1.1.0/26 is directly connected, r1-eth1 -E>* 193.1.2.0/24 [0/0] via 193.1.1.2, r1-eth1 diff --git a/tests/topotests/eigrp-topo1/r2/show_ip_route.json_ref b/tests/topotests/eigrp-topo1/r2/show_ip_route.json_ref new file mode 100644 index 000000000..ea1d86b76 --- /dev/null +++ b/tests/topotests/eigrp-topo1/r2/show_ip_route.json_ref @@ -0,0 +1,94 @@ +{ + "192.168.1.0/24":[ + { + "prefix":"192.168.1.0/24", + "protocol":"eigrp", + "selected":true, + "distance":0, + "metric":0, + "nexthops":[ + { + "fib":true, + "ip":"193.1.1.1", + "afi":"ipv4", + "interfaceName":"r2-eth0", + "active":true + } + ] + } + ], + "192.168.3.0/24":[ + { + "prefix":"192.168.3.0/24", + "protocol":"eigrp", + "selected":true, + "distance":0, + "metric":0, + "nexthops":[ + { + "fib":true, + "ip":"193.1.2.2", + "afi":"ipv4", + "interfaceName":"r2-eth1", + "active":true + } + ] + } + ], + "193.1.1.0/26":[ + { + "prefix":"193.1.1.0/26", + "protocol":"eigrp", + "distance":0, + "metric":0, + "nexthops":[ + { + "directlyConnected":true, + "interfaceName":"r2-eth0", + "active":true + } + ] + }, + { + "prefix":"193.1.1.0/26", + "protocol":"connected", + "selected":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"r2-eth0", + "active":true + } + ] + } + ], + "193.1.2.0/24":[ + { + "prefix":"193.1.2.0/24", + "protocol":"eigrp", + "distance":0, + "metric":0, + "nexthops":[ + { + "directlyConnected":true, + "interfaceName":"r2-eth1", + "active":true + } + ] + }, + { + "prefix":"193.1.2.0/24", + "protocol":"connected", + "selected":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"r2-eth1", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/eigrp-topo1/r2/show_ip_route.ref b/tests/topotests/eigrp-topo1/r2/show_ip_route.ref deleted file mode 100644 index 13ef7c618..000000000 --- a/tests/topotests/eigrp-topo1/r2/show_ip_route.ref +++ /dev/null @@ -1,11 +0,0 @@ -Codes: K - kernel route, C - connected, S - static, R - RIP, - O - OSPF, I - IS-IS, B - BGP, P - PIM, E - EIGRP, N - NHRP, - T - Table, v - VNC, V - VNC-Direct, A - Babel, - > - selected route, * - FIB route - -E>* 192.168.1.0/24 [0/0] via 193.1.1.1, r2-eth0 -E>* 192.168.3.0/24 [0/0] via 193.1.2.2, r2-eth1 -E 193.1.1.0/26 [0/0] is directly connected, r2-eth0 -C>* 193.1.1.0/26 is directly connected, r2-eth0 -E 193.1.2.0/24 [0/0] is directly connected, r2-eth1 -C>* 193.1.2.0/24 is directly connected, r2-eth1 diff --git a/tests/topotests/eigrp-topo1/r3/show_ip_route.json_ref b/tests/topotests/eigrp-topo1/r3/show_ip_route.json_ref new file mode 100644 index 000000000..076e4b051 --- /dev/null +++ b/tests/topotests/eigrp-topo1/r3/show_ip_route.json_ref @@ -0,0 +1,112 @@ +{ + "192.168.1.0/24":[ + { + "prefix":"192.168.1.0/24", + "protocol":"eigrp", + "selected":true, + "distance":0, + "metric":0, + "nexthops":[ + { + "fib":true, + "ip":"193.1.2.1", + "afi":"ipv4", + "interfaceName":"r3-eth1", + "active":true + } + ] + } + ], + "192.168.2.0/24":[ + { + "prefix":"192.168.2.0/24", + "protocol":"static", + "selected":true, + "distance":1, + "metric":0, + "nexthops":[ + { + "fib":true, + "ip":"192.168.3.10", + "afi":"ipv4", + "interfaceName":"r3-eth0", + "active":true + } + ] + } + ], + "192.168.3.0/24":[ + { + "prefix":"192.168.3.0/24", + "protocol":"eigrp", + "distance":0, + "metric":0, + "nexthops":[ + { + "directlyConnected":true, + "interfaceName":"r3-eth0", + "active":true + } + ] + }, + { + "prefix":"192.168.3.0/24", + "protocol":"connected", + "selected":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"r3-eth0", + "active":true + } + ] + } + ], + "193.1.1.0/26":[ + { + "prefix":"193.1.1.0/26", + "protocol":"eigrp", + "selected":true, + "distance":0, + "metric":0, + "nexthops":[ + { + "fib":true, + "ip":"193.1.2.1", + "afi":"ipv4", + "interfaceName":"r3-eth1", + "active":true + } + ] + } + ], + "193.1.2.0/24":[ + { + "prefix":"193.1.2.0/24", + "protocol":"eigrp", + "distance":0, + "metric":0, + "nexthops":[ + { + "directlyConnected":true, + "interfaceName":"r3-eth1", + "active":true + } + ] + }, + { + "prefix":"193.1.2.0/24", + "protocol":"connected", + "selected":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"r3-eth1", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/eigrp-topo1/r3/show_ip_route.ref b/tests/topotests/eigrp-topo1/r3/show_ip_route.ref deleted file mode 100644 index c12965c1a..000000000 --- a/tests/topotests/eigrp-topo1/r3/show_ip_route.ref +++ /dev/null @@ -1,12 +0,0 @@ -Codes: K - kernel route, C - connected, S - static, R - RIP, - O - OSPF, I - IS-IS, B - BGP, P - PIM, E - EIGRP, N - NHRP, - T - Table, v - VNC, V - VNC-Direct, A - Babel, - > - selected route, * - FIB route - -E>* 192.168.1.0/24 [0/0] via 193.1.2.1, r3-eth1 -S>* 192.168.2.0/24 [1/0] via 192.168.3.10, r3-eth0 -E 192.168.3.0/24 [0/0] is directly connected, r3-eth0 -C>* 192.168.3.0/24 is directly connected, r3-eth0 -E>* 193.1.1.0/26 [0/0] via 193.1.2.1, r3-eth1 -E 193.1.2.0/24 [0/0] is directly connected, r3-eth1 -C>* 193.1.2.0/24 is directly connected, r3-eth1 diff --git a/tests/topotests/eigrp-topo1/test_eigrp_topo1.py b/tests/topotests/eigrp-topo1/test_eigrp_topo1.py index e50261b07..aff28b123 100755 --- a/tests/topotests/eigrp-topo1/test_eigrp_topo1.py +++ b/tests/topotests/eigrp-topo1/test_eigrp_topo1.py @@ -31,6 +31,7 @@ import os import re import sys import pytest +import json # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) @@ -166,6 +167,42 @@ def test_eigrp_routes(): assert failures == 0, 'SHOW IP EIGRP failed for router {}:\n{}'.format(router.name, diff) +# def test_zebra_ipv4_routingTable(): +# "Test 'show ip route'" + +# tgen = get_topogen() +# # Don't run this test if we have any failure. +# if tgen.routers_have_failure(): +# pytest.skip(tgen.errors) + +# # Verify OSPFv2 Routing Table +# logger.info("Verifying Zebra IPv4 Routing Table") + +# failures = 0 +# router_list = tgen.routers().values() +# for router in router_list: +# refTableFile = '{}/{}/show_ip_route.ref'.format(CWD, router.name) + +# # Read expected result from file +# expected = open(refTableFile).read().rstrip() + +# # Actual output from router +# actual = router.vtysh_cmd('show ip route').rstrip() + +# # Generate Diff +# diff = topotest.difflines(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: +# failures += 1 +# else: +# logger.info('{} ok'.format(router.name)) + +# assert failures == 0, 'Zebra IPv4 Routing Table verification failed for router {}:\n{}'.format(router.name, diff) + + def test_zebra_ipv4_routingTable(): "Test 'show ip route'" @@ -174,32 +211,27 @@ def test_zebra_ipv4_routingTable(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - # Verify OSPFv3 Routing Table - logger.info("Verifying Zebra IPv4 Routing Table") - failures = 0 router_list = tgen.routers().values() for router in router_list: - refTableFile = '{}/{}/show_ip_route.ref'.format(CWD, router.name) + output = router.vtysh_cmd('show ip route json', isjson=True) + refTableFile = '{}/{}/show_ip_route.json_ref'.format(CWD, router.name) + expected = json.loads(open(refTableFile).read()) - # Read expected result from file - expected = open(refTableFile).read().rstrip() - - # Actual output from router - actual = router.vtysh_cmd('show ip route').rstrip() + # diff = topotest.json_cmp(output, expected) - # Generate Diff - diff = topotest.difflines(actual, expected, - title1="actual Zebra IPv4 routing table", - title2="expected Zebra IPv4 routing table") + assertmsg = 'Zebra IPv4 Routing Table verification failed for router {}'.format(router.name) + assert topotest.json_cmp(output, expected) is None, assertmsg - # Empty string if it matches, otherwise diff contains unified diff - if diff: - failures += 1 - else: - logger.info('{} ok'.format(router.name)) + # # Empty string if it matches, otherwise diff contains unified diff + # if diff: + # logger.info('{} NOT ok'.format(router.name)) + # print("diff = %s" % str(diff)) + # failures += 1 + # else: + # logger.info('{} ok'.format(router.name)) - assert failures == 0, 'Zebra IPv4 Routing Table verification failed for router {}:\n{}'.format(router.name, diff) + # assert failures == 0, 'Zebra IPv4 Routing Table verification failed for router {}:\n{}'.format(router.name, diff) def test_shutdown_check_stderr():