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

[action] [PR:9262] [drop_packets]: Fix to support testbed with different hwsku with different asic count #9669

Merged
merged 1 commit into from
Aug 28, 2023
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
54 changes: 30 additions & 24 deletions tests/common/helpers/drop_counters/drop_counters.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,40 +23,46 @@
COMBINED_ACL_DROP_COUNTER = False


def get_pkt_drops(duthost, cli_cmd, asic_index):
def get_pkt_drops(duthost, cli_cmd, asic_index=None):
"""
@summary: Parse output of "portstat" or "intfstat" commands and convert it to the dictionary.
@param module: The AnsibleModule object
@param cli_cmd: one of supported CLI commands - "portstat -j" or "intfstat -j"
@return: Return dictionary of parsed counters
"""
# Get namespace from asic_index.
namespace = duthost.get_namespace_from_asic_id(asic_index)
result = {}
for asic_id in duthost.get_asic_ids():
if asic_index is not None and asic_index != asic_id:
continue
namespace = duthost.get_namespace_from_asic_id(asic_id)

# Frame the correct cli command
# the L2 commands need _SUFFIX and L3 commands need _PREFIX
if cli_cmd == GET_L3_COUNTERS:
CMD_PREFIX = NAMESPACE_PREFIX if (namespace is not None and duthost.is_multi_asic) else ''
cli_cmd = CMD_PREFIX + cli_cmd
elif cli_cmd == GET_L2_COUNTERS:
CMD_SUFFIX = NAMESPACE_SUFFIX if (namespace is not None and duthost.is_multi_asic) else ''
cli_cmd = cli_cmd + CMD_SUFFIX
# Frame the correct cli command
# the L2 commands need _SUFFIX and L3 commands need _PREFIX
if cli_cmd == GET_L3_COUNTERS:
CMD_PREFIX = NAMESPACE_PREFIX if (namespace is not None and duthost.is_multi_asic) else ''
cli_cmd = CMD_PREFIX + cli_cmd
elif cli_cmd == GET_L2_COUNTERS:
CMD_SUFFIX = NAMESPACE_SUFFIX if (namespace is not None and duthost.is_multi_asic) else ''
cli_cmd = cli_cmd + CMD_SUFFIX

stdout = duthost.command(cli_cmd.format(namespace))
stdout = stdout["stdout"]
match = re.search("Last cached time was.*\n", stdout)
if match:
stdout = re.sub("Last cached time was.*\n", "", stdout)
stdout = duthost.command(cli_cmd.format(namespace))
stdout = stdout["stdout"]
match = re.search("Last cached time was.*\n", stdout)
if match:
stdout = re.sub("Last cached time was.*\n", "", stdout)

try:
return json.loads(stdout)
except Exception as err:
raise Exception("Failed to parse output of '{}', err={}".format(cli_cmd, str(err)))
try:
namespace_result = json.loads(stdout)
result.update(namespace_result)
except Exception as err:
raise Exception("Failed to parse output of '{}', err={}".format(cli_cmd, str(err)))
return result


def ensure_no_l3_drops(duthost, asic_index, packets_count):
def ensure_no_l3_drops(duthost, packets_count):
""" Verify L3 drop counters were not incremented """
intf_l3_counters = get_pkt_drops(duthost, GET_L3_COUNTERS, asic_index)
intf_l3_counters = get_pkt_drops(duthost, GET_L3_COUNTERS)
unexpected_drops = {}
for iface, value in intf_l3_counters.items():
try:
Expand All @@ -70,9 +76,9 @@ def ensure_no_l3_drops(duthost, asic_index, packets_count):
pytest.fail("L3 'RX_ERR' was incremented for the following interfaces:\n{}".format(unexpected_drops))


def ensure_no_l2_drops(duthost, asic_index, packets_count):
def ensure_no_l2_drops(duthost, packets_count):
""" Verify L2 drop counters were not incremented """
intf_l2_counters = get_pkt_drops(duthost, GET_L2_COUNTERS, asic_index)
intf_l2_counters = get_pkt_drops(duthost, GET_L2_COUNTERS)
unexpected_drops = {}
for iface, value in intf_l2_counters.items():
try:
Expand All @@ -91,7 +97,7 @@ def verify_drop_counters(duthosts, asic_index, dut_iface, get_cnt_cli_cmd, colum
def get_drops_across_all_duthosts():
drop_list = []
for duthost in duthosts.frontend_nodes:
pkt_drops = get_pkt_drops(duthost, get_cnt_cli_cmd, asic_index)
pkt_drops = get_pkt_drops(duthost, get_cnt_cli_cmd)
# we cannot assume the iface name will be same on all the devices for SONiC chassis
# if the dut_iface is not found ignore this device
if dut_iface not in pkt_drops:
Expand Down
14 changes: 7 additions & 7 deletions tests/drop_packets/test_drop_counters.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,19 @@ def base_verification(discard_group, pkt, ptfadapter, duthosts, asic_index, port
if discard_group == "L2":
verify_drop_counters(duthosts, asic_index, ports_info["dut_iface"], GET_L2_COUNTERS, L2_COL_KEY, packets_count=PKT_NUMBER)
for duthost in duthosts.frontend_nodes:
ensure_no_l3_drops(duthost, asic_index, packets_count=PKT_NUMBER)
ensure_no_l3_drops(duthost, packets_count=PKT_NUMBER)
elif discard_group == "L3":
if COMBINED_L2L3_DROP_COUNTER:
verify_drop_counters(duthosts, asic_index, ports_info["dut_iface"], GET_L2_COUNTERS, L2_COL_KEY, packets_count=PKT_NUMBER)
for duthost in duthosts.frontend_nodes:
ensure_no_l3_drops(duthost, asic_index, packets_count=PKT_NUMBER)
ensure_no_l3_drops(duthost, packets_count=PKT_NUMBER)
else:
if not tx_dut_ports:
pytest.fail("No L3 interface specified")

verify_drop_counters(duthosts, asic_index, tx_dut_ports[ports_info["dut_iface"]], GET_L3_COUNTERS, L3_COL_KEY, packets_count=PKT_NUMBER)
for duthost in duthosts.frontend_nodes:
ensure_no_l2_drops(duthost, asic_index, packets_count=PKT_NUMBER)
ensure_no_l2_drops(duthost, packets_count=PKT_NUMBER)
elif discard_group == "ACL":
if not tx_dut_ports:
pytest.fail("No L3 interface specified")
Expand All @@ -150,12 +150,12 @@ def base_verification(discard_group, pkt, ptfadapter, duthosts, asic_index, port
pytest.fail(fail_msg)
if not COMBINED_ACL_DROP_COUNTER:
for duthost in duthosts.frontend_nodes:
ensure_no_l3_drops(duthost, asic_index, packets_count=PKT_NUMBER)
ensure_no_l2_drops(duthost, asic_index, packets_count=PKT_NUMBER)
ensure_no_l3_drops(duthost, packets_count=PKT_NUMBER)
ensure_no_l2_drops(duthost, packets_count=PKT_NUMBER)
elif discard_group == "NO_DROPS":
for duthost in duthosts.frontend_nodes:
ensure_no_l2_drops(duthost, asic_index, packets_count=PKT_NUMBER)
ensure_no_l3_drops(duthost, asic_index, packets_count=PKT_NUMBER)
ensure_no_l2_drops(duthost, packets_count=PKT_NUMBER)
ensure_no_l3_drops(duthost, packets_count=PKT_NUMBER)
else:
pytest.fail("Incorrect 'discard_group' specified. Supported values: 'L2', 'L3', 'ACL' or 'NO_DROPS'")

Expand Down