Skip to content

Commit

Permalink
Merge pull request #16485 from donaldsharp/test_fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
eqvinox authored Jul 27, 2024
2 parents 7f10381 + ce3cea3 commit 7ac16c9
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 16 deletions.
1 change: 1 addition & 0 deletions tests/topotests/bgp_duplicate_nexthop/r1/bgpd.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
router bgp 64500
bgp router-id 192.0.2.1
timers bgp 3 9
no bgp ebgp-requires-policy
neighbor rrserver peer-group
neighbor rrserver remote-as 64500
Expand Down
1 change: 1 addition & 0 deletions tests/topotests/bgp_duplicate_nexthop/r3/bgpd.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
router bgp 64500 view one
timers bgp 3 9
bgp router-id 192.0.2.3
neighbor rr peer-group
neighbor rr remote-as 64500
Expand Down
1 change: 1 addition & 0 deletions tests/topotests/bgp_duplicate_nexthop/r5/bgpd.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
router bgp 64500
timers bgp 3 9
bgp router-id 192.0.2.5
no bgp ebgp-requires-policy
no bgp network import-check
Expand Down
1 change: 1 addition & 0 deletions tests/topotests/bgp_duplicate_nexthop/r6/bgpd.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
router bgp 64500
timers bgp 3 9
bgp router-id 192.0.2.6
no bgp ebgp-requires-policy
no bgp network import-check
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def check_ipv4_prefix_with_multiple_nexthops(prefix, multipath=True):
test_func = functools.partial(
ip_check_path_selection, tgen.gears["r1"], prefix, expected
)
_, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
_, result = topotest.run_and_expect(test_func, None, count=120, wait=0.5)
assert (
result is None
), f"Failed to check that {prefix} uses the IGP label 16055 and 16006"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,28 @@ def teardown_module(_mod):
tgen.stop_topology()


def check_bgp_vpnv4_prefix_presence(router, prefix):
def check_bgp_vpnv4_prefix_presence(router, prefix, table_version):
"Check the presence of a prefix"
tgen = get_topogen()

dump = router.vtysh_cmd("show bgp ipv4 vpn {} json".format(prefix), isjson=True)
if not dump:
return "{}, prefix ipv4 vpn {} is not installed yet".format(router.name, prefix)

for _, paths in dump.items():
for path in paths["paths"]:
new_version = path["version"]
if new_version <= table_version:
return "{}, prefix ipv4 vpn {} has not been updated yet".format(
router.name, prefix
)

return None


def bgp_vpnv4_table_check(router, group, label_list=None, label_value_expected=None):
def bgp_vpnv4_table_check(
router, group, label_list=None, label_value_expected=None, table_version=0
):
"""
Dump and check that vpnv4 entries have the same MPLS label value
* 'router': the router to check
Expand All @@ -173,7 +184,9 @@ def bgp_vpnv4_table_check(router, group, label_list=None, label_value_expected=N

stored_label_inited = False
for prefix in group:
test_func = functools.partial(check_bgp_vpnv4_prefix_presence, router, prefix)
test_func = functools.partial(
check_bgp_vpnv4_prefix_presence, router, prefix, table_version
)
success, _ = topotest.run_and_expect(test_func, None, count=10, wait=0.5)
assert success, "{}, prefix ipv4 vpn {} is not installed yet".format(
router.name, prefix
Expand Down Expand Up @@ -218,7 +231,7 @@ def bgp_vpnv4_table_check(router, group, label_list=None, label_value_expected=N
)


def bgp_vpnv4_table_check_all(router, label_list=None, same=False):
def bgp_vpnv4_table_check_all(router, label_list=None, same=False, table_version=0):
"""
Dump and check that vpnv4 entries are correctly configured with specific label values
* 'router': the router to check
Expand All @@ -236,6 +249,7 @@ def bgp_vpnv4_table_check_all(router, label_list=None, same=False):
+ PREFIXES_REDIST
+ PREFIXES_CONNECTED,
label_list=label_list,
table_version=table_version,
)
else:
for group in (
Expand All @@ -245,7 +259,9 @@ def bgp_vpnv4_table_check_all(router, label_list=None, same=False):
PREFIXES_REDIST,
PREFIXES_CONNECTED,
):
bgp_vpnv4_table_check(router, group=group, label_list=label_list)
bgp_vpnv4_table_check(
router, group=group, label_list=label_list, table_version=table_version
)


def check_show_mpls_table(router, blacklist=None, label_list=None, whitelist=None):
Expand Down Expand Up @@ -350,6 +366,11 @@ def check_show_mpls_table_entry_label_not_found(router, inlabel):
return None


def get_table_version(router):
table = router.vtysh_cmd("show bgp ipv4 vpn json", isjson=True)
return table["tableVersion"]


def mpls_entry_get_interface(router, label):
"""
Assert that the label is in MPLS table
Expand Down Expand Up @@ -686,6 +707,7 @@ def test_changing_default_label_value():
old_len != 1
), "r1, number of labels used should be greater than 1, oberved {} ".format(old_len)

table_version = get_table_version(router)
logger.info("r1, vrf1, changing the default MPLS label value to export to 222")
router.vtysh_cmd(
"configure terminal\nrouter bgp 65500 vrf vrf1\naddress-family ipv4 unicast\nlabel vpn export 222\n",
Expand All @@ -705,7 +727,7 @@ def test_changing_default_label_value():
# check label repartition is ok
logger.info("r1, vpnv4 table, check the number of labels used after modification")
label_list = set()
bgp_vpnv4_table_check_all(router, label_list)
bgp_vpnv4_table_check_all(router, label_list, table_version=table_version)
new_len = len(label_list)
assert (
old_len == new_len
Expand Down Expand Up @@ -734,6 +756,7 @@ def test_unconfigure_allocation_mode_nexthop():

logger.info("Unconfiguring allocation mode per nexthop")
router = tgen.gears["r1"]
table_version = get_table_version(router)
router.vtysh_cmd(
"configure terminal\nrouter bgp 65500 vrf vrf1\naddress-family ipv4 unicast\nno label vpn export allocation-mode per-nexthop\n",
isjson=False,
Expand All @@ -752,7 +775,9 @@ def test_unconfigure_allocation_mode_nexthop():
# Check vpnv4 routes from r1
logger.info("Checking vpnv4 routes on r1")
label_list = set()
bgp_vpnv4_table_check_all(router, label_list=label_list, same=True)
bgp_vpnv4_table_check_all(
router, label_list=label_list, same=True, table_version=table_version
)
assert len(label_list) == 1, "r1, multiple Label values found for vpnv4 updates"

new_label = label_list.pop()
Expand Down Expand Up @@ -782,6 +807,8 @@ def test_reconfigure_allocation_mode_nexthop():

logger.info("Reconfiguring allocation mode per nexthop")
router = tgen.gears["r1"]

table_version = get_table_version(router)
router.vtysh_cmd(
"configure terminal\nrouter bgp 65500 vrf vrf1\naddress-family ipv4 unicast\nlabel vpn export allocation-mode per-nexthop\n",
isjson=False,
Expand All @@ -800,7 +827,9 @@ def test_reconfigure_allocation_mode_nexthop():
# Check vpnv4 routes from r1
logger.info("Checking vpnv4 routes on r1")
label_list = set()
bgp_vpnv4_table_check_all(router, label_list=label_list)
bgp_vpnv4_table_check_all(
router, label_list=label_list, table_version=table_version
)
assert len(label_list) != 1, "r1, only 1 label values found for vpnv4 updates"

# Check mpls table with all values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,28 @@ def teardown_module(_mod):
tgen.stop_topology()


def check_bgp_vpnv6_prefix_presence(router, prefix):
def check_bgp_vpnv6_prefix_presence(router, prefix, table_version):
"Check the presence of a prefix"
tgen = get_topogen()

dump = router.vtysh_cmd("show bgp ipv6 vpn {} json".format(prefix), isjson=True)
if not dump:
return "{}, prefix ipv6 vpn {} is not installed yet".format(router.name, prefix)

for _, paths in dump.items():
for path in paths["paths"]:
new_version = path["version"]
if new_version <= table_version:
return "{}, prefix ipv6 vpn {} has not been updated yet".format(
router.name, prefix
)

return None


def bgp_vpnv6_table_check(router, group, label_list=None, label_value_expected=None):
def bgp_vpnv6_table_check(
router, group, label_list=None, label_value_expected=None, table_version=0
):
"""
Dump and check that vpnv6 entries have the same MPLS label value
* 'router': the router to check
Expand All @@ -172,7 +183,9 @@ def bgp_vpnv6_table_check(router, group, label_list=None, label_value_expected=N

stored_label_inited = False
for prefix in group:
test_func = functools.partial(check_bgp_vpnv6_prefix_presence, router, prefix)
test_func = functools.partial(
check_bgp_vpnv6_prefix_presence, router, prefix, table_version
)
success, _ = topotest.run_and_expect(test_func, None, count=10, wait=0.5)
assert success, "{}, prefix ipv6 vpn {} is not installed yet".format(
router.name, prefix
Expand Down Expand Up @@ -214,7 +227,7 @@ def bgp_vpnv6_table_check(router, group, label_list=None, label_value_expected=N
)


def bgp_vpnv6_table_check_all(router, label_list=None, same=False):
def bgp_vpnv6_table_check_all(router, label_list=None, same=False, table_version=0):
"""
Dump and check that vpnv6 entries are correctly configured with specific label values
* 'router': the router to check
Expand All @@ -231,6 +244,7 @@ def bgp_vpnv6_table_check_all(router, label_list=None, same=False):
+ PREFIXES_REDIST_R14
+ PREFIXES_CONNECTED,
label_list=label_list,
table_version=table_version,
)
else:
for group in (
Expand All @@ -239,7 +253,9 @@ def bgp_vpnv6_table_check_all(router, label_list=None, same=False):
PREFIXES_REDIST_R14,
PREFIXES_CONNECTED,
):
bgp_vpnv6_table_check(router, group=group, label_list=label_list)
bgp_vpnv6_table_check(
router, group=group, label_list=label_list, table_version=table_version
)


def check_show_mpls_table(router, blacklist=None, label_list=None, whitelist=None):
Expand Down Expand Up @@ -345,6 +361,11 @@ def check_show_mpls_table_entry_label_not_found(router, inlabel):
return None


def get_table_version(router):
table = router.vtysh_cmd("show bgp ipv6 vpn json", isjson=True)
return table["tableVersion"]


def mpls_entry_get_interface(router, label):
"""
Assert that the label is in MPLS table
Expand Down Expand Up @@ -691,6 +712,7 @@ def test_changing_default_label_value():
old_len != 1
), "r1, number of labels used should be greater than 1, oberved {} ".format(old_len)

table_version = get_table_version(router)
logger.info("r1, vrf1, changing the default MPLS label value to export to 222")
router.vtysh_cmd(
"configure terminal\nrouter bgp 65500 vrf vrf1\naddress-family ipv6 unicast\nlabel vpn export 222\n",
Expand All @@ -710,7 +732,7 @@ def test_changing_default_label_value():
# check label repartition is ok
logger.info("r1, VPNv6 table, check the number of labels used after modification")
label_list = set()
bgp_vpnv6_table_check_all(router, label_list)
bgp_vpnv6_table_check_all(router, label_list, table_version=table_version)
new_len = len(label_list)
assert (
old_len == new_len
Expand Down Expand Up @@ -786,6 +808,7 @@ def test_reconfigure_allocation_mode_nexthop():

logger.info("Reconfiguring allocation mode per nexthop")
router = tgen.gears["r1"]
table_version = get_table_version(router)
dump = router.vtysh_cmd(
"configure terminal\nrouter bgp 65500 vrf vrf1\naddress-family ipv6 unicast\nlabel vpn export allocation-mode per-nexthop\n",
isjson=False,
Expand All @@ -804,7 +827,9 @@ def test_reconfigure_allocation_mode_nexthop():
# Check vpnv6 routes from r1
logger.info("Checking VPNv6 routes on r1")
label_list = set()
bgp_vpnv6_table_check_all(router, label_list=label_list)
bgp_vpnv6_table_check_all(
router, label_list=label_list, table_version=table_version
)
assert len(label_list) != 1, "r1, only 1 label values found for VPNv6 updates"

# Check mpls table with all values
Expand Down

0 comments on commit 7ac16c9

Please sign in to comment.