Exemplo n.º 1
0
def client_auth(dut, **kwargs):
    """
    To enable disable REST client auth.
    Author: Prudvi Mangadu ([email protected])
    :param dut:
    :param kwargs:
    :return:
    """
    st.log("Configuring REST authentication.")
    docer_name = "mgmt-framework"
    show_command = []
    if 'auth_type' in kwargs:
        show_command.append('sonic-cfggen -d -v "REST_SERVER"')
        if kwargs.get('auth_type'):
            command = redis.build(dut, redis.CONFIG_DB, 'hmset "REST_SERVER|default" client_auth "{}"'.format(kwargs.get('auth_type')))
        else:
            command = redis.build(dut, redis.CONFIG_DB, 'hdel "REST_SERVER|default" client_auth')
        st.config(dut, command)
    if 'ca_crt' in kwargs:
        show_command.append(redis.build(dut, redis.CONFIG_DB, 'hgetall "DEVICE_METADATA|x509"'))
        if kwargs.get('ca_crt'):
            command = redis.build(dut, redis.CONFIG_DB, 'hmset "DEVICE_METADATA|x509" ca_crt {}'.format(kwargs.get('ca_crt')))
        else:
            command = redis.build(dut, redis.CONFIG_DB, 'hdel "DEVICE_METADATA|x509" ca_crt')
        st.config(dut, command)
    from apis.system.basic import service_operations_by_systemctl
    service_operations_by_systemctl(dut, docer_name, 'stop')
    service_operations_by_systemctl(dut, docer_name, 'start')
    st.config(dut, show_command)
    return True
Exemplo n.º 2
0
def verify_error_db(dut, table, **kwargs):
    """
    Verify error db using redis cli
    :param dut:
    :param table:
    :param kwargs:
    :return:
    """
    match = ""
    if table == "ERROR_ROUTE_TABLE":
        vrfKey = ""
        if 'vrf' in kwargs:
            vrfKey = kwargs["vrf"] + ":"
        command = redis.build(
            dut, redis.ERROR_DB,
            "hgetall {}:{}{}/{}".format(table, vrfKey, kwargs["route"],
                                        kwargs["mask"]))
        if kwargs["opcode"] == "create":
            match = {
                "nhp": kwargs["nhp"],
                "rc": kwargs["rc"],
                "ifname": kwargs["port"],
                "opcode": kwargs["opcode"]
            }
        elif kwargs["opcode"] == "remove":
            match = {"rc": kwargs["rc"], "opcode": kwargs["opcode"]}
        elif "rc" not in kwargs and "opcode" not in kwargs:
            match = {"nhp": kwargs["nhp"], "ifname": kwargs["port"]}

    elif table == "ERROR_NEIGH_TABLE":
        st.log("table")
        command = redis.build(
            dut, redis.ERROR_DB,
            "hgetall {}:{}:{}".format(table, kwargs["port"], kwargs["nhp"]))
        if kwargs["opcode"] == "create":
            match = {
                "mac": kwargs["mac"],
                "rc": kwargs["rc"],
                "ifname": kwargs["port"],
                "opcode": kwargs["opcode"]
            }
        elif kwargs["opcode"] == "remove":
            match = {"rc": kwargs["rc"], "opcode": kwargs["opcode"]}
        elif "rc" not in kwargs and "opcode" not in kwargs:
            match = {"ifname": kwargs["port"], "mac": kwargs["mac"]}
    output = st.show(dut, command)
    output = _get_entries_with_native_port(dut, output, **kwargs)
    st.debug(output)
    if not filter_and_select(output, None, match):
        st.error("No match found")
        return False
    return True
Exemplo n.º 3
0
def verify_error_db_redis(dut, table, **kwargs):
    """
    Verify error db using redis cli
    Author : Prudvi Mangadu ([email protected])
    :param :dut:
    :param :table:
    :param :route:
    :param :mask:
    :param :ifname:
    :param :nhp:
    :param :operation:
    :param :rc:
    :param :result: (Default True)
    :param :iteration: default(30)
    :return:
    """
    port = kwargs.pop("ifname")
    port = st.get_other_names(dut, [port])[0] if "/" in port else port
    exp_result = kwargs.get("result", True)
    iteration = kwargs.get("iteration", 30)
    command = ''
    if table == "ERROR_ROUTE_TABLE":
        command = redis.build(
            dut, redis.ERROR_DB,
            "hgetall {}:{}/{}".format(table, kwargs.pop("route"),
                                      kwargs.pop("mask")))
    elif table == "ERROR_NEIGH_TABLE":
        command = redis.build(
            dut, redis.ERROR_DB,
            "hgetall {}:{}:{}".format(table, port, kwargs.pop("nhp")))
    else:
        st.error("Invalid table name - {}".format(table))

    i = 1
    while True:
        output = st.show(dut, command)
        st.debug(output)
        result = True
        for each in kwargs.keys():
            if not filter_and_select(output, None, {each: kwargs[each]}):
                st.error("No match for {} = {} in redis cli".format(
                    each, kwargs[each]))
                result = False
        if result == exp_result:
            return True
        if i >= iteration:
            return False
        i += 1
        st.wait(1)
Exemplo n.º 4
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)
Exemplo n.º 5
0
def verify_nat_entry_db(dut, table, prot, ip, port, **kwargs):
    """
    Author : Priyanka
    :param dut:
    :param table:
    :param prot:
    :param ip:
    :param port:
    :param kwargs:
    :return:
    """
    string = ''
    if table == "NAT_TABLE":
        string = "NAT_TABLE:{}".format(ip)
    elif table == "NAPT_TABLE":
        string = "NAPT_TABLE:{}:{}:{}".format(prot, ip, port)
    command = redis.build(dut, redis.APPL_DB, "hgetall {}".format(string))
    output = st.show(dut, command)
    st.debug(output)
    for each in kwargs.keys():
        match = {each: kwargs[each]}
        entries = filter_and_select(output, None, match)
        if not entries:
            st.log("{} and {} is not match ".format(each, kwargs[each]))
            return False
    return True
Exemplo n.º 6
0
def verify_stp_entry_db(dut, table, vlan = None, ifname = None, **kwargs):
   """
   """
   if table == "_STP_VLAN_INTF_TABLE":
      cmd = "Vlan"+str(vlan)
      string = "{}:{}:{}".format(table, cmd, ifname)
   elif table == "_STP_PORT_TABLE":
      string = "{}:{}".format(table, ifname)
   else:
      print("invalid table")
      return False

   print("string is-")
   print(string)

   command = redis.build(dut, redis.APPL_DB, "hgetall {}".format(string))
   print("command is -", command)

   output = st.show(dut, command)
   print("output is -")
   print(output)
   st.debug(output)

   print("kwargs: ", kwargs)

   for each in kwargs.keys():
      match = {each: kwargs[each]}
      entries = filter_and_select(output, None, match)
      print("match :", match)
      print("entries:", entries)
      if not entries:
         st.log("{} and {} do not match ".format(each, kwargs[each]))
         return False
   return True
Exemplo n.º 7
0
def get_num_entries_error_db(dut, ifname_type=None):
    """
    To Get total entries in Error Database using redis cli
    :param dut:
    :return:
    """
    command = redis.build(dut, redis.ERROR_DB, "keys ERROR.*")
    output = st.show(dut, command)
    output = _get_entries_with_native_port(dut, output, ifname_type=ifname_type)
    st.debug(output)
    return len(output)
Exemplo n.º 8
0
def show_asicDB_macs(dut):
    '''
    Klish support not needed

        Author: [email protected]
        Display MACs in asicDB
        :param dut:
        :param kwargs:
        :return:
        '''

    ### Collect asicDB
    st.log("AsicDB MAC Entries:")
    st.show(dut, redis.build(dut, redis.ASIC_DB, 'keys *FDB*'), skip_tmpl=True)
Exemplo n.º 9
0
def set_nat_timeout_db(dut, prot, seconds):
    """
    Author : Akhilesh
    :param dut:
    :param prot:
    :param seconds:
    :return:
    """
    if prot == "tcp":
        timeout = "nat_tcp_timeout"
    elif prot == "udp":
        timeout = "nat_udp_timeout"
    elif prot == "all":
        timeout = "nat_timeout"

    string = "\"NAT_GLOBAL|Values\" \"{}\" {}".format(timeout, seconds)
    command = redis.build(dut, redis.CONFIG_DB, "hset {}".format(string))
    st.config(dut, command)
    return True
Exemplo n.º 10
0
def verify_ip_mroute_appdb(dut, source, group, **kwargs):
    """
    Author : Kiran Kumar K
    :param : source:
    :type : address
    :param : group:
    :type : address
    :type : interface name
    :return:
    :type: bool
    """
    if 'vrf' in kwargs:
        vrf_name = kwargs['vrf']
        del kwargs['vrf']
    else:
        vrf_name = 'default'

    if vrf_name != 'default':
        key = "IPMC_ROUTE_TABLE:{}|{}|{}".format(vrf_name, source, group)
    else:
        key = "IPMC_ROUTE_TABLE:{}|{}".format(source, group)
    print(key)
    command = redis.build(dut, redis.APPL_DB, "hgetall \"{}\"".format(key))
    print(command)
    output = st.show(dut, command)
    print(output)
    st.debug(output)

    if len(output) == 0:
        return False

    for each in kwargs.keys():
        print(each)
        match = {each: kwargs[each]}
        entries = filter_and_select(output, None, match)
        if not entries:
            st.log("{} and {} is not match ".format(each, kwargs[each]))
            return False
    return True
Exemplo n.º 11
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)
Exemplo n.º 12
0
def verify_intf_mcast_mode_in_appdb(dut, in_intf, **kwargs):
    """
    Author : Kiran Kumar K
    :param : in_intf:
    :type : interface name
    :return:
    :type: bool
    """

    key = "INTF_TABLE:{}".format(in_intf)
    print(key)
    command = redis.build(dut, redis.APPL_DB, "hgetall {}".format(key))
    print(command)
    output = st.show(dut, command)
    print(output)
    st.debug(output)
    for each in kwargs.keys():
        match = {each: kwargs[each]}
        entries = filter_and_select(output, None, match)
        if not entries:
            st.log("{} and {} is not match ".format(each, kwargs[each]))
            return False
    return True
Exemplo n.º 13
0
def client_auth(dut, **kwargs):
    """
    To enable disable gNMI client auth.
    Author: Prudvi Mangadu ([email protected])
    :param dut:
    :param auth_type:
    :return:
    """
    st.log("Configuring gNMI authentication.")
    docker_name= "telemetry"
    command = redis.build(dut, redis.CONFIG_DB, 'hmset "TELEMETRY|gnmi" client_auth')
    if 'auth_type' in kwargs:
        if kwargs.get('auth_type'):
            command = redis.build(dut, redis.CONFIG_DB, 'hmset "TELEMETRY|gnmi" client_auth "{}"'.format(kwargs.get('auth_type')))
        else:
            command = redis.build(dut, redis.CONFIG_DB, 'hdel "TELEMETRY|gnmi" client_auth')
        st.config(dut, command)
    if 'server_key' in kwargs:
        if kwargs.get('server_key'):
            command = redis.build(dut, redis.CONFIG_DB, 'hmset "DEVICE_METADATA|x509" server_key "{}"'.format(kwargs.get('server_key')))
        st.config(dut, command)
    if 'server_crt' in kwargs:
        if kwargs.get('server_crt'):
            command = redis.build(dut, redis.CONFIG_DB, 'hmset "DEVICE_METADATA|x509" server_crt "{}"'.format(kwargs.get('server_crt')))
        st.config(dut, command)
    if 'ca_crt' in kwargs:
        if kwargs.get('ca_crt'):
            command = redis.build(dut, redis.CONFIG_DB, 'hmset "DEVICE_METADATA|x509" ca_crt "{}"'.format(kwargs.get('ca_crt')))
        else:
            command = redis.build(dut, redis.CONFIG_DB, 'hdel "DEVICE_METADATA|x509" ca_crt')
        st.config(dut, command)
    service_operations_by_systemctl(dut, docker_name, 'stop')
    service_operations_by_systemctl(dut, docker_name, 'start')
    command = 'sonic-cfggen -d -v "TELEMETRY"'
    st.config(dut, command)
    return True
Exemplo n.º 14
0
def show(dut, *argv, **kwargs):
    """
    show commands summary
    Author: prudviraj k ([email protected])
    :param dut:
    :param argv:
    :param interval:
    :param clear_interval:
    :param persistent_head:
    :param persistent_shared:
    :param threshold_head:
    :param threshold__shared:
    :param watermark_head:
    :param watermark_shared:
    :param port_alias:
    :param column_name:
    :param queue_value:
    :return:
    """
    cli_type = st.get_ui_type(dut, **kwargs)
    if cli_type in ["rest-patch", "rest-put"] and 'column_name' in kwargs:
        cli_type = 'klish'
    if cli_type in ["rest-patch", "rest-put"]:
        for queue_type in argv:
            if queue_type in [
                    "buffer_pool_watermark",
                    "buffer_pool_persistent-watermark",
                    "buffer_pool_counters_DB"
            ]:
                cli_type = 'klish'
    persistent = "show priority-group persistent-watermark"
    user_watermark = "show priority-group watermark"
    queue_user_watermark = "show queue watermark"
    queue_persistent_watermark = "show queue persistent-watermark"
    if cli_type == 'click' or cli_type == 'klish':
        if "snapshot_interval" in argv:
            command = "show watermark interval"
        elif 'telemetry_interval' in argv:
            command = "show watermark telemetry interval"
        elif 'persistent_PG_headroom' in argv:
            command = persistent + " " + "{}".format("headroom")
        elif 'persistent_PG_shared' in argv:
            command = persistent + " " + "{}".format("shared")
        elif 'user_watermark_PG_headroom' in argv:
            command = user_watermark + " " + "{}".format("headroom")
        elif 'user_watermark_PG_shared' in argv:
            command = user_watermark + " " + "{}".format("shared")
        elif 'queue_user_watermark_unicast' in argv:
            command = queue_user_watermark + " " + "{}".format("unicast")
        elif 'queue_user_watermark_multicast' in argv:
            command = queue_user_watermark + " " + "{}".format("multicast")
        elif 'queue_user_watermark_cpu' in argv:
            command = queue_user_watermark + " " + "{}".format("CPU")
        elif 'queue_persistent_watermark_unicast' in argv:
            command = queue_persistent_watermark + " " + "{}".format("unicast")
        elif 'queue_persistent_watermark_multicast' in argv:
            command = queue_persistent_watermark + " " + "{}".format(
                "multicast")
        elif 'buffer_pool_watermark' in argv or 'percent' in kwargs:
            if cli_type == 'klish' and 'percent' in kwargs:
                perc = 'percentage'
            else:
                perc = kwargs.get('percent', '')
            command = "show buffer_pool watermark {}".format(perc)
        elif 'buffer_pool_persistent-watermark' in argv or 'percent' in kwargs:
            if cli_type == 'klish' and 'percent' in kwargs:
                perc = 'percentage'
            else:
                perc = kwargs.get('percent', '')
            command = "show buffer_pool persistent-watermark {}".format(perc)
        elif 'column_name' and 'queue_value' in kwargs:
            intf_name = st.get_other_names(
                dut, [kwargs['interface_name']])[0] if '/' in kwargs[
                    'interface_name'] else kwargs['interface_name']
            command = redis.build(
                dut, redis.COUNTERS_DB,
                "hget {} {}:{}".format(kwargs['column_name'], intf_name,
                                       kwargs['queue_value']))
            output = st.show(dut, command)
            oid = output[0]['oid'].strip('"')
            command = redis.build(
                dut, redis.COUNTERS_DB,
                "hgetall {}:{}".format(kwargs['table_name'], oid))
            output = st.show(dut, command)
            output = output[:-1]
            dut_output = get_dict_from_redis_cli(output)
            st.log(dut_output)
            return [dut_output]
        elif 'buffer_pool_counters_DB' in argv:
            command = redis.build(dut, redis.COUNTERS_DB,
                                  "Hgetall COUNTERS_BUFFER_POOL_NAME_MAP")
            output = st.show(dut, command)
            output = output[:-1]
            dut_output = get_dict_from_redis_cli(output)
            st.log(dut_output)
            command = redis.build(
                dut, redis.COUNTERS_DB, "hgetall COUNTERS:{}".format(
                    dut_output[kwargs['oid_type']].strip('"')))
            output = st.show(dut, command)
            output = output[:-1]
            dut_output = get_dict_from_redis_cli(output)
            st.log(dut_output)
            return [dut_output]
        if 'port_alias' in kwargs or 'percentage' in kwargs:
            if cli_type == 'click':
                command += " {} | grep -w {}".format(
                    kwargs.get('percentage', ''), kwargs['port_alias'])
                return st.show(dut, command, type=cli_type)
            elif cli_type == 'klish':
                if kwargs['port_alias'] == 'CPU':
                    command += " | grep {}".format(kwargs['port_alias'])
                else:
                    interface_details = get_interface_number_from_name(
                        kwargs['port_alias'])
                    if 'percentage' in kwargs:
                        using_perc = command.split(" ")
                        using_perc.insert(-1, "percentage")
                        command = " ".join(using_perc)
                        command += " interface {} {}".format(
                            interface_details.get("type"),
                            interface_details.get("number"))
                    else:
                        command += " interface {} {}".format(
                            interface_details.get("type"),
                            interface_details.get("number"))
        return st.show(dut, command, type=cli_type)
    elif cli_type in ["rest-patch", "rest-put"]:
        ret_val = list()
        rest_urls = st.get_datastore(dut, "rest_urls")
        if "snapshot_interval" in argv:
            url = rest_urls['get_watermark_interval']
            get_info = get_rest(dut, rest_url=url, timeout=60)
            temp = dict()
            temp['snapshotinterval'] = get_info['output'][
                'openconfig-qos-ext:watermark']['state']['refresh-interval']
            ret_val.append(temp)
            st.debug(ret_val)
            return ret_val
        elif 'telemetry_interval' in argv:
            url = rest_urls['get_telemetry_interval']
            get_info = get_rest(dut, rest_url=url, timeout=60)
            temp = dict()
            temp['telemetryinterval'] = get_info['output'][
                'openconfig-qos-ext:telemetry-watermark']['state'][
                    'refresh-interval']
            ret_val.append(temp)
            st.debug(ret_val)
            return ret_val
        for queue_type in argv:
            if 'port_alias' in kwargs or 'percentage' in kwargs:
                ret_val = list()
                rest_urls = st.get_datastore(dut, "rest_urls")
                if queue_type in [
                        'queue_user_watermark_unicast',
                        'queue_user_watermark_multicast',
                        'queue_persistent_watermark_unicast',
                        'queue_persistent_watermark_multicast',
                        'queue_user_watermark_cpu'
                ]:
                    url = rest_urls['get_queue_counter_values'].format(
                        kwargs['port_alias'])
                    get_info = get_rest(dut, rest_url=url, timeout=60)
                    for entry in get_info['output']['openconfig-qos:queues'][
                            'queue']:
                        temp = dict()
                        counters_info = entry['state']
                        port, queue = counters_info['name'].split(':')
                        type = counters_info["openconfig-qos-ext:traffic-type"]
                        counter = type.lower() + queue
                        if kwargs['port_alias'] == 'CPU':
                            cpu_counter = port + queue
                            temp['queue'] = cpu_counter
                            temp['bytes'] = counters_info[
                                "openconfig-qos-ext:watermark"]
                        if 'percentage' in kwargs:
                            if queue_type in [
                                    'queue_user_watermark_unicast',
                                    'queue_user_watermark_multicast'
                            ]:
                                temp[counter] = counters_info[
                                    "openconfig-qos-ext:watermark-percent"]
                            elif queue_type in [
                                    'queue_persistent_watermark_unicast',
                                    'queue_persistent_watermark_multicast'
                            ]:
                                temp[counter] = counters_info[
                                    "openconfig-qos-ext:persistent-watermark-percent"]
                        else:
                            if queue_type in [
                                    'queue_user_watermark_unicast',
                                    'queue_user_watermark_multicast'
                            ]:
                                temp[counter] = counters_info[
                                    "openconfig-qos-ext:watermark"]
                            elif queue_type in [
                                    'queue_persistent_watermark_unicast',
                                    'queue_persistent_watermark_multicast'
                            ]:
                                temp[counter] = counters_info[
                                    "openconfig-qos-ext:persistent-watermark"]
                        ret_val.append(temp)
                    st.debug(ret_val)
                    return ret_val
                if queue_type in [
                        'persistent_PG_shared', 'user_watermark_PG_shared',
                        'persistent_PG_headroom', 'user_watermark_PG_headroom'
                ]:
                    url = rest_urls['get_pg_counter_values'].format(
                        kwargs['port_alias'])
                    get_info = get_rest(dut, rest_url=url, timeout=60)
                    for entry in get_info['output'][
                            'openconfig-qos-ext:priority-groups'][
                                'priority-group']:
                        temp = dict()
                        counters_info = entry['state']
                        port, queue = counters_info['name'].split(':')
                        for i in range(0, 8):
                            if queue == str(i):
                                counter = 'pg' + str(i)
                                if 'percentage' in kwargs:
                                    if queue_type == 'user_watermark_PG_shared':
                                        temp[counter] = counters_info[
                                            'shared-watermark-percent']
                                    elif queue_type == 'user_watermark_PG_headroom':
                                        temp[counter] = counters_info[
                                            'headroom-watermark-percent']
                                    elif queue_type == 'persistent_PG_shared':
                                        temp[counter] = counters_info[
                                            'shared-persistent-watermark-percent']
                                    elif queue_type == 'persistent_PG_headroom':
                                        temp[counter] = counters_info[
                                            'headroom-persistent-watermark-percent']
                                else:
                                    if queue_type == 'user_watermark_PG_shared':
                                        temp[counter] = counters_info[
                                            'shared-watermark']
                                    elif queue_type == 'user_watermark_PG_headroom':
                                        temp[counter] = counters_info[
                                            'headroom-watermark']
                                    elif queue_type == 'persistent_PG_shared':
                                        temp[counter] = counters_info[
                                            'shared-persistent-watermark']
                                    elif queue_type == 'persistent_PG_headroom':
                                        temp[counter] = counters_info[
                                            'headroom-persistent-watermark']
                                ret_val.append(temp)
                    st.debug(ret_val)
                    return ret_val
    else:
        st.error("Unsupported UI Type: {} provided".format(cli_type))
        return False