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

View file

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

View file

@ -133,27 +133,37 @@ def teardown_module(_mod):
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
statuses as they depend on it.
Check bgp no 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
logger.info("Checking IPv4 routes for convergence on r1")
router = tgen.gears['r1']
logger.info("Checking VPNv4 routes for convergence on r1")
router = tgen.gears["r1"]
json_file = "{}/{}/ipv4_vpn_routes.json".format(CWD, router.name)
if not os.path.isfile(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
expected = json.loads(open(json_file).read())
test_func = partial(
topotest.router_json_cmp,
router_json_cmp_exact_filter,
router,
"show bgp ipv4 vpn json",
expected,
@ -162,23 +172,31 @@ def test_protocols_convergence():
assertmsg = '"{}" JSON output mismatches'.format(router.name)
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")
router = tgen.gears['r1']
router.vtysh_cmd("configure\nrouter bgp 65500\naddress-family ipv4 vpn\nbgp retain route-target all\n")
def test_bgp_retain():
"""
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
logger.info("Checking IPv4 routes for convergence on r1")
router = tgen.gears['r1']
logger.info("Checking VPNv4 routes on r1 after bgp no retain")
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)
if not os.path.isfile(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
expected = json.loads(open(json_file).read())
test_func = partial(
topotest.router_json_cmp,
router_json_cmp_exact_filter,
router,
"show bgp ipv4 vpn json",
expected,
@ -187,6 +205,7 @@ def test_protocols_convergence():
assertmsg = '"{}" JSON output mismatches'.format(router.name)
assert result is None, assertmsg
def test_memory_leak():
"Run the memory leak test and report results."
tgen = get_topogen()