Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to wrap verify_only_loopback_routes with assert and wait_until #16523

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions tests/bgp/route_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from tests.common.devices.eos import EosHost
from tests.common.helpers.assertions import pytest_assert
from tests.common.helpers.parallel import parallel_run
from tests.common.utilities import wait_until

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -206,6 +207,18 @@ def verify_only_loopback_routes_are_announced_to_neighs(dut_hosts, duthost, neig
dut_hosts, duthost, neigh_hosts, 6, community)


def assert_only_loopback_routes_announced_to_neighs(dut_hosts, duthost, neigh_hosts, community,
error_msg=""):
if not error_msg:
error_msg = "Failed to verify only loopback routes are announced to neighbours"

pytest_assert(
wait_until(180, 10, 5, verify_only_loopback_routes_are_announced_to_neighs,
dut_hosts, duthost, neigh_hosts, community),
error_msg
)


def parse_routes_on_neighbors(dut_host, neigh_hosts, ip_ver, exp_community=[]):
if isinstance(list(neigh_hosts.items())[0][1]['host'], EosHost):
routes_on_all_nbrs = parse_routes_on_eos(dut_host, neigh_hosts, ip_ver, exp_community)
Expand Down
118 changes: 59 additions & 59 deletions tests/bgp/test_reliable_tsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from tests.bgp.bgp_helpers import get_tsa_chassisdb_config, get_sup_cfggen_tsa_value, verify_dut_configdb_tsa_value
from tests.bgp.traffic_checker import get_traffic_shift_state
from tests.bgp.route_checker import parse_routes_on_neighbors, check_and_log_routes_diff, \
verify_current_routes_announced_to_neighs, verify_only_loopback_routes_are_announced_to_neighs
verify_current_routes_announced_to_neighs, assert_only_loopback_routes_announced_to_neighs
from tests.bgp.constants import TS_NORMAL, TS_MAINTENANCE
from tests.bgp.test_startup_tsa_tsb_service import get_tsa_tsb_service_uptime, get_tsa_tsb_service_status, \
get_startup_tsb_timer, enable_disable_startup_tsa_tsb_service # noqa: F401
Expand Down Expand Up @@ -309,9 +309,9 @@ def verify_linecard_after_sup_tsa(lc):

for linecard in duthosts.frontend_nodes:
# Verify only loopback routes are announced after TSA
pytest_assert(verify_only_loopback_routes_are_announced_to_neighs(
duthosts, linecard, dut_nbrhosts[linecard], traffic_shift_community),
"Failed to verify routes on nbr in TSA")
assert_only_loopback_routes_announced_to_neighs(duthosts, linecard, dut_nbrhosts[linecard],
traffic_shift_community,
"Failed to verify routes on nbr in TSA")
finally:
# Bring back the supervisor and line cards to the normal state
set_tsb_on_sup_duts_before_and_after_test(duthosts, enum_supervisor_dut_hostname)
Expand Down Expand Up @@ -381,9 +381,9 @@ def verify_linecard_after_sup_tsa(lc):

for linecard in duthosts.frontend_nodes:
# Verify only loopback routes are announced after TSA
pytest_assert(verify_only_loopback_routes_are_announced_to_neighs(
duthosts, linecard, dut_nbrhosts[linecard], traffic_shift_community),
"Failed to verify routes on nbr in TSA")
assert_only_loopback_routes_announced_to_neighs(duthosts, linecard, dut_nbrhosts[linecard],
traffic_shift_community,
"Failed to verify routes on nbr in TSA")
finally:
# Bring back the supervisor and line cards to the normal state
set_tsb_on_sup_duts_before_and_after_test(duthosts, enum_supervisor_dut_hostname)
Expand Down Expand Up @@ -439,9 +439,9 @@ def verify_linecard_after_sup_tsa(lc):

for linecard in duthosts.frontend_nodes:
# Verify only loopback routes are announced after TSA
pytest_assert(verify_only_loopback_routes_are_announced_to_neighs(
duthosts, linecard, dut_nbrhosts[linecard], traffic_shift_community),
"Failed to verify routes on nbr in TSA")
assert_only_loopback_routes_announced_to_neighs(duthosts, linecard, dut_nbrhosts[linecard],
traffic_shift_community,
"Failed to verify routes on nbr in TSA")

# Issue TSB on the supervisor
suphost.shell('TSB')
Expand Down Expand Up @@ -537,9 +537,9 @@ def verify_linecard_after_sup_tsb(lc):

for linecard in duthosts.frontend_nodes:
# Verify only loopback routes are announced after TSA
pytest_assert(verify_only_loopback_routes_are_announced_to_neighs(
duthosts, linecard, dut_nbrhosts[linecard], traffic_shift_community),
"Failed to verify routes on nbr in TSA")
assert_only_loopback_routes_announced_to_neighs(duthosts, linecard, dut_nbrhosts[linecard],
traffic_shift_community,
"Failed to verify routes on nbr in TSA")
finally:
# Bring back the supervisor and line cards to the normal state
set_tsb_on_sup_duts_before_and_after_test(duthosts, enum_supervisor_dut_hostname)
Expand Down Expand Up @@ -597,9 +597,9 @@ def run_tsa_on_linecard_and_verify(lc):

for linecard in duthosts.frontend_nodes:
# Verify only loopback routes are announced after TSA
pytest_assert(verify_only_loopback_routes_are_announced_to_neighs(
duthosts, linecard, dut_nbrhosts[linecard], traffic_shift_community),
"Failed to verify routes on nbr in TSA")
assert_only_loopback_routes_announced_to_neighs(duthosts, linecard, dut_nbrhosts[linecard],
traffic_shift_community,
"Failed to verify routes on nbr in TSA")

# Verify supervisor still has tsa_enabled 'false' config
pytest_assert('false' == get_tsa_chassisdb_config(suphost),
Expand Down Expand Up @@ -680,9 +680,9 @@ def run_tsa_on_linecard_and_verify(lc):

for linecard in duthosts.frontend_nodes:
# Verify only loopback routes are announced after TSA
pytest_assert(verify_only_loopback_routes_are_announced_to_neighs(
duthosts, linecard, dut_nbrhosts[linecard], traffic_shift_community),
"Failed to verify routes on nbr in TSA")
assert_only_loopback_routes_announced_to_neighs(duthosts, linecard, dut_nbrhosts[linecard],
traffic_shift_community,
"Failed to verify routes on nbr in TSA")

# Verify supervisor still has tsa_enabled 'true' config
pytest_assert('true' == get_tsa_chassisdb_config(suphost),
Expand Down Expand Up @@ -747,9 +747,9 @@ def run_tsa_on_linecard_and_verify(lc):

for linecard in duthosts.frontend_nodes:
# Verify only loopback routes are announced after TSA
pytest_assert(verify_only_loopback_routes_are_announced_to_neighs(
duthosts, linecard, dut_nbrhosts[linecard], traffic_shift_community),
"Failed to verify routes on nbr in TSA")
assert_only_loopback_routes_announced_to_neighs(duthosts, linecard, dut_nbrhosts[linecard],
traffic_shift_community,
"Failed to verify routes on nbr in TSA")

def run_tsb_on_linecard_and_verify(lc):
lc.shell('TSB')
Expand Down Expand Up @@ -845,9 +845,9 @@ def run_tsb_on_linecard_and_verify(lc):

for linecard in duthosts.frontend_nodes:
# Verify only loopback routes are announced after TSA
pytest_assert(verify_only_loopback_routes_are_announced_to_neighs(
duthosts, linecard, dut_nbrhosts[linecard], traffic_shift_community),
"Failed to verify routes on nbr in TSA")
assert_only_loopback_routes_announced_to_neighs(duthosts, linecard, dut_nbrhosts[linecard],
traffic_shift_community,
"Failed to verify routes on nbr in TSA")

# Verify supervisor still has tsa_enabled 'true' config
pytest_assert('true' == get_tsa_chassisdb_config(suphost),
Expand Down Expand Up @@ -991,9 +991,9 @@ def verify_linecard_tsa_tsb(lc):
executor.submit(verify_linecard_tsa_tsb, linecard)

for linecard in duthosts.frontend_nodes:
pytest_assert(verify_only_loopback_routes_are_announced_to_neighs(
duthosts, linecard, dut_nbrhosts[linecard], traffic_shift_community),
"Failed to verify routes on nbr in TSA")
assert_only_loopback_routes_announced_to_neighs(duthosts, linecard, dut_nbrhosts[linecard],
traffic_shift_community,
"Failed to verify routes on nbr in TSA")
finally:
# Bring back the supervisor and line cards to the normal state
set_tsb_on_sup_duts_before_and_after_test(duthosts, enum_supervisor_dut_hostname)
Expand Down Expand Up @@ -1098,9 +1098,9 @@ def verify_line_card_after_sup_config_reload(lc):
executor.submit(verify_line_card_after_sup_config_reload, linecard)

for linecard in duthosts.frontend_nodes:
pytest_assert(verify_only_loopback_routes_are_announced_to_neighs(
duthosts, linecard, dut_nbrhosts[linecard], traffic_shift_community),
"Failed to verify routes on nbr in TSA")
assert_only_loopback_routes_announced_to_neighs(duthosts, linecard, dut_nbrhosts[linecard],
traffic_shift_community,
"Failed to verify routes on nbr in TSA")
finally:
# Bring back the supervisor and line cards to the normal state
set_tsb_on_sup_duts_before_and_after_test(duthosts, enum_supervisor_dut_hostname)
Expand Down Expand Up @@ -1214,9 +1214,9 @@ def reboot_linecard_and_verify(lc):

for linecard in duthosts.frontend_nodes:
# Verify only loopback routes are announced to neighbors when the linecards are in TSA
pytest_assert(verify_only_loopback_routes_are_announced_to_neighs(
duthosts, linecard, dut_nbrhosts[linecard], traffic_shift_community),
"Failed to verify routes on nbr in TSA")
assert_only_loopback_routes_announced_to_neighs(duthosts, linecard, dut_nbrhosts[linecard],
traffic_shift_community,
"Failed to verify routes on nbr in TSA")

# Verify supervisor still has tsa_enabled 'false' config
pytest_assert('false' == get_tsa_chassisdb_config(suphost),
Expand Down Expand Up @@ -1302,10 +1302,10 @@ def verify_line_card_after_sup_tsa(lc):
# Verify DUT is in maintenance state.
pytest_assert(TS_MAINTENANCE == get_traffic_shift_state(first_linecard, cmd='TSC no-stats'),
"DUT is not in maintenance state after config reload")

pytest_assert(verify_only_loopback_routes_are_announced_to_neighs(
duthosts, first_linecard, dut_nbrhosts[first_linecard], traffic_shift_community),
"Failed to verify routes on nbr in TSA")
assert_only_loopback_routes_announced_to_neighs(duthosts, first_linecard,
dut_nbrhosts[first_linecard],
traffic_shift_community,
"Failed to verify routes on nbr in TSA")

# Verify supervisor still has tsa_enabled 'true' config
pytest_assert('true' == get_tsa_chassisdb_config(suphost),
Expand Down Expand Up @@ -1393,9 +1393,9 @@ def verify_linecard_after_sup_tsa(lc):

for linecard in duthosts.frontend_nodes:
# Verify only loopback routes are announced with TSA
pytest_assert(verify_only_loopback_routes_are_announced_to_neighs(
duthosts, linecard, dut_nbrhosts[linecard], traffic_shift_community),
"Failed to verify routes on nbr in TSA")
assert_only_loopback_routes_announced_to_neighs(duthosts, linecard, dut_nbrhosts[linecard],
traffic_shift_community,
"Failed to verify routes on nbr in TSA")
finally:
# Bring back the supervisor and line cards to the normal state
set_tsb_on_sup_duts_before_and_after_test(duthosts, enum_supervisor_dut_hostname)
Expand Down Expand Up @@ -1478,9 +1478,9 @@ def verify_linecard_after_sup_tsb(lc):

for linecard in duthosts.frontend_nodes:
# Verify only loopback routes are announced with TSA
pytest_assert(verify_only_loopback_routes_are_announced_to_neighs(
duthosts, linecard, dut_nbrhosts[linecard], traffic_shift_community),
"Failed to verify routes on nbr in TSA")
assert_only_loopback_routes_announced_to_neighs(duthosts, linecard, dut_nbrhosts[linecard],
traffic_shift_community,
"Failed to verify routes on nbr in TSA")
finally:
# Bring back the supervisor and line cards to the normal state
set_tsb_on_sup_duts_before_and_after_test(duthosts, enum_supervisor_dut_hostname)
Expand Down Expand Up @@ -1602,9 +1602,9 @@ def verify_linecard_after_sup_tsa(lc):

# Verify only loopback routes are announced to neighbors at this state
for linecard in duthosts.frontend_nodes:
pytest_assert(verify_only_loopback_routes_are_announced_to_neighs(
duthosts, linecard, dut_nbrhosts[linecard], traffic_shift_community),
"Failed to verify routes on nbr in TSA")
assert_only_loopback_routes_announced_to_neighs(duthosts, linecard, dut_nbrhosts[linecard],
traffic_shift_community,
"Failed to verify routes on nbr in TSA")
finally:
# Bring back the supervisor and line cards to the normal state
set_tsb_on_sup_duts_before_and_after_test(duthosts, enum_supervisor_dut_hostname)
Expand Down Expand Up @@ -1776,9 +1776,9 @@ def test_sup_tsb_followed_by_dut_bgp_restart_when_sup_on_tsa_duts_on_tsb(
pytest_assert(TS_MAINTENANCE == get_traffic_shift_state(linecard, cmd='TSC no-stats'),
"DUT is not in maintenance state")
# Verify only loopback routes are announced after TSA
pytest_assert(verify_only_loopback_routes_are_announced_to_neighs(
duthosts, linecard, dut_nbrhosts[linecard], traffic_shift_community),
"Failed to verify routes on nbr in TSA")
assert_only_loopback_routes_announced_to_neighs(duthosts, linecard, dut_nbrhosts[linecard],
traffic_shift_community,
"Failed to verify routes on nbr in TSA")

# Issue TSB on the supervisor
suphost.shell('TSB')
Expand Down Expand Up @@ -1897,9 +1897,9 @@ def restart_bgp_and_verify(lc):

for linecard in duthosts.frontend_nodes:
# Verify only loopback routes are announced after TSA
pytest_assert(verify_only_loopback_routes_are_announced_to_neighs(
duthosts, linecard, dut_nbrhosts[linecard], traffic_shift_community),
"Failed to verify routes on nbr in TSA")
assert_only_loopback_routes_announced_to_neighs(duthosts, linecard, dut_nbrhosts[linecard],
traffic_shift_community,
"Failed to verify routes on nbr in TSA")
finally:
# Bring back the supervisor and line cards to the normal state
set_tsb_on_sup_duts_before_and_after_test(duthosts, enum_supervisor_dut_hostname)
Expand Down Expand Up @@ -1962,9 +1962,9 @@ def run_tsa_on_linecard_and_verify(lc):

for linecard in duthosts.frontend_nodes:
# Verify only loopback routes are announced after TSA
pytest_assert(verify_only_loopback_routes_are_announced_to_neighs(
duthosts, linecard, dut_nbrhosts[linecard], traffic_shift_community),
"Failed to verify routes on nbr in TSA")
assert_only_loopback_routes_announced_to_neighs(duthosts, linecard, dut_nbrhosts[linecard],
traffic_shift_community,
"Failed to verify routes on nbr in TSA")

def run_tsb_on_linecard_and_verify(lc):
lc.shell('TSB')
Expand Down Expand Up @@ -2112,9 +2112,9 @@ def restart_bgp_and_verify(lc):

for linecard in duthosts.frontend_nodes:
# Verify only loopback routes are announced after TSA
pytest_assert(verify_only_loopback_routes_are_announced_to_neighs(
duthosts, linecard, dut_nbrhosts[linecard], traffic_shift_community),
"Failed to verify routes on nbr in TSA")
assert_only_loopback_routes_announced_to_neighs(duthosts, linecard, dut_nbrhosts[linecard],
traffic_shift_community,
"Failed to verify routes on nbr in TSA")
finally:
# Bring back the supervisor and line cards to the normal state
set_tsb_on_sup_duts_before_and_after_test(duthosts, enum_supervisor_dut_hostname)
Expand Down
Loading
Loading