Skip to content

Commit

Permalink
Upstream arp/test_stress_arp.py changes to 202311 branch (sonic-net#1…
Browse files Browse the repository at this point in the history
…4419)

There are 3 issues with arp/test_stress_arp.py:

It is doing a redundant subtraction.
In both variants, it calculates space available as (available - used)
instead of (total size - used), giving an incorrect value for available
space.

Not enough allowance/wiggle room for hash collision.
In both variants, it expects only 100 hash collisions which is very
little. For specific SKUs, there may be a further performance impact as
some hash functions is not as performant for incremental values, which
is what is used for this test.

The test will crash if cleanup fails.
Sometimes arp cache cleanup will fail if it is done too often. Allowing the
test to continue after the failure as the failure is unrelated to the test and
being unable to clean implies it is clean.

This patch fixes these 3 issues by:

- Removing the redundant subtraction.
- Change hash collision allowance from 100 to 250.
- Add a catch for failing clear_dut_arp_cache().
  • Loading branch information
justin-wong-ce authored Sep 5, 2024
1 parent f5568a5 commit 6657387
Showing 1 changed file with 55 additions and 13 deletions.
68 changes: 55 additions & 13 deletions tests/arp/test_stress_arp.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
in6_getnsma, inet_pton, inet_ntop, socket
from ipaddress import ip_address, ip_network
from tests.common.utilities import wait_until
from tests.common.errors import RunAnsibleModuleFail

ARP_BASE_IP = "172.16.0.1/16"
ARP_SRC_MAC = "00:00:01:02:03:04"
Expand All @@ -29,6 +30,34 @@
}


@pytest.fixture(autouse=True)
def arp_cache_fdb_cleanup(duthost):
try:
clear_dut_arp_cache(duthost)
fdb_cleanup(duthost)
except RunAnsibleModuleFail as e:
if 'Failed to send flush request: No such file or directory' in str(e):
logger.warning("Failed to clear arp cache or cleanup fdb table, file may not exist yet")
else:
raise e

time.sleep(5)

yield

# Ensure clean test environment even after failing
try:
clear_dut_arp_cache(duthost)
fdb_cleanup(duthost)
except RunAnsibleModuleFail as e:
if 'Failed to send flush request: No such file or directory' in str(e):
logger.warning("Failed to clear arp cache or cleanup fdb table, file may not exist yet")
else:
raise e

time.sleep(10)


def add_arp(ptf_intf_ipv4_addr, intf1_index, ptfadapter):
ip_num = 0
for arp_request_ip in ptf_intf_ipv4_addr:
Expand Down Expand Up @@ -66,10 +95,8 @@ def test_ipv4_arp(duthost, garp_enabled, ip_and_intf_info, intfs_for_test,
if normalized_level is None:
normalized_level = "debug"

ipv4_avaliable = get_crm_resources(duthost, "ipv4_neighbor", "available") - \
get_crm_resources(duthost, "ipv4_neighbor", "used")
fdb_avaliable = get_crm_resources(duthost, "fdb_entry", "available") - \
get_crm_resources(duthost, "fdb_entry", "used")
ipv4_avaliable = get_crm_resources(duthost, "ipv4_neighbor", "available")
fdb_avaliable = get_crm_resources(duthost, "fdb_entry", "available")
pytest_assert(ipv4_avaliable > 0 and fdb_avaliable > 0, "Entries have been filled")

arp_avaliable = min(min(ipv4_avaliable, fdb_avaliable), ENTRIES_NUMBERS)
Expand All @@ -90,11 +117,17 @@ def test_ipv4_arp(duthost, garp_enabled, ip_and_intf_info, intfs_for_test,
logger.debug("Expected route number: {}, real route number {}"
.format(arp_avaliable, get_fdb_dynamic_mac_count(duthost)))
pytest_assert(wait_until(20, 1, 0,
lambda: abs(arp_avaliable - get_fdb_dynamic_mac_count(duthost)) < 100),
lambda: abs(arp_avaliable - get_fdb_dynamic_mac_count(duthost)) < 250),
"ARP Table Add failed")

clear_dut_arp_cache(duthost)
fdb_cleanup(duthost)
try:
clear_dut_arp_cache(duthost)
fdb_cleanup(duthost)
except RunAnsibleModuleFail as e:
if 'Failed to send flush request: No such file or directory' in str(e):
logger.warning("Failed to clear arp cache or cleanup fdb table, file may not exist yet")
else:
raise e

time.sleep(5)

Expand Down Expand Up @@ -150,9 +183,11 @@ def test_ipv6_nd(duthost, ptfhost, config_facts, tbinfo, ip_and_intf_info,
normalized_level = "debug"

loop_times = LOOP_TIMES_LEVEL_MAP[normalized_level]
ipv6_avaliable = get_crm_resources(duthost, "ipv6_neighbor", "available") - \
get_crm_resources(duthost, "ipv6_neighbor", "used")
nd_avaliable = min(ipv6_avaliable, ENTRIES_NUMBERS)
ipv6_avaliable = get_crm_resources(duthost, "ipv6_neighbor", "available")
fdb_avaliable = get_crm_resources(duthost, "fdb_entry", "available")
pytest_assert(ipv6_avaliable > 0 and fdb_avaliable > 0, "Entries have been filled")

nd_avaliable = min(min(ipv6_avaliable, fdb_avaliable), ENTRIES_NUMBERS)

while loop_times > 0:
loop_times -= 1
Expand All @@ -163,10 +198,17 @@ def test_ipv6_nd(duthost, ptfhost, config_facts, tbinfo, ip_and_intf_info,
logger.debug("Expected route number: {}, real route number {}"
.format(nd_avaliable, get_fdb_dynamic_mac_count(duthost)))
pytest_assert(wait_until(20, 1, 0,
lambda: abs(nd_avaliable - get_fdb_dynamic_mac_count(duthost)) < 100),
lambda: abs(nd_avaliable - get_fdb_dynamic_mac_count(duthost)) < 250),
"Neighbor Table Add failed")

clear_dut_arp_cache(duthost)
fdb_cleanup(duthost)
try:
clear_dut_arp_cache(duthost)
fdb_cleanup(duthost)
except RunAnsibleModuleFail as e:
if 'Failed to send flush request: No such file or directory' in str(e):
logger.warning("Failed to clear arp cache or cleanup fdb table, file may not exist yet")
else:
raise e

# Wait for 10 seconds before starting next loop
time.sleep(10)

0 comments on commit 6657387

Please sign in to comment.