def verify_mroute_debugcommand(dut, **kwargs): """ Author :Priyanka Gupta :return: :type: bool """ command = "show debug ipmcorch all" 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
def verify_vrf_verbose(dut, vrfname, interface): st.log("verify show vrf --verbose output") """ verify_vrf_verbose(dut1,vrfname="Vrf-103",interface='Ethernet2') """ cmd = "show vrf --verbose" output = st.show(dut, cmd) if not isinstance(vrfname, list): vrfname = [vrfname] for vname, intf in zip(vrfname, interface): match = {"vrfname": vname, "interfaces": intf} entries = filter_and_select(output, ["vrfname"], match) print("entries") if not bool(entries): return bool(entries) return True
def set_copp_config(dut, *argv): """ To set the config into copp Author : Chaitanya Lohith Bollapragada ([email protected]) Expected input from user should be [[table_name,attribute,value],[table_name,attribute,value],...] :param dut: :param table_name: :param attribute: :param value: :return bool: Example : set_copp_config(dut, ["COPP_TABLE:trap.group.bgp.lacp","queue","4"]) set_copp_config(dut, ["COPP_TABLE:trap.group.bgp.lacp","queue","4"],["COPP_TABLE:trap.group.lldp.dhcp.udld","trap_priority","6"]) """ command = "docker exec swss cat /etc/swss/config.d/00-copp.config.json" output = st.show(dut, command, skip_tmpl=True) reg_output = utils_obj.remove_last_line_from_string(output) try: data = do_eval(reg_output) except Exception as e: st.log(e) reg_output = "{} ]".format(reg_output) data = do_eval(reg_output) st.log("ARGV {}".format(argv)) for eachli in argv: if len(eachli) != 3: st.error("Invalid input is provided {}".format(eachli)) return False table = eachli[0] attribute = eachli[1] value = eachli[2] for each in data: if table in each: each[table][attribute] = value break else: st.error("Table not found {}".format(table)) return False file_path = utils_obj.write_to_json_file(data, "/tmp/00-copp.config.json") st.log("FILE PATH -- {}".format(file_path)) st.upload_file_to_dut(dut, file_path, "/tmp/00-copp.config.json") command = "docker cp /tmp/00-copp.config.json swss:/etc/swss/config.d/00-copp.config.json" st.config(dut, command) command = "rm /tmp/00-copp.config.json" st.config(dut, command) return True
def set_copp_pir_config(dut, config, *args): """ To set the config into copp_config.json Author : [email protected] :param dut: :param config: :param args: :return: """ command = "sudo cat /etc/sonic/copp_config.json" output = st.show(dut, command, skip_tmpl=True) reg_output = utils_obj.remove_last_line_from_string(output) try: data = eval(reg_output) except Exception as e: st.log(e) reg_output = str(reg_output) + "\n" + "}" data = eval(reg_output) st.log("ARGS {}".format(args)) if config == "get": return data for eachli in args: if len(eachli) != 3: st.error("Invalid input is provided {}".format(eachli)) return False table = eachli[0] attribute = eachli[1] value = eachli[2] found_table = False if table in data['SCHEDULER'].keys(): data['SCHEDULER'][table][attribute] = value found_table = True if not found_table: st.error("Table not found {}".format(table)) return False file_path = utils_obj.write_to_json_file(data, "/tmp/00-copp.config.json") st.log("FILE PATH -- {}".format(file_path)) st.upload_file_to_dut(dut, file_path, "/tmp/00-copp.config.json") command = "sudo cp /tmp/00-copp.config.json /etc/sonic/copp_config.json" st.config(dut, command) command = "rm /tmp/00-copp.config.json" st.config(dut, command) return True
def grep_total_count(dut,**kwargs): """ :param dut: :param kwargs: :return: """ ret_val = True grep_val = kwargs['grep'] cmd = kwargs['cmd'] output = st.show(dut,"sudo vtysh -c '{}' | grep {} | wc -l".format(cmd,grep_val),skip_tmpl=True) actual_count = int(output.split('\n')[0]) exp_count = int(kwargs['exp_count']) if actual_count != exp_count: st.error("Count Mismatch: Expected-{} Actual-{}".format(exp_count,actual_count)) ret_val = False return ret_val
def mtrace(dut,**kwargs): """ Author : Sooriya G :param dut: :param source: :param group :return: """ if 'source' not in kwargs or 'group' not in kwargs: st.error("Mandatory argument -source or -group is missing") return False source = kwargs['source'] group = kwargs['group'] cmd = 'mtrace {} {}'.format(source,group) output = st.show(dut,cmd,skip_tmpl=True,skip_error_check=True, type='vtysh') return output
def show_config(dut, search_string="", cli_type="klish"): ''' API to show the configured radius parameters Author: Chaitanya Vella ([email protected]) :param dut: :return: {'globals': [{global_auth_type': 'pap (default)','global_source_ip': '10.25.36.25','global_passkey': 'abcd (default)', 'global_timeout': '5 (default)'}], 'servers': [{'auth_type': '', 'passkey': '', 'auth_port': '1815', 'priority': '1', 'timeout': '', 'address': '1.1.1.5'}, {'auth_type': '', 'passkey': '', 'auth_port': '1812', 'priority': '1', 'timeout': '', 'address': '1.1.1.1'}]} ''' st.log("Showing radius configuration ...") result = {"globals": [], "servers": []} if cli_type == "klish": command = "show radius-server" output = st.cli_show(dut, command, "mgmt-user") global_out = dict() for k, v in output[0].items(): if "global" in k: global_out[k] = v if global_out and utils.check_empty_values_in_dict(global_out): result["globals"].append(global_out) for d in output[1:]: server_out = dict() for k, v in d.items(): if not "global" in k: server_out[k] = v if server_out and utils.check_empty_values_in_dict(server_out): result["servers"].append(server_out) elif cli_type == "click": command = "show radius | grep -w {}".format( search_string) if search_string else "show radius" output = st.show(dut, command) for d in output: global_out = dict() server_out = dict() for k, v in d.items(): if "global" in k: global_out[k] = v else: server_out[k] = v if global_out and not utils.check_empty_values_in_dict(global_out): result["globals"].append(global_out) if server_out and not utils.check_empty_values_in_dict(server_out): result["servers"].append(server_out) return result
def show_ip_route_validation_cli(type='click'): st.log("{} validation".format(type)) test_case = 'FtOpSoRtPerfFn053' if type == 'click' else 'FtOpSoRtPerfFn052' start_time = datetime.datetime.now() if "via" not in st.show(dut, "show ip route", type=type, skip_tmpl=True, max_time=300): st.report_tc_fail(test_case, 'test_case_failed') end_time = datetime.datetime.now() st.log("start_time for route display using {}: {} ".format( type, start_time)) st.log("end_time for route display using {}: {} ".format(type, end_time)) time_diff_in_secs = end_time - start_time st.log("time_diff_in_secs: {}".format(time_diff_in_secs)) st.report_tc_pass(test_case, 'test_case_passed')
def verify_pim_nexthop_lookup(dut,**kwargs): """ :param dut: :param source :type string :param group :type string :param interface :type string :param vrf :type string :return: """ ret_val = True if 'vrf' in kwargs: vrf_name = kwargs['vrf'] del kwargs['vrf'] else: vrf_name = 'default' if 'source' not in kwargs or 'group' not in kwargs: st.error("Mandatory arguments -source or -group Missing") return False if vrf_name != 'default': cmd = 'show ip pim vrf {} nexthop-lookup {} {}'.format(vrf_name,kwargs['source'],kwargs['group']) else: cmd = "show ip pim nexthop-lookup {} {}".format(kwargs['source'],kwargs['group']) output = st.show(dut,cmd, type='vtysh') if len(output) == 0: st.error("Output is Empty") return False if 'return_output' in kwargs: return output for key in kwargs: if str(kwargs[key]) != str(output[0][key]): st.error("Match not found for {} : Expected- {} Actual - {}".format(key,kwargs[key],output[0][key])) ret_val = False else: st.log("Match found for {} : Expected- {} Actual - {}".format(key, kwargs[key], output[0][key])) return ret_val
def verify_show_error_db_multi(dut, table, *argv, **kwargs): """ Verify multiple Error Database entries. Author : Prudvi Mangadu ([email protected]) :param : dut: :param : table: :param : result: Expected result(Default True) :param : iteration: default(30) :param : argv: list of dict arguments to verify :return: """ exp_result = kwargs.get("result", True) iteration = kwargs.get("iteration", 30) cli_type = st.get_ui_type(dut, **kwargs) if kwargs.get("interface"): intf_entry_val = kwargs.get("interface") if cli_type == "klish": if vars.config.ifname_type == "alias": intf_entry_val = st.get_other_names( vars.D1, [kwargs.get("interface")])[0] kwargs.update({"interface": intf_entry_val}) command = "show error_database" if table: command = "show error_database {}".format(table) i = 1 while True: output = st.show(dut, command) output = _get_entries_with_native_port(dut, output, **kwargs) st.debug(output) result = True for each_row in argv: row_match = filter_and_select(output, None, each_row) if not row_match: st.log("Entry not found - {}".format(', '.join( ["{}='{}'".format(k, each_row[k]) for k in each_row]))) result = False else: st.log("Entry found - {}".format(', '.join( ["{}='{}'".format(k, each_row[k]) for k in each_row]))) if result == exp_result: return True if i >= iteration: return False i += 1 st.wait(1)
def verify_cpu_queue_counters(dut,queue_name,param_list,val_list,tol_list): ''' Author: Gangadhara Sahu ([email protected]) verifies CPU queue counters in the CLI show CPU queue counters :param dut: Device name where the command to be executed :type dut: string :param queue_name: queue name to be checked :type queue_name: string :param param_list: list of params to be verified; example ['pkts_count', 'pkts_drop'] :param val_list: list of expected values for the params specified; example ['10000','5000'] :param tol_list: tolerence value for each param while comparing; for example ['1000', '500'] :return: True/False True - success case; False - Failure case usage: verify_cpu_queue_counters(dut1,'0',['pkts_count', 'pkts_drop'], ['10000','5000'],['1000', '500']) verify_cpu_queue_counters(dut1,'0',['pkts_count'],['10000'],['1000']) ''' success = True cli_out = st.show(dut,'show queue counters interface CPU queue {}'.format(queue_name),type="klish") fil_out = filter_and_select(cli_out, param_list, {"txq" : "MC"+queue_name}) if not fil_out: st.error('port: CPU and queue name: {} not found in output: {}'.format(queue_name,cli_out)) return False else: fil_out = fil_out[0] for param,val,tol in zip(param_list,val_list,tol_list): try: fil_out[param] = re.sub(",","",fil_out[param]) int(fil_out[param]) except ValueError: st.error('cannot get integer value from obtained string: {}'.format(fil_out[param])) return False if int(fil_out[param])<=int(val)+int(tol) and int(fil_out[param])>=int(val)-int(tol): st.log('obtained value: {} is in the range b/w {} and {} as expected for param: {}' 'in queue: {}'.format(int(fil_out[param]),int(val)-int(tol), int(val)+int(tol),param,queue_name)) else: st.error('obtained value: {} is NOT in the range b/w {} and {} for param: {}' 'in queue: {}'.format(int(fil_out[param]), int(val) - int(tol), int(val) + int(tol), param, queue_name)) success = False return True if success else False