Exemple #1
0
def setup(request, duthosts, enum_rand_one_per_hwsku_hostname, xcvr_skip_list, conn_graph_facts, shutdown_ebgp):
    sfp_setup = {}
    duthost = duthosts[enum_rand_one_per_hwsku_hostname]

    if duthost.is_supervisor_node():
        pytest.skip("skipping for supervisor node")

    # We are interested only in ports that are used for device connection
    physical_intfs = conn_graph_facts["device_conn"][duthost.hostname]

    physical_port_index_map = get_physical_port_indices(duthost, physical_intfs)

    sfp_port_indices = set([physical_port_index_map[intf] \
        for intf in physical_port_index_map.keys()])
    sfp_setup["sfp_port_indices"] = sorted(sfp_port_indices)

    if len(xcvr_skip_list[duthost.hostname]):
        logging.info("Skipping tests on {}".format(xcvr_skip_list[duthost.hostname]))

    sfp_port_indices = set([physical_port_index_map[intf] for intf in \
                                                physical_port_index_map.keys() \
                                                if intf not in xcvr_skip_list[duthost.hostname]])
    sfp_setup["sfp_test_port_indices"] = sorted(sfp_port_indices)

    # Fetch SFP names from platform.json
    sfp_fact_names = []
    sfp_fact_list = duthost.facts.get("chassis").get("sfps")
    for sfp in sfp_fact_list:
        sfp_fact_names.append(sfp.get('name'))
    sfp_setup["sfp_fact_names"] = sfp_fact_names

    if request.cls is not None:
        request.cls.sfp_setup = sfp_setup
    def get_cable_supported_speeds(cls, duthost, dut_port_name):
        """Helper function to get supported speeds for a cable

        Args:
            duthost: DUT object
            dut_port_name (str): DUT interface name

        Returns:
            list: A list of supported speed strings
        """
        if (duthost, dut_port_name) in cls.supported_speeds:
            return cls.supported_speeds[duthost, dut_port_name]

        if duthost not in cls.sorted_ports:
            int_status = duthost.show_interface(command="status")["ansible_facts"]['int_status']
            ports = natsorted([port_name for port_name in int_status.keys()])
            cls.sorted_ports[duthost] = ports

        if not cls.device_path:
            cls.device_path = duthost.shell('ls /dev/mst/*_pci_cr0')['stdout'].strip()
        port_index = get_physical_port_indices(duthost, [dut_port_name]).get(dut_port_name)
        cmd = 'mlxlink -d {} -p {} | grep "Supported Cable Speed"'.format(cls.device_path, port_index)
        output = duthost.shell(cmd)['stdout'].strip()
        # Valid output should be something like "Supported Cable Speed:0x68b1f141 (100G,56G,50G,40G,25G,10G,1G)"
        logger.info('Get supported speeds for {} {}: {}'.format(duthost, dut_port_name, output))
        if not output:
            return None
        pos = output.rfind('(')
        if pos == -1:
            return None
        speeds_str = output[pos+1:-1]
        speeds = list(set([speed.split('G')[0] + '000' for speed in speeds_str.split(',')]))
        cls.supported_speeds[(duthost, dut_port_name)] = speeds
        return speeds
def physical_port_indices(duthosts, enum_rand_one_per_hwsku_hostname):
    duthost = duthosts[enum_rand_one_per_hwsku_hostname]
    port_map = get_physical_port_indices(duthost)
    result = []
    visited_intfs = set()
    for intf in natsorted(port_map.keys()):
        if intf in visited_intfs:
            continue
        visited_intfs.add(intf)
        result.append(port_map[intf])
    return result