示例#1
0
def generate_params_frontend_hostname_rand_per_hwsku(request, duts_in_testbed, tbname):
    frontend_hosts = generate_params_frontend_hostname(request, duts_in_testbed, tbname)
    inv_files = get_inventory_files(request)
    # Create a list of hosts per hwsku
    host_hwskus = {}
    for a_host in frontend_hosts:
        a_host_hwsku = get_host_visible_vars(inv_files, a_host, variable='hwsku')
        if not a_host_hwsku:
            # Lets try 'sonic_hwsku' as well
            a_host_hwsku = get_host_visible_vars(inv_files, a_host, variable='sonic_hwsku')
        if a_host_hwsku:
            if a_host_hwsku not in host_hwskus:
                host_hwskus[a_host_hwsku] = [a_host]
            else:
                host_hwskus[a_host_hwsku].append(a_host)
        else:
            pytest.fail("Test selected require a node per hwsku, but 'hwsku' for '{}' not defined in the inventory".format(a_host))

    frontend_hosts_per_hwsku = []
    for hosts in host_hwskus.values():
        if len(hosts) == 1:
            frontend_hosts_per_hwsku.append(hosts[0])
        else:
            frontend_hosts_per_hwsku.extend(random.sample(hosts, 1))

    return frontend_hosts_per_hwsku
示例#2
0
def generate_param_asic_index(request,
                              dut_hostnames,
                              param_type,
                              random_asic=False):
    _, tbinfo = get_tbinfo(request)
    inv_files = get_inventory_files(request)
    logging.info("generating {} asic indicies for  DUT [{}] in ".format(
        param_type, dut_hostnames))

    asic_index_params = []
    for dut in dut_hostnames:
        inv_data = get_host_visible_vars(inv_files, dut)
        # if the params are not present treat the device as a single asic device
        dut_asic_params = [DEFAULT_ASIC_ID]
        if inv_data:
            if param_type == ASIC_PARAM_TYPE_ALL and ASIC_PARAM_TYPE_ALL in inv_data:
                if int(inv_data[ASIC_PARAM_TYPE_ALL]) == 1:
                    dut_asic_params = [DEFAULT_ASIC_ID]
                else:
                    dut_asic_params = range(int(inv_data[ASIC_PARAM_TYPE_ALL]))
            elif param_type == ASIC_PARAM_TYPE_FRONTEND and ASIC_PARAM_TYPE_FRONTEND in inv_data:
                dut_asic_params = inv_data[ASIC_PARAM_TYPE_FRONTEND]
            elif param_type == ASIC_PARAM_TYPE_BACKEND and ASIC_PARAM_TYPE_BACKEND in inv_data:
                dut_asic_params = inv_data[ASIC_PARAM_TYPE_BACKEND]
            logging.info("dut name {}  asics params = {}".format(
                dut, dut_asic_params))
        if random_asic:
            asic_index_params.append(random.sample(dut_asic_params, 1))
        else:
            asic_index_params.append(dut_asic_params)
    return asic_index_params
示例#3
0
def generate_params_hostname_rand_per_hwsku(request, frontend_only=False):
    hosts = get_specified_duts(request)
    if frontend_only:
        hosts = generate_params_frontend_hostname(request)
    inv_files = get_inventory_files(request)
    # Create a list of hosts per hwsku
    host_hwskus = {}
    for a_host in hosts:
        host_vars = get_host_visible_vars(inv_files, a_host)
        a_host_hwsku = None
        if 'hwsku' in host_vars:
            a_host_hwsku = host_vars['hwsku']
        else:
            # Lets try 'sonic_hwsku' as well
            if 'sonic_hwsku' in host_vars:
                a_host_hwsku = host_vars['sonic_hwsku']
        if a_host_hwsku:
            if a_host_hwsku not in host_hwskus:
                host_hwskus[a_host_hwsku] = [a_host]
            else:
                host_hwskus[a_host_hwsku].append(a_host)
        else:
            pytest.fail(
                "Test selected require a node per hwsku, but 'hwsku' for '{}' not defined in the inventory"
                .format(a_host))

    hosts_per_hwsku = []
    for hosts in host_hwskus.values():
        if len(hosts) == 1:
            hosts_per_hwsku.append(hosts[0])
        else:
            hosts_per_hwsku.extend(random.sample(hosts, 1))

    return hosts_per_hwsku
示例#4
0
    def compare_value_with_device_facts(self,
                                        duthost,
                                        key,
                                        value,
                                        case_sensitive=True):
        expected_value = None

        if self.inv_files:
            host_vars = get_host_visible_vars(self.inv_files, duthost.hostname)
            expected_value = host_vars.get(key)

        pytest_assert(
            expected_value is not None,
            "Unable to get expected value for '{}' from inventory file".format(
                key))

        if case_sensitive:
            pytest_assert(
                value == expected_value,
                "'{}' value is incorrect. Got '{}', expected '{}'".format(
                    key, value, expected_value))
        else:
            value_lower = value.lower()
            expected_value_lower = expected_value.lower()
            pytest_assert(
                value_lower == expected_value_lower,
                "'{}' value is incorrect. Got '{}', expected '{}'".format(
                    key, value, expected_value))
示例#5
0
def test_inject_y_cable_simulator_client(duthosts, enum_dut_hostname, tbinfo,
                                         vmhost):
    '''
    Inject the Y cable simulator client to both ToRs in a dualtor testbed
    '''
    if 'dualtor' not in tbinfo['topo']['name']:
        return

    logger.info(
        "Injecting Y cable simulator client to {}".format(enum_dut_hostname))
    dut = duthosts[enum_dut_hostname]
    tbname = tbinfo['conf-name']
    _hostvars = get_host_visible_vars(dut.host.options['inventory'],
                                      dut.hostname)
    mux_simulator_port = _hostvars['mux_simulator_http_port'][tbname]
    y_cable_sim_client_template_path = 'templates/y_cable_simulator_client.j2'

    template_args = {
        'duts_map': json.dumps(tbinfo['duts_map'], sort_keys=True, indent=4),
        'mux_simulator_server': vmhost.mgmt_ip,
        'mux_simulator_port': mux_simulator_port,
        'dut_name': enum_dut_hostname,
        'group_name': tbinfo['group-name']
    }

    with open(y_cable_sim_client_template_path) as f:
        template = Template(f.read())

    rendered = template.render(template_args)

    dut.copy(content=rendered, dest='/tmp/y_cable_simulator_client.py')
    dut.shell(
        'cp /tmp/y_cable_simulator_client.py /usr/lib/python3/dist-packages/')
    dut.shell(
        'docker cp /tmp/y_cable_simulator_client.py pmon:/usr/lib/python3/dist-packages/'
    )

    # Below changes are required after these PRs are merged:
    # * https://github.com/Azure/sonic-platform-common/pull/213
    # * https://github.com/Azure/sonic-platform-daemons/pull/197
    # For the simulated y_cable driver to work, basic configuration information of the mux simulator is required.
    # When /etc/sonic/mux_simulator.json file is found on DUT, xcvrd will try to load simulated y_cable driver.
    # File /etc/sonic/mux_simulator.json can co-exist with the 'y_cable_simulator_client.py' file injected above.
    # Process xcvrd will determine which one to load or use.
    mux_simulator_config = {
        'server_ip':
        vmhost.mgmt_ip,
        'server_port':
        mux_simulator_port,
        'vm_set':
        tbinfo['group-name'],
        'side':
        UPPER_TOR
        if tbinfo['duts'].index(enum_dut_hostname) == 0 else LOWER_TOR
    }
    dut.copy(content=json.dumps(mux_simulator_config, indent=2),
             dest='/etc/sonic/mux_simulator.json')

    dut.shell('systemctl restart pmon')
示例#6
0
def skip_unsupported_asic_type(duthost):
    SUBPORT_UNSUPPORTED_ASIC_LIST = ["th2"]
    vendor = duthost.facts["asic_type"]
    hostvars = get_host_visible_vars(duthost.host.options['inventory'], duthost.hostname)
    for asic in SUBPORT_UNSUPPORTED_ASIC_LIST:
        vendorAsic = "{0}_{1}_hwskus".format(vendor, asic)
        if vendorAsic in hostvars.keys() and duthost.facts['hwsku'] in hostvars[vendorAsic]:
            pytest.skip(
                "Skipping test since subport is not supported on {0} {1} platforms".format(vendor, asic))
示例#7
0
def is_supervisor_node(inv_files, hostname):
    """Check if the current node is a supervisor node in case of multi-DUT.
     @param inv_files: List of inventory file paths, In tests,
            you can be get it from get_inventory_files in tests.common.utilities
     @param hostname: hostname as defined in the inventory
    Returns:
          Currently, we are using 'card_type' in the inventory to make the decision. If 'card_type' for the node is defined in
          the inventory, and it is 'supervisor', then return True, else return False. In future, we can change this
          logic if possible to derive it from the DUT.
    """
    dut_vars = get_host_visible_vars(inv_files, hostname)
    if 'card_type' in dut_vars and dut_vars['card_type'] == 'supervisor':
        return True
    return False
示例#8
0
def common_setup_teardown(rand_selected_dut, request, tbinfo, vmhost):
    # Skip dualtor test cases on unsupported platform
    supported_platforms = ['broadcom_td3_hwskus', 'broadcom_th2_hwskus']
    hostvars = get_host_visible_vars(
        rand_selected_dut.host.options['inventory'],
        rand_selected_dut.hostname)
    hwsku = rand_selected_dut.facts['hwsku']
    skip = True
    for platform in supported_platforms:
        supported_skus = hostvars.get(platform, [])
        if hwsku in supported_skus:
            skip = False
            break
    py_require(not skip, "Skip on unsupported platform")

    if 'dualtor' in tbinfo['topo']['name']:
        request.getfixturevalue('run_garp_service')
示例#9
0
def generate_param_asic_index(request, dut_indices, param_type):
    _, tbinfo = get_tbinfo(request)
    inv_files = get_inventory_files(request)
    logging.info("generating {} asic indicies for  DUT [{}] in ".format(
        param_type, dut_indices))
    #if the params are not present treat the device as a single asic device
    asic_index_params = [DEFAULT_ASIC_ID]

    for dut_id in dut_indices:
        dut = tbinfo['duts'][dut_id]
        inv_data = get_host_visible_vars(inv_files, dut)
        if inv_data is not None:
            if param_type == ASIC_PARAM_TYPE_ALL and ASIC_PARAM_TYPE_ALL in inv_data:
                if int(inv_data[ASIC_PARAM_TYPE_ALL]) == 1:
                    asic_index_params = [DEFAULT_ASIC_ID]
                else:
                    asic_index_params = range(
                        int(inv_data[ASIC_PARAM_TYPE_ALL]))
            elif param_type == ASIC_PARAM_TYPE_FRONTEND and ASIC_PARAM_TYPE_FRONTEND in inv_data:
                asic_index_params = inv_data[ASIC_PARAM_TYPE_FRONTEND]
            logging.info("dut_index {} dut name {}  asics params = {}".format(
                dut_id, dut, asic_index_params))
    return asic_index_params
def dut_vars(duthosts, enum_rand_one_per_hwsku_hostname, request):
    inv_files = get_inventory_files(request)
    dut_vars = get_host_visible_vars(inv_files,
                                     enum_rand_one_per_hwsku_hostname)
    yield dut_vars
示例#11
0
    def test_get_system_eeprom_info(self, duthosts,
                                    enum_rand_one_per_hwsku_hostname,
                                    localhost, platform_api_conn):
        ''' Test that we can retrieve sane system EEPROM info from the DUT via the platform API
        '''
        # OCP ONIE TlvInfo EEPROM type codes defined here: https://opencomputeproject.github.io/onie/design-spec/hw_requirements.html
        VALID_ONIE_TLVINFO_TYPE_CODES_LIST = [
            ONIE_TLVINFO_TYPE_CODE_PRODUCT_NAME,
            ONIE_TLVINFO_TYPE_CODE_PART_NUMBER,
            ONIE_TLVINFO_TYPE_CODE_SERIAL_NUMBER,
            ONIE_TLVINFO_TYPE_CODE_BASE_MAC_ADDR,
            ONIE_TLVINFO_TYPE_CODE_MFR_DATE,
            ONIE_TLVINFO_TYPE_CODE_DEVICE_VERSION,
            ONIE_TLVINFO_TYPE_CODE_LABEL_REVISION,
            ONIE_TLVINFO_TYPE_CODE_PLATFORM_NAME,
            ONIE_TLVINFO_TYPE_CODE_ONIE_VERSION,
            ONIE_TLVINFO_TYPE_CODE_NUM_MACS,
            ONIE_TLVINFO_TYPE_CODE_MANUFACTURER,
            ONIE_TLVINFO_TYPE_CODE_COUNTRY_CODE, ONIE_TLVINFO_TYPE_CODE_VENDOR,
            ONIE_TLVINFO_TYPE_CODE_DIAG_VERSION,
            ONIE_TLVINFO_TYPE_CODE_SERVICE_TAG,
            ONIE_TLVINFO_TYPE_CODE_VENDOR_EXT, ONIE_TLVINFO_TYPE_CODE_CRC32
        ]

        MINIMUM_REQUIRED_TYPE_CODES_LIST = [
            ONIE_TLVINFO_TYPE_CODE_SERIAL_NUMBER,
            ONIE_TLVINFO_TYPE_CODE_BASE_MAC_ADDR, ONIE_TLVINFO_TYPE_CODE_CRC32
        ]

        duthost = duthosts[enum_rand_one_per_hwsku_hostname]
        syseeprom_info_dict = chassis.get_system_eeprom_info(platform_api_conn)
        # Convert all keys of syseeprom_info_dict into lower case
        syseeprom_info_dict = {
            k.lower(): v
            for k, v in syseeprom_info_dict.items()
        }
        pytest_assert(syseeprom_info_dict is not None,
                      "Failed to retrieve system EEPROM data")
        pytest_assert(isinstance(syseeprom_info_dict, dict),
                      "System EEPROM data is not in the expected format")

        # case sensitive,so make all characters lowercase
        syseeprom_type_codes_list = [
            key.lower() for key in syseeprom_info_dict.keys()
        ]
        VALID_ONIE_TLVINFO_TYPE_CODES_LIST = [
            key.lower() for key in VALID_ONIE_TLVINFO_TYPE_CODES_LIST
        ]
        MINIMUM_REQUIRED_TYPE_CODES_LIST = [
            key.lower() for key in MINIMUM_REQUIRED_TYPE_CODES_LIST
        ]

        # Ensure that all keys in the resulting dictionary are valid ONIE TlvInfo type codes
        pytest_assert(
            set(syseeprom_type_codes_list) <=
            set(VALID_ONIE_TLVINFO_TYPE_CODES_LIST),
            "Invalid TlvInfo type code found")

        # Ensure that we were able to obtain the minimum required type codes
        pytest_assert(
            set(MINIMUM_REQUIRED_TYPE_CODES_LIST) <=
            set(syseeprom_type_codes_list),
            "Minimum required TlvInfo type codes not provided")

        # Ensure the base MAC address is sane
        base_mac = syseeprom_info_dict[ONIE_TLVINFO_TYPE_CODE_BASE_MAC_ADDR]
        pytest_assert(base_mac is not None,
                      "Failed to retrieve base MAC address")
        pytest_assert(re.match(REGEX_MAC_ADDRESS, base_mac),
                      "Base MAC address appears to be incorrect")

        # Ensure the serial number is sane
        serial = syseeprom_info_dict[ONIE_TLVINFO_TYPE_CODE_SERIAL_NUMBER]
        pytest_assert(serial is not None, "Failed to retrieve serial number")
        pytest_assert(re.match(REGEX_SERIAL_NUMBER, serial),
                      "Serial number appears to be incorrect")
        host_vars = get_host_visible_vars(self.inv_files, duthost.hostname)
        expected_syseeprom_info_dict = host_vars.get('syseeprom_info')
        # Ignore case of keys in syseeprom_info
        expected_syseeprom_info_dict = {
            k.lower(): v
            for k, v in expected_syseeprom_info_dict.items()
        }

        for field in expected_syseeprom_info_dict:
            pytest_assert(
                field in syseeprom_info_dict,
                "Expected field '{}' not present in syseeprom on '{}'".format(
                    field, duthost.hostname))
            pytest_assert(
                syseeprom_info_dict[field] ==
                expected_syseeprom_info_dict[field],
                "System EEPROM info is incorrect - for '{}', rcvd '{}', expected '{}' on '{}'"
                .format(field, syseeprom_info_dict[field],
                        expected_syseeprom_info_dict[field], duthost.hostname))