Пример #1
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
Пример #2
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
Пример #3
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
Пример #4
0
def fanouthost(request, duthosts, rand_one_dut_hostname, localhost):
    """
    Fixture that allows to update Fanout configuration if there is a need to send incorrect packets.
    Added possibility to create vendor specific logic to handle fanout configuration.
    If vendor need to update Fanout configuration, 'fanouthost' fixture should load and return appropriate instance.
    This instance can be used inside test case to handle fanout configuration in vendor specific section.
    By default 'fanouthost' fixture will not instantiate any instance so it will return None, and in such case
    'fanouthost' instance should not be used in test case logic.
    """
    duthost = duthosts[rand_one_dut_hostname]
    fanout = None
    # Check that class to handle fanout config is implemented
    if "mellanox" == duthost.facts["asic_type"]:
        for file_name in os.listdir(
                os.path.join(os.path.dirname(__file__), "fanout")):
            # Import fanout configuration handler based on vendor name
            if "mellanox" in file_name:
                module = importlib.import_module(
                    "..fanout.{0}.{0}_fanout".format(file_name.strip(".py")),
                    __name__)
                fanout = module.FanoutHandler(duthost, localhost,
                                              get_inventory_files(request))
                if not fanout.is_mellanox:
                    fanout = None
                break

    yield fanout

    if fanout is not None:
        fanout.restore_config()
Пример #5
0
def generate_params_frontend_hostname(request, duts_in_testbed, tbname):
    frontend_duts = []
    inv_files = get_inventory_files(request)
    for dut in duts_in_testbed:
        if is_frontend_node(inv_files, dut):
            frontend_duts.append(dut)
    assert len(frontend_duts) > 0, \
        "Test selected require at-least one frontend node, " \
        "none of the DUTs '{}' in testbed '{}' are a supervisor node".format(duts_in_testbed, tbname)
    return frontend_duts
Пример #6
0
def generate_params_supervisor_hostname(request, duts_in_testbed, tbname):
    if len(duts_in_testbed) == 1:
        # We have a single node - dealing with pizza box, return it
        return [duts_in_testbed[0]]
    inv_files = get_inventory_files(request)
    for dut in duts_in_testbed:
        # Expecting only a single supervisor node
        if is_supervisor_node(inv_files, dut):
            return [dut]
    pytest.fail("Test selected require a supervisor node, " +
                "none of the DUTs '{}' in testbed '{}' are a supervisor node".format(duts_in_testbed, tbname))
Пример #7
0
def generate_params_supervisor_hostname(request):
    duts = get_specified_duts(request)
    if len(duts) == 1:
        # We have a single node - dealing with pizza box, return it
        return [duts[0]]
    inv_files = get_inventory_files(request)
    for dut in duts:
        # Expecting only a single supervisor node
        if is_supervisor_node(inv_files, dut):
            return [dut]
    # If there are no supervisor cards in a multi-dut tesbed, we are dealing with all pizza box in the testbed, pick the first DUT
    return [duts[0]]
Пример #8
0
def get_host_data(request, dut):
    '''
    This function parses multple inventory files and returns the dut information present in the inventory
    '''
    inv_data = None
    inv_files = get_inventory_files(request)
    for inv_file in inv_files:
        inv_mgr = InventoryManager(loader=DataLoader(), sources=inv_file)
        if dut in inv_mgr.hosts:
            return inv_mgr.get_host(dut).get_vars()

    return inv_data
Пример #9
0
def chassis_facts(duthosts, request):
    """
    Fixture to add some items to host facts from inventory file.
    """
    for a_host in duthosts.nodes:

        if len(duthosts.supervisor_nodes) > 0:
            inv_files = get_inventory_files(request)
            host_vars = get_host_visible_vars(inv_files, a_host.hostname)
            pytest_assert('slot_num' in host_vars, 
                          "Variable 'slot_num' not found in inventory for host {}".format (a_host.hostname))
            slot_num = host_vars['slot_num'] 
            a_host.facts['slot_num'] = int(slot_num)
Пример #10
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
Пример #11
0
def get_host_data(request, dut):
    '''
    This function parses multple inventory files and returns the dut information present in the inventory
    '''
    inv_files = get_inventory_files(request)
    return get_host_vars(inv_files, dut)
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
Пример #13
0
def gather_facts(request, duthosts):
    request.cls.inv_files = get_inventory_files(request)
Пример #14
0
def vmhost(ansible_adhoc, request, tbinfo):
    server = tbinfo["server"]
    inv_files = get_inventory_files(request)
    vmhost = get_test_server_host(inv_files, server)
    return VMHost(ansible_adhoc, vmhost.name)