From 706d58367c6a38207377f03924f0a9ea75079c94 Mon Sep 17 00:00:00 2001 From: Vinod Kumar Date: Tue, 4 Jun 2024 09:04:03 -0700 Subject: [PATCH 1/2] Fix qos/test_qos_dscp_mapping.py This test is mainly failing due to: - Sending 10K packets at once on a ptf interface is causing nnpy socket to be non-functional for a moment sometimes and connection is getting timedout. - Sometimes egress_queue_count on queue 7 is way greater than no of packets being sent and the queue_count is not within the TOLERANCE, this could be due to protocol packets. - Test is not enhanced to be run on dualtor topologies (packets are going to unexpected ToR). - Fixtures "upstream_links" and "downstream_links" are always referring to upper ToR, thus return values of these fixtures is not really considering the ToR type and causing failures. --- tests/common/helpers/ptf_tests_helper.py | 10 +++++---- tests/qos/test_qos_dscp_mapping.py | 27 ++++++++++++++++++------ 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/tests/common/helpers/ptf_tests_helper.py b/tests/common/helpers/ptf_tests_helper.py index 38a7a1b829a..de6e8fbc5c8 100644 --- a/tests/common/helpers/ptf_tests_helper.py +++ b/tests/common/helpers/ptf_tests_helper.py @@ -14,17 +14,18 @@ @pytest.fixture(scope="module") -def downstream_links(duthost, tbinfo): +def downstream_links(rand_selected_dut, tbinfo): """ Returns a dictionary of all the links that are downstream from the DUT. Args: - duthost: DUT fixture + rand_selected_dut: DUT fixture tbinfo: testbed information fixture Returns: links: Dictionary of links downstream from the DUT """ links = dict() + duthost = rand_selected_dut def filter(interface, neighbor, mg_facts, tbinfo): if ((tbinfo["topo"]["type"] == "t0" and "Server" in neighbor["name"]) @@ -41,18 +42,19 @@ def filter(interface, neighbor, mg_facts, tbinfo): @pytest.fixture(scope="module") -def upstream_links(duthost, tbinfo, nbrhosts): +def upstream_links(rand_selected_dut, tbinfo, nbrhosts): """ Returns a dictionary of all the links that are upstream from the DUT. Args: - duthost: DUT fixture + rand_selected_dut: DUT fixture tbinfo: testbed information fixture nbrhosts: neighbor host fixture Returns: links: Dictionary of links upstream from the DUT """ links = dict() + duthost = rand_selected_dut def filter(interface, neighbor, mg_facts, tbinfo): if ((tbinfo["topo"]["type"] == "t0" and "T1" in neighbor["name"]) diff --git a/tests/qos/test_qos_dscp_mapping.py b/tests/qos/test_qos_dscp_mapping.py index 17237743457..b5bdb810252 100644 --- a/tests/qos/test_qos_dscp_mapping.py +++ b/tests/qos/test_qos_dscp_mapping.py @@ -11,6 +11,7 @@ from scapy.all import Ether, IP from tabulate import tabulate +from tests.common.dualtor.mux_simulator_control import toggle_all_simulator_ports_to_rand_selected_tor from tests.common.helpers.ptf_tests_helper import downstream_links, upstream_links, select_random_link,\ get_stream_ptf_ports, get_dut_pair_port_from_ptf_port, apply_dscp_cfg_setup, apply_dscp_cfg_teardown # noqa F401 from tests.common.utilities import get_ipv4_loopback_ip, get_dscp_to_queue_value, find_egress_queue,\ @@ -27,8 +28,7 @@ DEFAULT_DSCP = 4 DEFAULT_TTL = 64 DEFAULT_ECN = 1 -DEFAULT_PKT_COUNT = 10000 -TOLERANCE = 0.05 * DEFAULT_PKT_COUNT # Account for noise and polling delays +DEFAULT_PKT_COUNT = 2000 DUMMY_OUTER_SRC_IP = '8.8.8.8' DUMMY_INNER_SRC_IP = '9.9.9.9' DUMMY_INNER_DST_IP = '10.10.10.10' @@ -271,8 +271,9 @@ def _run_test(self, ptf_src_port_id=ptf_src_port_id, ptf_dst_port_ids=ptf_dst_port_ids) - except Exception as e: - logger.error(str(e)) + except ConnectionError as e: + # Sending large number of packets can cause socket buffer to be full and leads connection timeout. + logger.error("{}: Try reducing DEFAULT_PKT_COUNT value".format(str(e))) failed_once = True global packet_egressed_success @@ -285,7 +286,8 @@ def _run_test(self, time.sleep(2) egress_queue_count, egress_queue_val = find_queue_count_and_value(duthost, queue_val, dut_egress_port) - verification_success = abs(egress_queue_count - DEFAULT_PKT_COUNT) < TOLERANCE + # Due to protocol packets, egress_queue_count can be greater than expected count. + verification_success = egress_queue_count >= DEFAULT_PKT_COUNT if verification_success: logger.info("SUCCESS: Received expected number of packets on queue {}".format(queue_val)) @@ -311,6 +313,7 @@ def _run_test(self, failed_once = True else: output_table.append([rotating_dscp, queue_val, 0, "FAILURE - NO PACKETS EGRESSED", "N/A"]) + failed_once = True # Reset packet egress status packet_egressed_success = False @@ -319,6 +322,8 @@ def _run_test(self, .format(tabulate(output_table, headers=["Inner Packet DSCP Value", "Expected Egress Queue", "Egress Queue Count", "Result", "Actual Egress Queue"]))) + # Clear the output_table (for next test functions). + output_table = [] pytest_assert(not failed_once, "FAIL: Test failed. Please check table for details.") @@ -331,18 +336,26 @@ def _teardown_test(self, duthost): """ apply_dscp_cfg_teardown(duthost) - def test_dscp_to_queue_mapping_pipe_mode(self, ptfadapter, duthost, tbinfo, downstream_links, upstream_links, dut_qos_maps_module): # noqa F811 + def test_dscp_to_queue_mapping_pipe_mode(self, ptfadapter, rand_selected_dut, + toggle_all_simulator_ports_to_rand_selected_tor, + setup_standby_ports_on_rand_unselected_tor, + tbinfo, downstream_links, upstream_links, dut_qos_maps_module): # noqa F811 """ Test QoS SAI DSCP to queue mapping for IP-IP packets in DSCP "pipe" mode """ + duthost = rand_selected_dut test_params = self._setup_test_params(duthost, downstream_links, upstream_links, "pipe") self._run_test(ptfadapter, duthost, tbinfo, test_params, dut_qos_maps_module, "pipe") self._teardown_test(duthost) - def test_dscp_to_queue_mapping_uniform_mode(self, ptfadapter, duthost, tbinfo, downstream_links, upstream_links, dut_qos_maps_module): # noqa F811 + def test_dscp_to_queue_mapping_uniform_mode(self, ptfadapter, rand_selected_dut, + toggle_all_simulator_ports_to_rand_selected_tor, + setup_standby_ports_on_rand_unselected_tor, + tbinfo, downstream_links, upstream_links, dut_qos_maps_module): # noqa F811 """ Test QoS SAI DSCP to queue mapping for IP-IP packets in DSCP "uniform" mode """ + duthost = rand_selected_dut test_params = self._setup_test_params(duthost, downstream_links, upstream_links, "uniform") self._run_test(ptfadapter, duthost, tbinfo, test_params, dut_qos_maps_module, "uniform") self._teardown_test(duthost) From 9508accebdbec3ddc16bc51e1abb9252b439cc28 Mon Sep 17 00:00:00 2001 From: Vinod Kumar Date: Tue, 4 Jun 2024 20:20:49 -0700 Subject: [PATCH 2/2] Fix pre-commit check failures pre-commit check is being failed with "toggle_all_simulator_ports_to_rand_selected_tor" imported but unused error. Added "# noqa" to suppress this failure as this import is being used as fixture argument (similar to other tests). --- tests/qos/test_qos_dscp_mapping.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/qos/test_qos_dscp_mapping.py b/tests/qos/test_qos_dscp_mapping.py index b5bdb810252..c4c9f40c684 100644 --- a/tests/qos/test_qos_dscp_mapping.py +++ b/tests/qos/test_qos_dscp_mapping.py @@ -11,7 +11,7 @@ from scapy.all import Ether, IP from tabulate import tabulate -from tests.common.dualtor.mux_simulator_control import toggle_all_simulator_ports_to_rand_selected_tor +from tests.common.dualtor.mux_simulator_control import toggle_all_simulator_ports_to_rand_selected_tor # noqa F401 from tests.common.helpers.ptf_tests_helper import downstream_links, upstream_links, select_random_link,\ get_stream_ptf_ports, get_dut_pair_port_from_ptf_port, apply_dscp_cfg_setup, apply_dscp_cfg_teardown # noqa F401 from tests.common.utilities import get_ipv4_loopback_ip, get_dscp_to_queue_value, find_egress_queue,\ @@ -337,7 +337,7 @@ def _teardown_test(self, duthost): apply_dscp_cfg_teardown(duthost) def test_dscp_to_queue_mapping_pipe_mode(self, ptfadapter, rand_selected_dut, - toggle_all_simulator_ports_to_rand_selected_tor, + toggle_all_simulator_ports_to_rand_selected_tor, # noqa F811 setup_standby_ports_on_rand_unselected_tor, tbinfo, downstream_links, upstream_links, dut_qos_maps_module): # noqa F811 """ @@ -349,7 +349,7 @@ def test_dscp_to_queue_mapping_pipe_mode(self, ptfadapter, rand_selected_dut, self._teardown_test(duthost) def test_dscp_to_queue_mapping_uniform_mode(self, ptfadapter, rand_selected_dut, - toggle_all_simulator_ports_to_rand_selected_tor, + toggle_all_simulator_ports_to_rand_selected_tor, # noqa F811 setup_standby_ports_on_rand_unselected_tor, tbinfo, downstream_links, upstream_links, dut_qos_maps_module): # noqa F811 """