topotests: fix bgp_vpnv4_noretain

Fix the following issues:
- two tests are done in one function. Dispatch the tests in two
functions to help the test debug.
- the first test passes even if a third prefix is not filtered. Match
the exact to avoid false positive.
- the expected values contains variable like version. Do no check
variable values.

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
This commit is contained in:
Louis Scalbert 2023-01-23 18:03:58 +01:00
parent de2e2d5ef0
commit 6c13bd5744
3 changed files with 39 additions and 22 deletions

View file

@ -1,7 +1,6 @@
{ {
"vrfId":0, "vrfId":0,
"vrfName":"default", "vrfName":"default",
"tableVersion":1,
"routerId":"1.1.1.1", "routerId":"1.1.1.1",
"defaultLocPrf":100, "defaultLocPrf":100,
"localAS":65500, "localAS":65500,
@ -17,7 +16,6 @@
"prefix":"10.201.0.0", "prefix":"10.201.0.0",
"prefixLen":24, "prefixLen":24,
"network":"10.201.0.0\/24", "network":"10.201.0.0\/24",
"version":1,
"metric":0, "metric":0,
"weight":32768, "weight":32768,
"peerId":"(unspec)", "peerId":"(unspec)",
@ -28,6 +26,7 @@
"nexthops":[ "nexthops":[
{ {
"ip":"0.0.0.0", "ip":"0.0.0.0",
"hostname":"r1",
"afi":"ipv4", "afi":"ipv4",
"used":true "used":true
} }
@ -45,7 +44,6 @@
"prefix":"10.200.0.0", "prefix":"10.200.0.0",
"prefixLen":24, "prefixLen":24,
"network":"10.200.0.0\/24", "network":"10.200.0.0\/24",
"version":1,
"metric":0, "metric":0,
"locPrf":100, "locPrf":100,
"weight":0, "weight":0,
@ -55,6 +53,7 @@
"nexthops":[ "nexthops":[
{ {
"ip":"10.125.0.2", "ip":"10.125.0.2",
"hostname":"r2",
"afi":"ipv4", "afi":"ipv4",
"used":true "used":true
} }

View file

@ -1,7 +1,6 @@
{ {
"vrfId":0, "vrfId":0,
"vrfName":"default", "vrfName":"default",
"tableVersion":1,
"routerId":"1.1.1.1", "routerId":"1.1.1.1",
"defaultLocPrf":100, "defaultLocPrf":100,
"localAS":65500, "localAS":65500,
@ -17,7 +16,6 @@
"prefix":"10.201.0.0", "prefix":"10.201.0.0",
"prefixLen":24, "prefixLen":24,
"network":"10.201.0.0\/24", "network":"10.201.0.0\/24",
"version":1,
"metric":0, "metric":0,
"weight":32768, "weight":32768,
"peerId":"(unspec)", "peerId":"(unspec)",
@ -28,6 +26,7 @@
"nexthops":[ "nexthops":[
{ {
"ip":"0.0.0.0", "ip":"0.0.0.0",
"hostname":"r1",
"afi":"ipv4", "afi":"ipv4",
"used":true "used":true
} }
@ -45,7 +44,6 @@
"prefix":"10.200.0.0", "prefix":"10.200.0.0",
"prefixLen":24, "prefixLen":24,
"network":"10.200.0.0\/24", "network":"10.200.0.0\/24",
"version":1,
"metric":0, "metric":0,
"locPrf":100, "locPrf":100,
"weight":0, "weight":0,
@ -55,6 +53,7 @@
"nexthops":[ "nexthops":[
{ {
"ip":"10.125.0.2", "ip":"10.125.0.2",
"hostname":"r2",
"afi":"ipv4", "afi":"ipv4",
"used":true "used":true
} }
@ -72,7 +71,6 @@
"prefix":"10.210.0.0", "prefix":"10.210.0.0",
"prefixLen":24, "prefixLen":24,
"network":"10.210.0.0\/24", "network":"10.210.0.0\/24",
"version":1,
"metric":0, "metric":0,
"locPrf":100, "locPrf":100,
"weight":0, "weight":0,
@ -82,6 +80,7 @@
"nexthops":[ "nexthops":[
{ {
"ip":"10.125.0.2", "ip":"10.125.0.2",
"hostname":"r2",
"afi":"ipv4", "afi":"ipv4",
"used":true "used":true
} }

View file

@ -133,27 +133,37 @@ def teardown_module(_mod):
tgen.stop_topology() tgen.stop_topology()
def test_protocols_convergence(): def router_json_cmp_exact_filter(router, cmd, expected):
# filter out tableVersion, version and nhVrfID
output = router.cmd('vtysh -c "{}" | grep -v ersion | grep -v nhVrfId'.format(cmd))
logger.info("{}: {}\n{}".format(router.name, cmd, output))
json_output = json.loads(output)
return topotest.json_cmp(json_output, expected, exact=True)
def test_bgp_no_retain():
""" """
Assert that all protocols have converged Check bgp no retain route-target all on r1
statuses as they depend on it.
""" """
tgen = get_topogen() tgen = get_topogen()
if tgen.routers_have_failure(): if tgen.routers_have_failure():
pytest.skip(tgen.errors) pytest.skip(tgen.errors)
# Check IPv4 VPN routing tables on r1 # Check IPv4 VPN routing tables on r1
logger.info("Checking IPv4 routes for convergence on r1") logger.info("Checking VPNv4 routes for convergence on r1")
router = tgen.gears['r1'] router = tgen.gears["r1"]
json_file = "{}/{}/ipv4_vpn_routes.json".format(CWD, router.name) json_file = "{}/{}/ipv4_vpn_routes.json".format(CWD, router.name)
if not os.path.isfile(json_file): if not os.path.isfile(json_file):
logger.info("skipping file {}".format(json_file)) logger.info("skipping file {}".format(json_file))
assert 0, 'ipv4_vpn_routes.json file not found' assert 0, "{} file not found".format(json_file)
return return
expected = json.loads(open(json_file).read()) expected = json.loads(open(json_file).read())
test_func = partial( test_func = partial(
topotest.router_json_cmp, router_json_cmp_exact_filter,
router, router,
"show bgp ipv4 vpn json", "show bgp ipv4 vpn json",
expected, expected,
@ -162,23 +172,31 @@ def test_protocols_convergence():
assertmsg = '"{}" JSON output mismatches'.format(router.name) assertmsg = '"{}" JSON output mismatches'.format(router.name)
assert result is None, assertmsg assert result is None, assertmsg
# Check BGP IPv4 routing tables after unsetting no retain flag
logger.info("Checking BGP IPv4 routes for convergence on r2") def test_bgp_retain():
router = tgen.gears['r1'] """
router.vtysh_cmd("configure\nrouter bgp 65500\naddress-family ipv4 vpn\nbgp retain route-target all\n") Apply and check bgp retain route-target all on r1
"""
tgen = get_topogen()
if tgen.routers_have_failure():
pytest.skip(tgen.errors)
# Check IPv4 VPN routing tables on r1 # Check IPv4 VPN routing tables on r1
logger.info("Checking IPv4 routes for convergence on r1") logger.info("Checking VPNv4 routes on r1 after bgp no retain")
router = tgen.gears['r1'] router = tgen.gears["r1"]
router.vtysh_cmd(
"configure\nrouter bgp 65500\naddress-family ipv4 vpn\nbgp retain route-target all\n"
)
json_file = "{}/{}/ipv4_vpn_routes_unfiltered.json".format(CWD, router.name) json_file = "{}/{}/ipv4_vpn_routes_unfiltered.json".format(CWD, router.name)
if not os.path.isfile(json_file): if not os.path.isfile(json_file):
logger.info("skipping file {}".format(json_file)) logger.info("skipping file {}".format(json_file))
assert 0, 'ipv4_vpn_routes_unfiltered.json file not found' assert 0, "{} file not found".format(json_file)
return return
expected = json.loads(open(json_file).read()) expected = json.loads(open(json_file).read())
test_func = partial( test_func = partial(
topotest.router_json_cmp, router_json_cmp_exact_filter,
router, router,
"show bgp ipv4 vpn json", "show bgp ipv4 vpn json",
expected, expected,
@ -187,6 +205,7 @@ def test_protocols_convergence():
assertmsg = '"{}" JSON output mismatches'.format(router.name) assertmsg = '"{}" JSON output mismatches'.format(router.name)
assert result is None, assertmsg assert result is None, assertmsg
def test_memory_leak(): def test_memory_leak():
"Run the memory leak test and report results." "Run the memory leak test and report results."
tgen = get_topogen() tgen = get_topogen()