Skip to content

Commit

Permalink
Refactor traffic_shift & traffic_shift_sup suites w.r.t reliable_tsa
Browse files Browse the repository at this point in the history
Do pre/post check only for t2 topo

typo
  • Loading branch information
sanjair-git committed Sep 20, 2024
1 parent 7c393c1 commit bb71883
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 61 deletions.
26 changes: 26 additions & 0 deletions tests/bgp/bgp_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from tests.common.helpers.parallel import reset_ansible_local_tmp
from tests.common.helpers.parallel import parallel_run
from tests.common.utilities import wait_until
from tests.bgp.traffic_checker import get_traffic_shift_state
from tests.bgp.constants import TS_NORMAL

BASE_DIR = os.path.dirname(os.path.realpath(__file__))
DUT_TMP_DIR = os.path.join('tmp', os.path.basename(BASE_DIR))
Expand Down Expand Up @@ -879,3 +881,27 @@ def verify_dut_configdb_tsa_value(duthost):
tsa_enabled = 'true'

return tsa_enabled


def initial_tsa_check_before_and_after_test(duthosts):
"""
@summary: Common method to make sure the supervisor and line cards are in normal state before and after the test
"""
for duthost in duthosts:
if duthost.is_supervisor_node():
# Initially make sure both supervisor and line cards are in BGP operational normal state
if get_tsa_chassisdb_config(duthost) != 'false' or get_sup_cfggen_tsa_value(duthost) != 'false':
duthost.shell('TSB')
duthost.shell('sudo config save -y')
pytest_assert('false' == get_tsa_chassisdb_config(duthost),
"Supervisor {} tsa_enabled config is enabled".format(duthost.hostname))

for linecard in duthosts.frontend_nodes:
# Issue TSB on the line card before proceeding further
if verify_dut_configdb_tsa_value(linecard) != 'false' or get_tsa_chassisdb_config(linecard) != 'false' or \
get_traffic_shift_state(linecard, cmd='TSC no-stats') != TS_NORMAL:
linecard.shell('TSB')
linecard.shell('sudo config save -y')
# Ensure that the DUT is not in maintenance already before start of the test
pytest_assert(TS_NORMAL == get_traffic_shift_state(linecard, cmd='TSC no-stats'),
"DUT is not in normal state")
2 changes: 1 addition & 1 deletion tests/bgp/route_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import ipaddr as ipaddress
import re
import json
from bgp_helpers import parse_rib
from tests.bgp.bgp_helpers import parse_rib
from tests.common.devices.eos import EosHost
from tests.common.helpers.assertions import pytest_assert
from tests.common.helpers.parallel import parallel_run
Expand Down
4 changes: 2 additions & 2 deletions tests/bgp/test_reliable_tsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
from tests.common.platform.processes_utils import wait_critical_processes, _all_critical_processes_healthy
from tests.common.platform.interface_utils import check_interface_status_of_up_ports
from tests.bgp.bgp_helpers import get_tsa_chassisdb_config, get_sup_cfggen_tsa_value, verify_dut_configdb_tsa_value
from traffic_checker import get_traffic_shift_state
from route_checker import parse_routes_on_neighbors, check_and_log_routes_diff, \
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
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, \
Expand Down
66 changes: 21 additions & 45 deletions tests/bgp/test_startup_tsa_tsb_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
from tests.common.utilities import wait_until
from tests.common.platform.processes_utils import wait_critical_processes, _all_critical_processes_healthy
from tests.common.platform.interface_utils import check_interface_status_of_up_ports
from traffic_checker import get_traffic_shift_state, check_tsa_persistence_support
from route_checker import parse_routes_on_neighbors, check_and_log_routes_diff, \
from tests.bgp.bgp_helpers import initial_tsa_check_before_and_after_test
from tests.bgp.traffic_checker import get_traffic_shift_state, check_tsa_persistence_support
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
from tests.bgp.constants import TS_NORMAL, TS_MAINTENANCE
from tests.bgp.bgp_helpers import get_tsa_chassisdb_config, get_sup_cfggen_tsa_value, verify_dut_configdb_tsa_value

pytestmark = [
pytest.mark.topology('t2')
Expand Down Expand Up @@ -145,30 +145,6 @@ def nbrhosts_to_dut(duthost, nbrhosts):
return dut_nbrhosts


def initial_check_before_and_after_test(duthosts):
"""
@summary: Common method to make sure the supervisor and line cards are in normal state before and after the test
"""
for duthost in duthosts:
if duthost.is_supervisor_node():
# Initially make sure both supervisor and line cards are in BGP operational normal state
if get_tsa_chassisdb_config(duthost) != 'false' or get_sup_cfggen_tsa_value(duthost) != 'false':
duthost.shell('TSB')
duthost.shell('sudo config save -y')
pytest_assert('false' == get_tsa_chassisdb_config(duthost),
"Supervisor {} tsa_enabled config is enabled".format(duthost.hostname))

for linecard in duthosts.frontend_nodes:
# Issue TSB on the line card before proceeding further
if verify_dut_configdb_tsa_value(linecard) != 'false' or get_tsa_chassisdb_config(linecard) != 'false' or \
get_traffic_shift_state(linecard, cmd='TSC no-stats') != TS_NORMAL:
linecard.shell('TSB')
linecard.shell('sudo config save -y')
# Ensure that the DUT is not in maintenance already before start of the test
pytest_assert(TS_NORMAL == get_traffic_shift_state(linecard, cmd='TSC no-stats'),
"DUT is not in normal state")


def check_ssh_state(localhost, dut_ip, expected_state, timeout=60):
"""
Check the SSH state of DUT.
Expand Down Expand Up @@ -208,7 +184,7 @@ def test_tsa_tsb_service_with_dut_cold_reboot(duthosts, localhost, enum_rand_one
pytest.skip("TSA persistence not supported in the image")

# Initially make sure both supervisor and line cards are in BGP operational normal state
initial_check_before_and_after_test(duthosts)
initial_tsa_check_before_and_after_test(duthosts)

try:
# Get all routes on neighbors before doing reboot
Expand Down Expand Up @@ -272,7 +248,7 @@ def test_tsa_tsb_service_with_dut_cold_reboot(duthosts, localhost, enum_rand_one

finally:
# Bring back the supervisor and line cards to the BGP operational normal state
initial_check_before_and_after_test(duthosts)
initial_tsa_check_before_and_after_test(duthosts)
# Verify DUT is in normal state after cold reboot scenario.
if not (int_status_result and crit_process_check and TS_NORMAL == get_traffic_shift_state(duthost)):
logging.info("DUT is not in normal state after cold reboot, doing config-reload")
Expand Down Expand Up @@ -303,7 +279,7 @@ def test_tsa_tsb_service_with_dut_abnormal_reboot(duthosts, localhost, enum_rand
pytest.skip("TSA persistence not supported in the image")

# Initially make sure both supervisor and line cards are in BGP operational normal state
initial_check_before_and_after_test(duthosts)
initial_tsa_check_before_and_after_test(duthosts)

try:
# Get all routes on neighbors before doing reboot
Expand Down Expand Up @@ -383,7 +359,7 @@ def test_tsa_tsb_service_with_dut_abnormal_reboot(duthosts, localhost, enum_rand

finally:
# Bring back the supervisor and line cards to the BGP operational normal state
initial_check_before_and_after_test(duthosts)
initial_tsa_check_before_and_after_test(duthosts)
# Verify DUT is in normal state after abnormal reboot scenario.
if not (int_status_result and crit_process_check and TS_NORMAL == get_traffic_shift_state(duthost)):
logging.info("DUT is not in normal state after abnormal reboot, doing config-reload")
Expand Down Expand Up @@ -418,7 +394,7 @@ def test_tsa_tsb_service_with_supervisor_cold_reboot(duthosts, localhost, enum_s
if not check_tsa_persistence_support(linecard):
pytest.skip("TSA persistence not supported in the image")
# Initially make sure both supervisor and line cards are in BGP operational normal state
initial_check_before_and_after_test(duthosts)
initial_tsa_check_before_and_after_test(duthosts)

try:
for linecard in duthosts.frontend_nodes:
Expand Down Expand Up @@ -492,7 +468,7 @@ def test_tsa_tsb_service_with_supervisor_cold_reboot(duthosts, localhost, enum_s

finally:
# Bring back the supervisor and line cards to the BGP operational normal state
initial_check_before_and_after_test(duthosts)
initial_tsa_check_before_and_after_test(duthosts)

# Make sure DUT is in normal state after supervisor cold reboot
for linecard in duthosts.frontend_nodes:
Expand Down Expand Up @@ -540,7 +516,7 @@ def test_tsa_tsb_service_with_supervisor_abnormal_reboot(duthosts, localhost, en
pytest.skip("TSA persistence not supported in the image")

# Initially make sure both supervisor and line cards are in BGP operational normal state
initial_check_before_and_after_test(duthosts)
initial_tsa_check_before_and_after_test(duthosts)

try:
for linecard in duthosts.frontend_nodes:
Expand Down Expand Up @@ -635,7 +611,7 @@ def test_tsa_tsb_service_with_supervisor_abnormal_reboot(duthosts, localhost, en

finally:
# Bring back the supervisor and line cards to the BGP operational normal state
initial_check_before_and_after_test(duthosts)
initial_tsa_check_before_and_after_test(duthosts)

# Make sure DUT is in normal state after supervisor abnormal reboot
for linecard in duthosts.frontend_nodes:
Expand Down Expand Up @@ -677,7 +653,7 @@ def test_tsa_tsb_service_with_user_init_tsa(duthosts, localhost, enum_rand_one_p
pytest.skip("TSA persistence not supported in the image")

# Initially make sure both supervisor and line cards are in BGP operational normal state
initial_check_before_and_after_test(duthosts)
initial_tsa_check_before_and_after_test(duthosts)

try:
# Get all routes on neighbors before doing reboot
Expand Down Expand Up @@ -753,7 +729,7 @@ def test_tsa_tsb_service_with_user_init_tsa(duthosts, localhost, enum_rand_one_p
pytest_assert(reboot_cause == COLD_REBOOT_CAUSE,
"Reboot cause {} did not match the trigger {}".format(reboot_cause, COLD_REBOOT_CAUSE))
# Bring back the supervisor and line cards to the BGP operational normal state
initial_check_before_and_after_test(duthosts)
initial_tsa_check_before_and_after_test(duthosts)


@pytest.mark.disable_loganalyzer
Expand All @@ -777,7 +753,7 @@ def test_user_init_tsa_while_service_run_on_dut(duthosts, localhost, enum_rand_o
pytest.skip("TSA persistence not supported in the image")

# Initially make sure both supervisor and line cards are in BGP operational normal state
initial_check_before_and_after_test(duthosts)
initial_tsa_check_before_and_after_test(duthosts)

try:
# Get all routes on neighbors before doing reboot
Expand Down Expand Up @@ -861,7 +837,7 @@ def test_user_init_tsa_while_service_run_on_dut(duthosts, localhost, enum_rand_o
pytest_assert(reboot_cause == COLD_REBOOT_CAUSE,
"Reboot cause {} did not match the trigger {}".format(reboot_cause, COLD_REBOOT_CAUSE))
# Bring back the supervisor and line cards to the BGP operational normal state
initial_check_before_and_after_test(duthosts)
initial_tsa_check_before_and_after_test(duthosts)


@pytest.mark.disable_loganalyzer
Expand All @@ -884,7 +860,7 @@ def test_user_init_tsb_while_service_run_on_dut(duthosts, localhost, enum_rand_o
pytest.skip("TSA persistence not supported in the image")

# Initially make sure both supervisor and line cards are in BGP operational normal state
initial_check_before_and_after_test(duthosts)
initial_tsa_check_before_and_after_test(duthosts)

try:
# Get all routes on neighbors before doing reboot
Expand Down Expand Up @@ -948,7 +924,7 @@ def test_user_init_tsb_while_service_run_on_dut(duthosts, localhost, enum_rand_o

finally:
# Bring back the supervisor and line cards to the BGP operational normal state
initial_check_before_and_after_test(duthosts)
initial_tsa_check_before_and_after_test(duthosts)
# Verify DUT is in normal state after cold reboot scenario.
if not (int_status_result and crit_process_check and TS_NORMAL == get_traffic_shift_state(duthost)):
logging.info("DUT is not in normal state after cold reboot, doing config-reload")
Expand Down Expand Up @@ -988,7 +964,7 @@ def test_user_init_tsb_on_sup_while_service_run_on_dut(duthosts, localhost,
pytest.skip("TSA persistence not supported in the image")

# Initially make sure both supervisor and line cards are in BGP operational normal state
initial_check_before_and_after_test(duthosts)
initial_tsa_check_before_and_after_test(duthosts)

try:
for linecard in duthosts.frontend_nodes:
Expand Down Expand Up @@ -1069,7 +1045,7 @@ def test_user_init_tsb_on_sup_while_service_run_on_dut(duthosts, localhost,

finally:
# Bring back the supervisor and line cards to the BGP operational normal state
initial_check_before_and_after_test(duthosts)
initial_tsa_check_before_and_after_test(duthosts)

for linecard in duthosts.frontend_nodes:
# Make sure linecards are in Normal state and save the config to proceed further
Expand Down Expand Up @@ -1107,7 +1083,7 @@ def test_tsa_tsb_timer_efficiency(duthosts, localhost, enum_rand_one_per_hwsku_f
pytest.skip("TSA persistence not supported in the image")

# Initially make sure both supervisor and line cards are in BGP operational normal state
initial_check_before_and_after_test(duthosts)
initial_tsa_check_before_and_after_test(duthosts)

try:
# Get all routes on neighbors before doing reboot
Expand Down Expand Up @@ -1185,7 +1161,7 @@ def test_tsa_tsb_timer_efficiency(duthosts, localhost, enum_rand_one_per_hwsku_f

finally:
# Bring back the supervisor and line cards to the BGP operational normal state
initial_check_before_and_after_test(duthosts)
initial_tsa_check_before_and_after_test(duthosts)
# Verify DUT is in normal state after cold reboot scenario.
if not (int_status_result and crit_process_check and TS_NORMAL == get_traffic_shift_state(duthost)):
logging.info("DUT is not in normal state after cold reboot, doing config-reload")
Expand Down
Loading

0 comments on commit bb71883

Please sign in to comment.