tests: reset neighbor state machine to avoid bad/stale state

Signed-off-by: Jafar Al-Gharaibeh <jafar@atcorp.com>
This commit is contained in:
Jafar Al-Gharaibeh 2023-05-11 00:12:29 -05:00
parent ba607fdfcb
commit 1fdd28a730
3 changed files with 18 additions and 10 deletions

View File

@ -302,7 +302,6 @@ def __create_ospf_global(tgen, input_dict, router, build, load_config, ospf):
# ospf gr information
gr_data = ospf_data.setdefault("graceful-restart", {})
if gr_data:
if "opaque" in gr_data and gr_data["opaque"]:
cmd = "capability opaque"
if gr_data.setdefault("delete", False):
@ -729,9 +728,11 @@ def verify_ospf_neighbor(
try:
nh_state = show_ospf_json[nbr_rid][0]["nbrState"].split("/")[0]
except KeyError:
errormsg = "[DUT: {}] missing OSPF neighbor {} with router-id {}".format(
errormsg = (
"[DUT: {}] missing OSPF neighbor {} with router-id {}".format(
router, ospf_nbr, nbr_rid
)
)
return errormsg
if nh_state == "Full":
@ -844,7 +845,6 @@ def verify_ospf6_neighbor(tgen, topo=None, dut=None, input_dict=None, lan=False)
return errormsg
for ospf_nbr, nbr_data in ospf_nbr_list.items():
try:
data_ip = data_rid = topo["routers"][ospf_nbr]["ospf6"]["router_id"]
except KeyError:
@ -915,7 +915,6 @@ def verify_ospf6_neighbor(tgen, topo=None, dut=None, input_dict=None, lan=False)
return errormsg
continue
else:
for router, rnode in tgen.routers().items():
if "ospf6" not in topo["routers"][router]:
continue
@ -969,9 +968,11 @@ def verify_ospf6_neighbor(tgen, topo=None, dut=None, input_dict=None, lan=False)
nh_state = get_index_val.get(neighbor_ip)["state"]
intf_state = get_index_val.get(neighbor_ip)["ifState"]
except TypeError:
errormsg = "[DUT: {}] missing OSPF neighbor {} with router-id {}".format(
errormsg = (
"[DUT: {}] missing OSPF neighbor {} with router-id {}".format(
router, ospf_nbr, nbr_rid
)
)
return errormsg
if nh_state == "Full":
@ -1762,7 +1763,6 @@ def verify_ospf6_rib(
continue
if st_rt in ospf_rib_json:
st_found = True
found_routes.append(st_rt)

View File

@ -977,7 +977,7 @@ def test_ospf_type5_summary_tc42_p0(request):
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 = {
"r0": {
"ospf": {"summary-address": [{"prefix": ip_net.split("/")[0], "mask": "8"}]}
@ -1579,6 +1579,10 @@ def test_ospf_type5_summary_tc45_p0(request):
result = create_interfaces_cfg(tgen, input_dict)
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)
assert ospf_covergence is True, "setup_module :Failed \n Error {}".format(
ospf_covergence

View File

@ -565,7 +565,7 @@ def test_ospfv3_type5_summary_tc42_p0(request):
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 = {
"r0": {
"ospf6": {
@ -1428,6 +1428,10 @@ def ospfv3_type5_summary_tc45_p0(request):
result = create_interfaces_cfg(tgen, input_dict)
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)
assert ospf_covergence is True, "Testcase {} :Failed \n Error: {}".format(
tc_name, ospf_covergence