Esempio n. 1
0
def verify_psuutil_data(dut, *argv, **kwargs):
    """
    API to get psuutil data based on type of the command
    Author: Prudvi Mangadu ([email protected])
    :param dut:
    :param argv:
    :param kwargs:
    :return:
    """
    result = True
    for each_mode in argv:
        output = get_psuutil_data(dut, each_mode)
        if "numpsus" in each_mode and int(output['numpsus']) != len(
                kwargs['psu_list']):
            st.error("Incorrect Number of PSUs detected.")
            result = False

        if "status" in each_mode:
            psu_li = cutils.dicts_list_values(output, "psu")
            for psu in kwargs['psu_list']:
                if psu not in psu_li:
                    st.error("PSU - {} is not present in DUT.")
                    result = False

            status_li = cutils.dicts_list_values(output, "status")
            for status in status_li:
                if status not in ['NOT OK', 'OK']:
                    st.error("Invalid PSU status in DUT.")
                    result = False

            if "OK" not in status_li:
                st.error("None of the PSU status is - OK")
                result = False
    return result
Esempio n. 2
0
def get_ndp_count(dut, cli_type="", **kwargs):
    """
    To get ndp count
    Author: Prudvi Mangadu ([email protected])
    :param dut:
    :return:
    """
    cli_type = st.get_ui_type(dut, cli_type=cli_type)
    if cli_type == 'click':
        command = "show ndp | grep 'Total number of entries'"
        output = st.show(dut, command)
        out = dicts_list_values(output, 'count')
    elif cli_type == 'klish':
        command = "show ipv6 neighbors summary"
        if 'vrf' in kwargs:
            command = "show ipv6 neighbors vrf {} summary".format(
                kwargs["vrf"])
        output = st.show(dut, command, type='klish')
        out = dicts_list_values(output, 'count')
    elif cli_type in ['rest-patch', 'rest-put']:
        if kwargs.get('vrf'):
            out = show_ndp(dut, vrf=kwargs['vrf'], cli_type=cli_type)
        else:
            out = show_ndp(dut, cli_type=cli_type)
        return len(out)
    else:
        st.error("Unsupported CLI_TYPE: {}".format(cli_type))
        return False
    return int(out[0]) if out else 0
Esempio n. 3
0
def verify_hardware_map_status(dut, queues, itter_count=30, delay=1):
    """
    To verify the Queue init in hardware
    :param dut:
    :param queues:
    :param itter_count:
    :param delay:
    :return:
    """
    command = redis.build(dut, redis.COUNTERS_DB, "keys *MAP*")
    queues_li = utils.make_list(queues)
    i = 1
    while True:
        output = st.show(dut, command)
        output_list = utils.filter_and_select(output, ["name"], None)
        output_list = utils.dicts_list_values(output_list, "name")
        result = True
        for each_q in queues_li:
            if each_q not in output_list:
                st.log("{} not yet init.".format(each_q))
                result = False
        if result:
            return True
        if i > itter_count:
            st.log("Max {} tries Exceeded.Exiting..".format(i))
            return False
        i += 1
        st.wait(delay)
Esempio n. 4
0
def bcmcmd_l3_entry_only_config(dut, **kwargs):
    if "action" not in kwargs:
        st.error("Mandatory params num, action are not provided")
        return False
    valid = 1
    if kwargs["action"] == "delete":
        valid = 0
    output = bcmcmd_get_l3_entry(dut)
    name_list = utils.dicts_list_values(output, "names")
    if "L3_ENTRY_ONLY" in name_list:
        num = int(
            utils.filter_and_select(
                output, [], {"names": "L3_ENTRY_ONLY"})[0]['entries']) - 1
        command = "bcmcmd 'mod L3_ENTRY_ONLY 1 {} VALID={}'".format(num, valid)
    elif "L3_ENTRY_ONLY_SINGLE" in name_list:
        num = int(
            utils.filter_and_select(
                output, [],
                {"names": "L3_ENTRY_ONLY_SINGLE"})[0]['entries']) - 1
        command = "bcmcmd 'mod L3_ENTRY_ONLY_SINGLE 1 {} BASE_VALID={}'".format(
            num, valid)
    elif "L3_ENTRY_SINGLE" in name_list:
        num = int(
            utils.filter_and_select(
                output, [], {"names": "L3_ENTRY_SINGLE"})[0]['entries']) - 1
        command = "bcmcmd 'mod L3_ENTRY_SINGLE 1 {} BASE_VALID={}'".format(
            num, valid)
    else:
        st.error(
            "L3_ENTRY_ONLY | L3_ENTRY_ONLY_SINGLE | L3_ENTRY_SINGLE not found in - listmem l3_entry"
        )
        return False
    st.config(dut, command)
    return True
Esempio n. 5
0
def get_ndp_count(dut):
    """
    To get ndp count
    Author: Prudvi Mangadu ([email protected])

    :param dut:
    :return:
    """
    command = "show ndp | grep 'Total number of entries'"
    output = st.show(dut, command)
    out = dicts_list_values(output, 'count')
    return int(out[0]) if out else 0
Esempio n. 6
0
def get(dut, *argv, **kwargs):
    """
    verify commands summary
    Author: prudviraj k ([email protected])
    :param dut:
    :param argv:
    :param :get_value:
    :return:
    """
    if not (kwargs.get('get_value') and kwargs.get('match')):
        st.error("Mandatory arguments 'get_value', 'match' is not given")
    output = show(dut, *argv, **kwargs)
    if not output:
        return None
    entries = filter_and_select(output, None, kwargs['match'])
    out = dicts_list_values(entries, kwargs['get_value'])
    return integer_parse(out[0])
Esempio n. 7
0
def get_arp_count(dut, ipaddress=None, interface=None, cli_type="", **kwargs):
    """
    To get arp count
    Author: Prudvi Mangadu ([email protected])
    :param dut:
    :param ipaddress:
    :param interface:
    :return:
    """
    cli_type = st.get_ui_type(dut, cli_type=cli_type)
    if cli_type == "click":
        command = "show arp"
        if ipaddress:
            command += " {}".format(ipaddress)
        if interface:
            command += " -if {}".format(interface)
        command += " | grep 'Total number of entries'"
    elif cli_type == "klish":
        command = "show ip arp"
        if interface:
            intf = get_interface_number_from_name(interface)
            command += " interface {} {}".format(intf["type"], intf["number"])
        if 'vrf' in kwargs:
            command += " vrf {}".format(kwargs["vrf"])
        if ipaddress:
            st.log("Unsupported attribute ipaddress")
            return 0
        command += " summary"
    elif cli_type in ["rest-patch", "rest-put"]:
        show_arp(dut, ipaddress=None, interface=None, vrf="", cli_type="")
        if interface:
            out = show_arp(dut, interface=interface, cli_type=cli_type)
        if 'vrf' in kwargs:
            out = show_arp(dut, vrf=kwargs['vrf'], cli_type=cli_type)
        if ipaddress:
            out = show_arp(dut, ipaddress=ipaddress, cli_type=cli_type)
        if not (interface and kwargs.get('vrf') and ipaddress):
            out = show_arp(dut, cli_type=cli_type)
        return len(out)
    else:
        st.error("Unsupported CLI_TYPE: {}".format(cli_type))
        return False
    output = st.show(dut, command, type=cli_type)
    out = dicts_list_values(output, 'count')
    return int(out[0]) if out else 0
Esempio n. 8
0
def verify_pddf_psuutils(dut, *argv, **kwargs):
    """
    Author: Prudvi Mangadu ([email protected])
    :param dut:
    :param argv:
    :return:
    """
    result = True
    for each_mode in argv:
        output = show_pddf_psuutils(dut, each_mode)
        if "numpsus" in each_mode and int(output['numpsus']) != len(
                kwargs['psu_list']):
            st.error("Incorrect Number of PSUs detected.")
            result = False

        if "status" in each_mode:
            psu_li = cutils.dicts_list_values(output, "psu")
            for psu in kwargs['psu_list']:
                if psu not in psu_li:
                    st.error("PSU - {} is not present in DUT.")
                    result = False

            status_li = cutils.dicts_list_values(output, "status")
            for status in status_li:
                if status not in ['NOT OK', 'OK']:
                    st.error("Invalid PSU status in DUT.")
                    result = False

            if "OK" not in status_li:
                st.error("None of the PSU status is - OK")
                result = False

        if "mfrinfo" in each_mode:
            status_li = cutils.dicts_list_values(output, "psu_status")
            if "OK" not in status_li:
                st.error("None of the PSU status is - OK")
                result = False

        if 'seninfo' in each_mode:
            status_li = cutils.dicts_list_values(output, "psu_status")
            if "OK" not in status_li:
                st.error("None of the PSU status is - OK")
                result = False
            for each in ['voltage', 'current', 'power']:
                if '0.0' in cutils.dicts_list_values(output, "each"):
                    st.error("{} in 'seninfo' is 0.0".format(each))
                    result = False
            if '0' in cutils.dicts_list_values(output, "fan_speed"):
                st.error("fan_speed in 'seninfo' is 0.0")
                result = False

    return result
Esempio n. 9
0
def get_arp_count(dut, ipaddress=None, interface=None):
    """
    To get arp count
    Author: Prudvi Mangadu ([email protected])

    :param dut:
    :param ipaddress:
    :param interface:
    :return:
    """
    command = "show arp"
    if ipaddress:
        command += " {}".format(ipaddress)
    if interface:
        command += " -if {}".format(interface)
    command += " | grep 'Total number of entries'"
    output = st.show(dut, command)
    out = dicts_list_values(output, 'count')
    return int(out[0]) if out else 0
Esempio n. 10
0
def get_dict_from_redis_cli(data):
    """
    This will convert show_redis_cli_key_search.tmpl output to the dict(key value pair)
    Author : Prudvi Mangadu ([email protected])
    :param data:
    :return:

    EX:
    data = [{'id': '1', 'name': 'sample'}, {'id': '2', 'name': '100'}, {'id': '3', 'name': 'ipaddress-type'},
            {'id': '4', 'name': 'ipv4'}]
    return output: {'ipaddress-type': 'ipv4', 'sample': '100'}
    """
    id_list = dicts_list_values(data, 'id')
    chunks = [id_list[x:x + 2] for x in xrange(0, len(id_list), 2)]
    output = {
        filter_and_select(data, ['name'], {'id': each[0]})[0]['name']:
        filter_and_select(data, ['name'], {'id': each[1]})[0]['name']
        for each in chunks
    }
    return output
Esempio n. 11
0
def get_all_interfaces(dut, int_type=None, cli_type="click"):
    """
    Author: Chaitanya Vella ([email protected])
    API to get all the interfaces nin DUT
    :param dut: dut object
    :param int_type: physical | port_channel
    :param cli_type:
    :return: interface list
    """
    output = interface_status_show(dut, cli_type=cli_type)
    out = dicts_list_values(output, 'interface')
    if out:
        if int_type == 'physical':
            return [each for each in out if each.startswith("Ethernet")]
        elif int_type == 'port_channel':
            return [
                each for each in out if each.lower().startswith("portchannel")
            ]
        else:
            return out
    else:
        return []
Esempio n. 12
0
def verify_port_table_port_config(dut, itter_count=30, delay=1):
    """
    To verify the Port Table Port config status
    Author: Prudvi Mangadu ([email protected])
    :param dut:
    :param itter_count:
    :param delay:
    :return:
    """
    command = redis.build(dut, redis.APPL_DB, "HGETALL PORT_TABLE:PortConfigDone")
    i = 1
    while True:
        output = st.show(dut, command)
        output_list = utils.filter_and_select(output, ["name"], None)
        output_list = utils.dicts_list_values(output_list, "name")
        if 'count' in output_list:
            st.log("{}".format(output))
            return True
        if i > itter_count:
            st.log("Max {} tries Exceeded.Exiting..".format(i))
            return False
        i += 1
        st.wait(delay)