diff --git a/tests/common/fixtures/ptfhost_utils.py b/tests/common/fixtures/ptfhost_utils.py index b54a6304de5..995c6c7cb85 100644 --- a/tests/common/fixtures/ptfhost_utils.py +++ b/tests/common/fixtures/ptfhost_utils.py @@ -1,4 +1,5 @@ import os +from natsort import natsorted import pytest import logging @@ -120,3 +121,32 @@ def copy_arp_responder_py(ptfhost): logger.info("Delete arp_responder.py from ptfhost '{0}'".format(ptfhost.hostname)) ptfhost.file(path=os.path.join(OPT_DIR, ARP_RESPONDER_PY), state="absent") + +@pytest.fixture(scope='class') +def ptf_portmap_file(duthost, ptfhost): + """ + Prepare and copys port map file to PTF host + + Args: + request (Fixture): pytest request object + duthost (AnsibleHost): Device Under Test (DUT) + ptfhost (AnsibleHost): Packet Test Framework (PTF) + + Returns: + filename (str): returns the filename copied to PTF host + """ + intfInfo = duthost.show_interface(command = "status")['ansible_facts']['int_status'] + portList = natsorted([port for port in intfInfo if port.startswith('Ethernet') and intfInfo[port]['speed'] != '10G']) + portMapFile = "/tmp/default_interface_to_front_map.ini" + with open(portMapFile, 'w') as file: + file.write("# ptf host interface @ switch front port name\n") + file.writelines( + map( + lambda (index, port): "{0}@{1}\n".format(index, port), + enumerate(portList) + ) + ) + + ptfhost.copy(src=portMapFile, dest="/root/") + + yield "/root/{}".format(portMapFile.split('/')[-1]) diff --git a/tests/qos/qos_sai_base.py b/tests/qos/qos_sai_base.py index b3c002b2dbd..1c7f0068d3f 100644 --- a/tests/qos/qos_sai_base.py +++ b/tests/qos/qos_sai_base.py @@ -4,7 +4,7 @@ import re import yaml -from natsort import natsorted +from tests.common.fixtures.ptfhost_utils import ptf_portmap_file # lgtm[py/unused-import] from tests.common.mellanox_data import is_mellanox_device as isMellanoxDevice from tests.common.system_utils import docker @@ -20,7 +20,6 @@ class QosSaiBase: TARGET_QUEUE_WRED = 3 TARGET_LOSSY_QUEUE_SCHED = 0 TARGET_LOSSLESS_QUEUE_SCHED = 3 - DEFAULT_PORT_INDEX_TO_ALIAS_MAP_FILE = "/tmp/default_interface_to_front_map.ini" def __runRedisCommandOrAssert(self, duthost, argv=[]): """ @@ -569,37 +568,8 @@ def dutQosConfig(self, duthost, ingressLosslessProfile, ingressLossyProfile, egr "portSpeedCableLength": portSpeedCableLength, } - @pytest.fixture(scope='class') - def ptfPortMapFile(self, duthost, ptfhost): - """ - Prepare and copys port map file to PTF host - - Args: - request (Fixture): pytest request object - duthost (AnsibleHost): Device Under Test (DUT) - ptfhost (AnsibleHost): Packet Test Framework (PTF) - - Returns: - filename (str): returns the filename copied to PTF host - """ - intfInfo = duthost.show_interface(command = "status")['ansible_facts']['int_status'] - portList = natsorted([port for port in intfInfo if port.startswith('Ethernet') and intfInfo[port]['speed'] != '10G']) - portMapFile = self.DEFAULT_PORT_INDEX_TO_ALIAS_MAP_FILE - with open(portMapFile, 'w') as file: - file.write("# ptf host interface @ switch front port name\n") - file.writelines( - map( - lambda (index, port): "{0}@{1}\n".format(index, port), - enumerate(portList) - ) - ) - - ptfhost.copy(src=portMapFile, dest="/root/") - - yield "/root/{}".format(portMapFile.split('/')[-1]) - @pytest.fixture(scope='class', autouse=True) - def dutTestParams(self, duthost, tbinfo, ptfPortMapFile): + def dutTestParams(self, duthost, tbinfo, ptf_portmap_file): """ Prepares DUT host test params @@ -621,7 +591,7 @@ def dutTestParams(self, duthost, tbinfo, ptfPortMapFile): "basicParams": { "router_mac": '' if topo in self.SUPPORTED_T0_TOPOS else dutFacts['ansible_Ethernet0']['macaddress'], "server": duthost.host.options['inventory_manager'].get_host(duthost.hostname).vars['ansible_host'], - "port_map_file": ptfPortMapFile, + "port_map_file": ptf_portmap_file, "sonic_asic_type": duthost.facts['asic_type'], } } diff --git a/tests/qos/test_qos_sai.py b/tests/qos/test_qos_sai.py index 905cf16b979..3a43365f4e8 100644 --- a/tests/qos/test_qos_sai.py +++ b/tests/qos/test_qos_sai.py @@ -23,6 +23,7 @@ from tests.common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm[py/unused-import] from tests.common.fixtures.ptfhost_utils import copy_saitests_directory # lgtm[py/unused-import] from tests.common.fixtures.ptfhost_utils import change_mac_addresses # lgtm[py/unused-import] +from tests.common.fixtures.ptfhost_utils import ptf_portmap_file # lgtm[py/unused-import] from qos_sai_base import QosSaiBase logger = logging.getLogger(__name__)