Skip to content

Commit

Permalink
[bgp/...] Add assert_only_loopback_routes_announced_to_neighs_function
Browse files Browse the repository at this point in the history
* Add function which wraps verify_only_loopback_routes_... with assert and wait_until

Signed-off-by: Javier Tan javiertan@microsoft.com
  • Loading branch information
Javier-Tan committed Jan 29, 2025
1 parent ba5a096 commit d85dcca
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 141 deletions.
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
156 changes: 59 additions & 97 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,11 +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(
wait_until(180, 10, 10,
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 @@ -383,11 +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(
wait_until(180, 10, 10,
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 @@ -443,11 +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(
wait_until(180, 10, 10,
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 @@ -543,11 +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(
wait_until(180, 10, 10,
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 @@ -605,11 +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(
wait_until(180, 10, 10,
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 @@ -690,11 +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(
wait_until(180, 10, 10,
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 @@ -759,11 +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(
wait_until(180, 10, 10,
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 @@ -859,11 +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(
wait_until(180, 10, 10,
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 @@ -1007,11 +991,9 @@ def verify_linecard_tsa_tsb(lc):
executor.submit(verify_linecard_tsa_tsb, linecard)

for linecard in duthosts.frontend_nodes:
pytest_assert(
wait_until(180, 10, 10,
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 @@ -1116,11 +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(
wait_until(180, 10, 10,
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 @@ -1234,11 +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(
wait_until(180, 10, 10,
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 @@ -1324,12 +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(
wait_until(180, 10, 10,
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 @@ -1417,11 +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(
wait_until(180, 10, 10,
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 @@ -1504,11 +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(
wait_until(180, 10, 10,
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 @@ -1630,11 +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(
wait_until(180, 10, 10,
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 @@ -1806,11 +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(
wait_until(180, 10, 10,
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 @@ -1929,11 +1897,9 @@ def restart_bgp_and_verify(lc):

for linecard in duthosts.frontend_nodes:
# Verify only loopback routes are announced after TSA
pytest_assert(
wait_until(180, 10, 10,
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 @@ -1996,11 +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(
wait_until(180, 10, 10,
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 @@ -2148,11 +2112,9 @@ def restart_bgp_and_verify(lc):

for linecard in duthosts.frontend_nodes:
# Verify only loopback routes are announced after TSA
pytest_assert(
wait_until(180, 10, 10,
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

0 comments on commit d85dcca

Please sign in to comment.