Merge pull request #13490 from Jafaral/fix-ospf-asbr-test

tests: improve log messages, clear neighbors to avoid bad state
This commit is contained in:
Donald Sharp 2023-05-11 20:31:21 -04:00 committed by GitHub
commit f1af873fef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 17 deletions

View File

@ -302,7 +302,6 @@ def __create_ospf_global(tgen, input_dict, router, build, load_config, ospf):
# ospf gr information # ospf gr information
gr_data = ospf_data.setdefault("graceful-restart", {}) gr_data = ospf_data.setdefault("graceful-restart", {})
if gr_data: if gr_data:
if "opaque" in gr_data and gr_data["opaque"]: if "opaque" in gr_data and gr_data["opaque"]:
cmd = "capability opaque" cmd = "capability opaque"
if gr_data.setdefault("delete", False): if gr_data.setdefault("delete", False):
@ -710,6 +709,7 @@ def verify_ospf_neighbor(
else: else:
data_ip = topo["routers"][ospf_nbr]["links"] data_ip = topo["routers"][ospf_nbr]["links"]
data_rid = topo["routers"][ospf_nbr]["ospf"]["router_id"] data_rid = topo["routers"][ospf_nbr]["ospf"]["router_id"]
logger.info("ospf neighbor %s: router-id: %s", router, data_rid)
if ospf_nbr in data_ip: if ospf_nbr in data_ip:
nbr_details = nbr_data[ospf_nbr] nbr_details = nbr_data[ospf_nbr]
elif lan: elif lan:
@ -728,8 +728,10 @@ def verify_ospf_neighbor(
try: try:
nh_state = show_ospf_json[nbr_rid][0]["nbrState"].split("/")[0] nh_state = show_ospf_json[nbr_rid][0]["nbrState"].split("/")[0]
except KeyError: except KeyError:
errormsg = "[DUT: {}] OSPF peer {} missing,from " "{} ".format( errormsg = (
router, nbr_rid, ospf_nbr "[DUT: {}] missing OSPF neighbor {} with router-id {}".format(
router, ospf_nbr, nbr_rid
)
) )
return errormsg return errormsg
@ -843,7 +845,6 @@ def verify_ospf6_neighbor(tgen, topo=None, dut=None, input_dict=None, lan=False)
return errormsg return errormsg
for ospf_nbr, nbr_data in ospf_nbr_list.items(): for ospf_nbr, nbr_data in ospf_nbr_list.items():
try: try:
data_ip = data_rid = topo["routers"][ospf_nbr]["ospf6"]["router_id"] data_ip = data_rid = topo["routers"][ospf_nbr]["ospf6"]["router_id"]
except KeyError: except KeyError:
@ -914,7 +915,6 @@ def verify_ospf6_neighbor(tgen, topo=None, dut=None, input_dict=None, lan=False)
return errormsg return errormsg
continue continue
else: else:
for router, rnode in tgen.routers().items(): for router, rnode in tgen.routers().items():
if "ospf6" not in topo["routers"][router]: if "ospf6" not in topo["routers"][router]:
continue continue
@ -945,7 +945,7 @@ def verify_ospf6_neighbor(tgen, topo=None, dut=None, input_dict=None, lan=False)
data_ip = data_rid = topo["routers"][nbr_data["nbr"]]["ospf6"][ data_ip = data_rid = topo["routers"][nbr_data["nbr"]]["ospf6"][
"router_id" "router_id"
] ]
logger.info("ospf neighbor %s: router-id: %s", ospf_nbr, data_rid)
if ospf_nbr in data_ip: if ospf_nbr in data_ip:
nbr_details = nbr_data[ospf_nbr] nbr_details = nbr_data[ospf_nbr]
elif lan: elif lan:
@ -968,8 +968,10 @@ def verify_ospf6_neighbor(tgen, topo=None, dut=None, input_dict=None, lan=False)
nh_state = get_index_val.get(neighbor_ip)["state"] nh_state = get_index_val.get(neighbor_ip)["state"]
intf_state = get_index_val.get(neighbor_ip)["ifState"] intf_state = get_index_val.get(neighbor_ip)["ifState"]
except TypeError: except TypeError:
errormsg = "[DUT: {}] OSPF peer {} missing,from " "{} ".format( errormsg = (
router, nbr_rid, ospf_nbr "[DUT: {}] missing OSPF neighbor {} with router-id {}".format(
router, ospf_nbr, nbr_rid
)
) )
return errormsg return errormsg
@ -1761,7 +1763,6 @@ def verify_ospf6_rib(
continue continue
if st_rt in ospf_rib_json: if st_rt in ospf_rib_json:
st_found = True st_found = True
found_routes.append(st_rt) found_routes.append(st_rt)

View File

@ -84,8 +84,8 @@ SUMMARY = {"ipv4": ["11.0.0.0/8", "12.0.0.0/8", "11.0.0.0/24"]}
""" """
TOPOOLOGY = TOPOOLOGY =
Please view in a fixed-width font such as Courier. Please view in a fixed-width font such as Courier.
+---+ A0 +---+ +---+ A0 +---+
+R1 +------------+R2 | |R1 +------------+R2 |
+-+-+- +--++ +-+-+- +--++
| -- -- | | -- -- |
| -- A0 -- | | -- A0 -- |
@ -94,8 +94,8 @@ TOPOOLOGY =
| -- -- | | -- -- |
| -- -- | | -- -- |
+-+-+- +-+-+ +-+-+- +-+-+
+R0 +-------------+R3 | |R0 +-------------+R3 |
+---+ A0 +---+ +---+ A0 +---+
TESTCASES = TESTCASES =
1. OSPF summarisation functionality. 1. OSPF summarisation functionality.
@ -977,7 +977,7 @@ def test_ospf_type5_summary_tc42_p0(request):
ip = topo["routers"]["r0"]["links"]["r3"]["ipv4"] ip = topo["routers"]["r0"]["links"]["r3"]["ipv4"]
ip_net = str(ipaddress.ip_interface(u"{}".format(ip)).network) ip_net = str(ipaddress.ip_interface("{}".format(ip)).network)
ospf_summ_r1 = { ospf_summ_r1 = {
"r0": { "r0": {
"ospf": {"summary-address": [{"prefix": ip_net.split("/")[0], "mask": "8"}]} "ospf": {"summary-address": [{"prefix": ip_net.split("/")[0], "mask": "8"}]}
@ -1519,7 +1519,7 @@ def test_ospf_type5_summary_tc45_p0(request):
step("Repeat steps 1 to 10 of summarisation in non Back bone area.") step("Repeat steps 1 to 10 of summarisation in non Back bone area.")
reset_config_on_routers(tgen) reset_config_on_routers(tgen)
step("Change the area id on the interface on R0") step("Change the area id on the interface on R0 to R1 from 0.0.0.0 to 0.0.0.1")
input_dict = { input_dict = {
"r0": { "r0": {
"links": { "links": {
@ -1549,7 +1549,7 @@ def test_ospf_type5_summary_tc45_p0(request):
result = create_interfaces_cfg(tgen, input_dict) result = create_interfaces_cfg(tgen, input_dict)
assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
step("Change the area id on the interface ") step("Change the area id on the interface on R1 to R0 from 0.0.0.0 to 0.0.0.1")
input_dict = { input_dict = {
"r1": { "r1": {
"links": { "links": {
@ -1579,6 +1579,10 @@ def test_ospf_type5_summary_tc45_p0(request):
result = create_interfaces_cfg(tgen, input_dict) result = create_interfaces_cfg(tgen, input_dict)
assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
# clear neighbor state on both routers to avoid stale state
tgen.net["r0"].cmd("clear ip ospf neighbor")
tgen.net["r1"].cmd("clear ip ospf neighbor")
ospf_covergence = verify_ospf_neighbor(tgen, topo) ospf_covergence = verify_ospf_neighbor(tgen, topo)
assert ospf_covergence is True, "setup_module :Failed \n Error {}".format( assert ospf_covergence is True, "setup_module :Failed \n Error {}".format(
ospf_covergence ospf_covergence

View File

@ -565,7 +565,7 @@ def test_ospfv3_type5_summary_tc42_p0(request):
ip = topo["routers"]["r0"]["links"]["r3"]["ipv6"] ip = topo["routers"]["r0"]["links"]["r3"]["ipv6"]
ip_net = str(ipaddress.ip_interface(u"{}".format(ip)).network) ip_net = str(ipaddress.ip_interface("{}".format(ip)).network)
ospf_summ_r1 = { ospf_summ_r1 = {
"r0": { "r0": {
"ospf6": { "ospf6": {
@ -1428,6 +1428,10 @@ def ospfv3_type5_summary_tc45_p0(request):
result = create_interfaces_cfg(tgen, input_dict) result = create_interfaces_cfg(tgen, input_dict)
assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
# restart interface state machine on both routers to avoid stale state
tgen.net["r0"].cmd("clear ipv6 ospf6 interface")
tgen.net["r1"].cmd("clear ipv6 ospf6 interface")
ospf_covergence = verify_ospf6_neighbor(tgen, topo) ospf_covergence = verify_ospf6_neighbor(tgen, topo)
assert ospf_covergence is True, "Testcase {} :Failed \n Error: {}".format( assert ospf_covergence is True, "Testcase {} :Failed \n Error: {}".format(
tc_name, ospf_covergence tc_name, ospf_covergence