Skip to content

Commit

Permalink
Add dualtor standby drop test and check dhcpmon count based on number…
Browse files Browse the repository at this point in the history
… of dhcp servers configured (sonic-net#9088)
  • Loading branch information
kellyyeh authored and mssonicbld committed Aug 3, 2023
1 parent e45ba21 commit 86c446b
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions tests/dhcp_relay/test_dhcp_relay.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ def testing_config(request, duthosts, rand_one_dut_hostname, tbinfo):
if testing_mode == DUAL_TOR_MODE:
pytest.skip("skip DUAL_TOR_MODE tests on t0-56-vlan2po testbeds")
else:
if testing_mode == DUAL_TOR_MODE:
pytest.skip("skip DUAL_TOR_MODE tests on Single ToR testbeds")

if testing_mode == SINGLE_TOR_MODE:
if subtype_exist:
duthost.shell('redis-cli -n 4 HDEL "DEVICE_METADATA|localhost" "subtype"')
Expand Down Expand Up @@ -287,31 +290,43 @@ def start_dhcp_monitor_debug_counter(duthost):


def test_dhcp_relay_default(ptfhost, dut_dhcp_relay_data, validate_dut_routes_exist, testing_config,
toggle_all_simulator_ports_to_rand_selected_tor_m): # noqa F811
rand_unselected_dut, toggle_all_simulator_ports_to_rand_selected_tor_m): # noqa F811
"""Test DHCP relay functionality on T0 topology.
For each DHCP relay agent running on the DuT, verify DHCP packets are relayed properly
"""

testing_mode, duthost, testbed_mode = testing_config

if testing_mode == DUAL_TOR_MODE:
skip_release(duthost, ["201811", "201911"])

skip_dhcpmon = (testing_mode == DUAL_TOR_MODE or
any(vers in duthost.os_version for vers in ["201811", "201911", "202111"]))
skip_dhcpmon = any(vers in duthost.os_version for vers in ["201811", "201911", "202111"])

try:
for dhcp_relay in dut_dhcp_relay_data:
if not skip_dhcpmon:
dhcp_server_num = len(dhcp_relay['downlink_vlan_iface']['dhcp_server_addrs'])
if testing_mode == DUAL_TOR_MODE:
standby_duthost = rand_unselected_dut
start_dhcp_monitor_debug_counter(standby_duthost)
expected_standby_agg_counter_message = (
r".*dhcp_relay#dhcpmon\[[0-9]+\]: "
r"\[\s*Agg-%s\s*-[\sA-Za-z0-9]+\s*rx/tx\] "
r"Discover: +0/ +0, Offer: +0/ +0, Request: +0/ +0, ACK: +0/ +0+"
) % (dhcp_relay['downlink_vlan_iface']['name'])
loganalyzer_standby = LogAnalyzer(ansible_host=standby_duthost, marker_prefix="dhcpmon counter")
marker_standby = loganalyzer_standby.init()
loganalyzer_standby.expect_regex = [expected_standby_agg_counter_message]
start_dhcp_monitor_debug_counter(duthost)
expected_agg_counter_message = (
r".*dhcp_relay#dhcpmon\[[0-9]+\]: "
r"\[\s*Agg-%s\s*-[\sA-Za-z0-9]+\s*rx/tx\] "
r"Discover: +1/ +4, Offer: +1/ +1, Request: +3/ +12, ACK: +1/ +1+"
) % dhcp_relay['downlink_vlan_iface']['name']
r"Discover: +1/ +%d, Offer: +1/ +1, Request: +3/ +%d, ACK: +1/ +1+"
) % (dhcp_relay['downlink_vlan_iface']['name'], dhcp_server_num, dhcp_server_num * 3)
loganalyzer = LogAnalyzer(ansible_host=duthost, marker_prefix="dhcpmon counter")
loganalyzer.expect_regex = []
marker = loganalyzer.init()
loganalyzer.expect_regex = [expected_agg_counter_message]

# Run the DHCP relay test on the PTF host
ptf_runner(ptfhost,
"ptftests",
Expand Down Expand Up @@ -339,13 +354,19 @@ def test_dhcp_relay_default(ptfhost, dut_dhcp_relay_data, validate_dut_routes_ex
if not skip_dhcpmon:
time.sleep(18) # dhcpmon debug counter prints every 18 seconds
loganalyzer.analyze(marker)
if testing_mode == DUAL_TOR_MODE:
loganalyzer_standby.analyze(marker_standby)
except LogAnalyzerError as err:
logger.error("Unable to find expected log in syslog")
raise err

# Clean up - Restart DHCP relay service on DUT to recover original dhcpmon setting
restart_dhcp_service(duthost)
pytest_assert(wait_until(120, 5, 0, check_interface_status, duthost))
if not skip_dhcpmon:
# Clean up - Restart DHCP relay service on DUT to recover original dhcpmon setting
restart_dhcp_service(duthost)
if testing_mode == DUAL_TOR_MODE:
restart_dhcp_service(standby_duthost)
pytest_assert(wait_until(120, 5, 0, check_interface_status, standby_duthost))
pytest_assert(wait_until(120, 5, 0, check_interface_status, duthost))


def test_dhcp_relay_after_link_flap(ptfhost, dut_dhcp_relay_data, validate_dut_routes_exist, testing_config):
Expand Down

0 comments on commit 86c446b

Please sign in to comment.