def __del__(self): if self.tail_pid != None: try: il_connections.execute_mml_without_check('kill %s' % self.tail_pid) except: pass if self.tmp_file != None: try: il_connections.execute_mml('rm -f %s' % self.tmp_file) except: pass
def my_exec_mml(self,s,*answers): """ Execute MML command and catch the exception if it fails. If we do not catch the exception then Robot test will crash. """ try: # The org_execute_mml points to connections.execute_mml il_connections.execute_mml_without_check('date "+%a %b %d %H:%M:%S.%N %Z %Y"') ret = org_execute_mml(s,*answers) return ret except Exception,e: raise AssertionError('execute_mml command %s fails: %s' % (s,str(e)))
def stop_monitoring(self): il_connections.execute_mml_without_check('kill %%%s' % self.tail_job.strip('[]')) while True: if il_connections.execute_mml('jobs').find(self.tail_job) < 0: break time.sleep(1) self._get_log_data() self.running = False il_connections.execute_mml('rm -f %s' % self.tmp_file) self.tmp_file = None self.tail_pid = None
def Get_Snapshot_Signal_Msg_Count(log_file, signal_num): cmd = "grep " + "'kernel: dmxmsg: snapshot:'" + " " + log_file output = connections.execute_mml_without_check(cmd) dumplog_list = output.strip().splitlines() log_cout = len(dumplog_list) msg_num = 0 i = 0 signal_hex_number = int(signal_num) while i < log_cout: log_item = dumplog_list[i].strip() re_item = "(?<=number:)\d*%X," % signal_hex_number match = re.findall(re_item, log_item) if match: doc_len = len(log_item.split(',')) msg_num_str = log_item.split(',')[doc_len - 1] msg_num = msg_num_str.strip().split(' ')[1] return msg_num i += 1 print "There is no log with number 0x%X" % signal_hex_number return msg_num
def Get_Snapshot_Top_Five_PID_Count(log_file, recv_fam): cmd = "grep " + "'kernel: dmxmsg: snapshot:'" + " " + log_file output = connections.execute_mml_without_check(cmd) dumplog_list = output.strip().splitlines() log_cout = len(dumplog_list) msg_num = 0 i = 0 while i < log_cout: log_item = dumplog_list[i].strip() re_item_top = "\s*Top 5 PRBs in RU\s*" match_top = re.findall(re_item_top, log_item) if match_top: print "find top 5 prb log \n" re_item_fam = "(?<=\(0x%s\)=)\d*" % recv_fam match_fam = re.findall(re_item_fam, log_item) if match_fam: return match_fam[0].strip() i += 1 print "There is no top log with receiver family 0x%s" % recv_fam return msg_num
def _search_vcp_connection_list_with_conn_id(conn_id): command = """vcp_conn_list -c 0x%s""" %(conn_id) exec_output = connections.execute_mml_without_check(command) items = exec_output.strip().splitlines() vcp_res = {} for item in items: infos = item.split("|") if len(infos) == 10: vcp_res = CommonItem() vcp_res.index = infos[0].strip() vcp_res.conn_id =infos[1].strip() vcp_res.owner_id =infos[2].strip() vcp_res.type =infos[3].strip() local_ip = infos[4].strip().split(":") vcp_res.local_ip=local_ip[1].strip() vcp_res.local_port = local_ip[2].strip() remote_ip = infos[5].strip().split(":") vcp_res.remote_ip=remote_ip[1].strip() vcp_res.remote_port=remote_ip[2].strip() return vcp_res
def search_iu_transport_info_in_tf_table(leg_info): """ This keyword is used to search transport information in TF routine table #COMMAND: lgutilgx RID:USCP-0:1,2; vcp_conn_list -c 0x12345 | Parameters | Man.| Description | | leg_info | Yes | Iu Leg info parsed by keyword create_iucs_leg_with_cac_params | | Return value | two instance of CommonItem, transport info in RM2 and TF table | Example | result | search_iu_transport_info_in_tf_table | ${iu_leg_info} | """ command = """lgutilgx RID:%s:%s,%s""" % (leg_info.computer, leg_info.hand_id, leg_info.focus_id) exec_output = connections.execute_mml_without_check(command) pattern = re.compile("""CONNECTION\s+ID:(\S+)""") leg_pattern = re.compile("""RES_TYPE\s+PRID\s+ENC\s+CAC_ALLOC\s+OUT\s+IPv4\s+(\S+):(\S+)""") rg_pattern = re.compile("""PROVIDER\s+QNUP-(\S+)""") conn_id = pattern.findall(exec_output)[0] rg_index = rg_pattern.findall(exec_output) result = leg_pattern.findall(exec_output) rm2_info = CommonItem() rm2_info.ip = result[0][0] rm2_info.port = result[0][1] eitpuptrm_list = upm_lib.class_all_units_info('QUNP') eitpuptrm_key = 'QNUP-000%d' % (int(rg_index[0])) print "QNUP key:",eitpuptrm_key starter_fileparse.change_ru(eitpuptrm_list[eitpuptrm_key].moname) vcp_info = _search_vcp_connection_list_with_conn_id(conn_id) # if (connections.execute_mml('echo $HW_PLATFORM').count('BCN') > 0): # ssh_eipu = 'ssh EIPU-%d' % (int(rg_index[0])) # connections.execute_mml(ssh_eipu) # for conn_id in result: # vcp_info = _search_vcp_connection_list_with_conn_id(conn_id) # connections.execute_mml('exit') # else: # vcp_info = _search_vcp_connection_list_with_conn_id(conn_id) return rm2_info, vcp_info
def show_ip_address(ipaddress): """ This keyword is used to show the ip address in SCLI #COMMAND: fsclish -c "show show networking address ip-address <ip_addr>" | Parameters | Man. | Description | | ipaddress | Yes | IP address | | Return value | command execution result | Example | result | show_ip_address | 12.0.0.1 | """ command = """fsclish -c "show networking address ip-address %s" """ % ( ipaddress) print "Command: " + command output = connections.execute_mml_without_check(command) if output == "" or output == " ": exceptions.raise_ILError("ILCommandExecuteError", "ip address infomation doesn't exist") if output.find("type") != -1: pattern = re.compile( """\s+IP addresses in\s+\S+\s+instance:\s+(?P<inface>\S+)\s+type\s+:\s+(?P<type>\S+)\s+address\s+:\s+(?P<address>\S+)\s+owner\s+:\s+(?P<owner>\S+)\s+$""" ) else: pattern = re.compile( """\s+IP addresses in\s+\S+\s+instance:\s+(?P<inface>\S+)\s+address\s+:\s+(?P<address>\S+)\s+owner\s+:\s+(?P<owner>\S+)\s+$""" ) match = re.match(pattern, output) if match: return match.groupdict() else: print "not match" exceptions.raise_ILError("ILCommandExecuteError", "ip address infomation doesn't exist") return {}
def execute_dmxmsg_command(computer_id,family_id,command_str,timeout='2000'): """This keyword is to execute specified command | Parameters | Man. | Description | | computer_id | Yes | the computer address | | family_id | Yes | the target family to monitor and send message | | command | Yes | the command to be executed | | Return value | success, if the command executed successfully | Example | result | execute dmxmsg command | 0x700 | 0x1941 | refer | """ if (command_str.strip() == 'time'): command = 'msgmonstub -u %s -f %s -r %s -T %s'%(computer_id,family_id,command_str,timeout) else: command = 'msgmonstub -u %s -f %s -r %s'%(computer_id,family_id,command_str) out = connections.execute_mml_without_check(command) if (command_str.strip() == 'time'): time_out = int(timeout) print 'timeout is:', time_out match = re.search(r"\s*time elapsed:\s*([0-9]*)\s*", out, re.I) if match is not None: time1 = match.group(1) time2 = atoi(str(time1), 10) if (time2 >= time_out) and (time2 < (time_out+99)): return 'success' else: return 'failure' else: return 'failure' if (command_str.strip() == 'mthread'): if out.count('success') ==2: return 'success' else: return 'failure' if out.count('success') ==1: return 'success' else: return 'failure'
def set_ip_based_route_with_specified_parameters(ipbr_id, *args): """ This keyword is used to set ip based route attributes with attribute string description #COMMAND: fsclish -c "add networking ipbr ipbr-id <ipbr_id> ipbr-name <ipbr_name> route-bandwidth <route_bw> " | Parameters | Man. | Description | | ipbr_id | Yes | IPBR ID | | args | No | list of the ipbr attribute string: e.g. ipbr-name=xxx | | Return value | instance of dictionary | Example | result | set_ip_based_route_with_specified_parameters | ${ipbr_id} | ipbr-name=bts1 | """ command = "set networking ipbr ipbr-id %s" % (ipbr_id) for arg in args: items = arg.split("=") command = command + " " + items[0].strip() + " " + items[1].strip() command = """fsclish -c "%s" """ % (command) print "Command:", command output = connections.execute_mml_without_check(command) return _parse_SCLI_command_output('IPBR Modify', output)
def release_iub_leg(call_id, leg_id="IN", computer="USCP-0"): """ This keyword is used to release iub leg #COMMAND: lgutilgx RV:<computer>:<call_id>:<leg_id> | Parameters | Man.| Description | | call_id | Yes | call ID | | leg_id | No | Leg ID | | computer | No | recovery unit where the leg reserved, default is USCP-0 | | Return value | an instance of CommonItem | Example | result | release_iub_leg | ${CALL_ID} | ${LEG_ID}| ${USCP-0} | """ command = """lgutilgx RV:%s:%s:%s""" % (computer, call_id, leg_id) exec_output = connections.execute_mml_without_check(command) if -1 == exec_output.find("RELEASING SUCCESSFUL"): raise exceptions.raise_ILError("ILCommandExecuteError", exec_output) return "success"
def release_iucs_leg(call_id, computer="USCP-0"): """ This keyword is used to release iucs leg # COMMAND: lgutilgx RV:USCP-0:123:OUT | Parameters | Man.| Description | | call_id | Yes | IPBR ID | | computer | No | recovery unit where the leg reserved, default is USCP-0 | | Return value | string "success" when the operation success | Example | result | release_iucs_leg | ${CALL_ID} | ${USCP-0} | """ command = """lgutilgx RV:%s:%s:OUT""" %(computer, call_id) print "execute command:", command exec_output = connections.execute_mml_without_check(command) if -1 == exec_output.find("RELEASING SUCCESSFUL"): raise exceptions.raise_ILError("ILCommandExecuteError", exec_output) return "success"
def check_bin_header_is_correct(dir_name, files_name): """This keyword is to check whether the LIBGEN bin header is correct or not. | Parameters | Man. | Description | | dir_name | Yes | the directory name | | files_name | Yes | the array of files name | | Return value | None | Example | check bin header is correct | monster_test | ["test1-000.bin","test1-001.bin"] | """ bin_header_context = "0000000 0000 000c 0003 0000 0000 0000" file_count = len(files_name) for i in range(file_count): command = "hexdump -n 16 /var/log/" + dir_name + "/" + files_name[i] output = connections.execute_mml_without_check(command) if (output.count(bin_header_context) <= 0): exceptions.raise_ILError( "ILCommandExecuteError", "The LIBGEN bin header is not correct for file: %s." % files_name[i])
def execute_dmxmsg_command_and_check_result(computer_id,family_id,command_str,result,res_count): """This keyword is to execute specified command | Parameters | Man. | Description | | computer_id | Yes | the computer address | | family_id | Yes | the target family to monitor and send message | | command | Yes | the command to be executed | | Return value | success, if the command executed successfully | Example | result | execute dmxmsg command and check result | 0x700 | 0x1941 | register | success | 2 | """ command = 'msgmonstub -u %s -f %s -r %s'%(computer_id,family_id,command_str) out = connections.execute_mml_without_check(command) if out.count(result) == int(res_count): return 'success' else: return 'failure'
def check_whether_process_is_exist_or_not(prb_name): """This keyword is to whether given PRB exist or not | Parameters | Man. | Description | | prb_name | Yes | The name of checked PRB | | Return value | success, if the checked prb exist | Example | result | check whether process is exist or not | ${prb_name} | """ command = 'ps -ef|grep %s'%(prb_name) out = connections.execute_mml_without_check(command) lines = out.strip().splitlines() count = 0 for line in lines: count = count +1 if count ==2: return 'success'
def mod_ip_based_route(ipbr_id, ipbr_name='', route_bw='', commit_bw='', commit_sig_bw='', commit_dcn_bw='', \ ifc_nrtdch='', ifc_nrthsdpa='', scheduler_type='', phb_profile='', dspm_profile='', \ mux_flag='', max_mux_pkt_num='', mux_local_port='', mux_remote_port='', mux_udp_dscp=''): """ This keyword is used to set networking ipbr info by ipbr-id #COMMAND: fsclish -c "set networking ipbr ipbr-id <ipbr_id> ipbr-name <ipbr_name> route-bandwidth <route_bw> " | Parameters | Man. | Description | | ipbr_id | Yes | IPBR ID | | ipbr_name | No | IPBR_name | | route_bw | No | route bandwidth | | commit_bw | No | committed bandwidth | | commit_sig_bw | No | committed signaling bandwidth | | commit_dcn_bw | No | committed DCN bandwidth | | ifc_flag | No | IFC flag(enabled,disabled) | | ratio | No | Ratio for Iur/Iub+Iur | | scheduler_type | No | scheduler type(None, VQ, RQ) | | phb_profile | No | phb profile id | | dspm_profile | No | dspm profile id | | mux_flag | No | specify whether enable mux function | | max_mux_pkt_num| No | specify max mux packets number | | mux_local_port | No | specify local mux port: range 49152~65535, default is 65535 | | mux_remote_port| No | specify remote mux port: range 49152~65535, default is 65535 | | mux_udp_dscp | No | specify mux DSCP value: range 0~63, default is 46 | | Return value | instance of dictionary | Example | result | mod_ip_based_route | 123 | bts-1 | 123124 | """ ipbr_attributes_list_str = _set_ipbr_attributes_list_str(ipbr_id, ipbr_name, route_bw, commit_bw, \ commit_sig_bw, commit_dcn_bw, ifc_nrtdch, ifc_nrthsdpa, \ scheduler_type, phb_profile, dspm_profile, mux_flag, \ max_mux_pkt_num, mux_local_port, mux_remote_port, mux_udp_dscp) command = 'fsclish -c "set networking ipbr %s"' % ( ipbr_attributes_list_str) print "Command:", command output_str = connections.execute_mml_without_check(command) return _parse_SCLI_command_output('IPBR Modify', output_str)
def _get_available_ip_with_sepcified_recovery_group_type(rg_type): command = 'fsclish -c "show networking instance default address"' output = connections.execute_mml_without_check(command) if output.find('type') != -1: ip_addr_pattern_str = "(\w+)\s+type\s+:\s+(\w+)\s+address\s+:\s+(\d+.\d+.\d+.\d+)/(\d+)\s+owner\s+:\s+(\S+)" iface_index = 0 addr_index = 2 owner_index = 4 else: ip_addr_pattern_str = "(\w+)\s+address\s+:\s+(\d+.\d+.\d+.\d+)/(\d+)\s+owner\s+:\s+(\S+)" iface_index = 0 addr_index = 1 owner_index = 3 ip_addr_list = re.findall(ip_addr_pattern_str, output) eitp_ip_list = [] for ip_info in ip_addr_list: if ip_info[addr_index].startswith('169.254'): continue if -1 == ip_info[owner_index].find(rg_type): continue temp_items = ip_info[owner_index].split('-') if len(temp_items) == 1: index = 0 else: index = atoi(temp_items[1]) if index >= len(eitp_ip_list): for i in range(len(eitp_ip_list), index + 1): eitp_ip_list.append([]) ip_content = CommonItem() ip_content.rg_name = ip_info[owner_index] ip_content.ip_addr = ip_info[addr_index] ip_content.iface = ip_info[iface_index] eitp_ip_list[index].append(ip_content) return eitp_ip_list
def send_message_to_test_process_with_condition_by_libdmxmsg(monitor_computer_id,receiver_computer_id, family_id,process_id,condition,ncount=10,delay=3,data="'01 34 56 ff 01 21'",retry=3): """This keyword is to trigger CLI to send message to test process by libdmxmsg and catch the received message with condition by monster #COMMAND: testmon.py -p "-u monitor_computer_id -f family_id -c contion" -c "montest -u receiver_computer_id -f family_id -p process_id -d data -n ncount" -t delay | Parameters | Man. | Description | | monitor_computer_id | Yes | the computer address monster to monitor | | receiver_comptuer_id | Yes | the target computer address message sent to | | family_id | Yes | the target family to monitor and send message| | process_id | Yes | the target process id to send message to | | condition | Yes | condition used by monster to filter the message out | | ncount | No | the message count send out | | delay | No | delay time python script will kill monster process after message sent out | | data | No | the message data vlaue | | Return value | command str, the catched message string monitored by monster | Example | ${result} | send message to test process with condition by libdmxmsg | 0x700 | 0x700 | 0x1942 | 0 | ":NUM=FF01" | """ command='testmon.py -p "-u %s -f %s -V -c %s" -c "msgmonstub -u %s -f %s -p %s -d %s -n %s" -t %s -r %s'%(monitor_computer_id,family_id,condition,receiver_computer_id,family_id,process_id,data,ncount,delay,retry) out = connections.execute_mml_without_check(command) return out
def get_GCU_info(): """ This keyword is used to basic ipbr config information from CAC PRB #COMMAND: ilfunitcli -lx | Parameters | Man. | Description | | None | | | | Return value | String | Example | result | get_GCU_info | | """ command = 'ilfunitcli -lx' print "Command:", command output = connections.execute_mml_without_check(command) pattern = re.compile(r'\s*GCU-1\s+\S+\s+\S+\s+\S+\s+\S+\s+(\S+)', re.S) result = re.findall(pattern, output) result1 = result[0] print result print result1 return result1
def dmxcli2_sending(options): """ This keyword is to return execution result contains "**SUCCESS**" when funcs implemented successful. #COMMAND: dmxcli2 Usage: dmxcli2 [options] 1. dmxcli2 -h / -? :Show this help message. 2. dmxcli2 -s comp.fam :Send a message to dest pid. 3. dmxcli2 -r comp[.fam[.timeout]] :Receive a message from pid. e.g. -r 0.ad9c :Receive from 0.ad9c.0. Wait for ever. e.g. -r 1.?.1000 :Receive from computer 1 and any family. Timeout 1000MS. e.g. -r ?.?.50 :Receive from any computer and any family. Timeout 50MS. 4. dmxcli2 -m wosp_logic_addr :Check last warming message. e.g. -m 7002 :Must be WOSP logical address. 5. dmxcli2 -w wosp_logic_addr :Check WO message is faster than SP. e.g. -w 7002 :Must be WOSP logical address. 6. dmxcli2 -u unit_addr=unit_state :Update RU state. Addr and state are all hexadecimal. e.g. -u 0100=F :Unit_addr must be physical address. 0xF means UNIT_STATE_T_WO_C. 7. dmxcli2 -c unit_addr=co_uaddr :Update RU co-unit address. (Hexadecimal) e.g. -c 0100=0200 :Both address must be physical addr. 8. dmxcli2 -U uaddr,ustate,counit :Update RU state and co-unit at one time. e.g. -U 100,0,200 :Set RU 100's state to WO, and co-unit addr is 200. 9. dmxcli2 -C unit,log,wosp,wo,sp :Config logical address. This will modify the computer table. e.g. -C 1F0,4FF0,FF7,0,100 :Config logical address 7FF0. 10.dmxcli2 -G grp,num,addr1,... :Config group address. This will modify the group table. e.g. -G FF7,2,0,100 :Config group address FF7. 11.dmxcli2 -Q unit_addr :Query unit state by unit address. e.g. -Q 0100 :Query unit state of 0x0100. Return value will be 'State,CoUnit'. 12.dmxcli2 -q RUType[,n] :Query RU computer table info. Such as logical addr, Physical address, ... Optional 'n' :0=All, 1=PhysAddr, 2=LogAddr, 3=Log_GroupAddr, 4=Group_LogAddr, 5=Processor_index. e.g. -q Unit_Type,0 :Query all info about unit type. 13.dmxcli2 -o :Query own physical address. Example | dmxcli2_sending |-s 0.ad9c.0| """ command = "dmxcli2 " + options out = connections.execute_mml_without_check(command) return out
def Check_Snapshot_Time_Scape_Less_Then_Expected_Value(log_file, end_str, expect_time): cmd = "grep '" + end_str + "' " + log_file output = connections.execute_mml_without_check(cmd) end_log = output.strip() if len(end_log) == 0: print "There is no end log" result = 0 else: stack_time = end_log.split(',')[3] print stack_time time_value = stack_time.split('=')[1] if int(time_value) < int(expect_time): result = 1 else: print "time value is: %s, expect_time is: %s\n" % (time_value, expect_time) result = 0 if result == 1: return "successful" else: return "error"
def del_ip_based_route(ipbr_id, ipbr_name=""): """ This keyword is to used to delete an ip based route. #COMMAND: fsclish -c "delete networking ipbr ipbr-id <IPBR ID> ipbr-name <IPBR Name>" | Parameters | Man. | Description | | ipbr_id | Yes | IPBR ID | | ipbr_name | No | IPBR Name | | Return value | an instance of dictionay | Example | result | del_ip_based_route | 123 | """ ipbr_attributes_list_str = _set_ipbr_attributes_list_str( ipbr_id, ipbr_name) command = """fsclish -c "delete networking ipbr %s" """ % ( ipbr_attributes_list_str) output_str = connections.execute_mml_without_check(command) return _parse_SCLI_command_output('IPBR Delete', output_str)
def testcli_send_message_to_test_process(receiver_computer_id, family_id,process_id,ncount=10,data="'01 34 56 ff 01 21'"): """This keyword is to trigger CLI to send message to test process #COMMAND: montest -u receiver_computer_id -f family_id -p process_id -d data -n ncount | Parameters | Man. | Description | | receiver_comptuer_id | Yes | the target computer address message sent to | | family_id | Yes | the target family to monitor and send message| | process_id | Yes | the target process id to send message to | | ncount | No | the message count send out | | data | No | the message data vlaue | | Return value | command str, success for only 1 string of 'Next working' in the execute result | Example | ${result} | test cli send message to test process | 0x200 | 0x193B | 0 | """ command='montest -f 0xffff -- -u %s -f %s -p %s -d %s -n %s'%(receiver_computer_id,family_id,process_id,data,ncount) out = connections.execute_mml_without_check(command) if out.count('Next working') == 1: return 'success' else: return 'failure'
def create_iur_leg_with_cac_params(call_id, ipbr_id, params="", computer="USCP-0"): """ This keyword is used to create Iur leg with CACPRB parameters #COMMAND: lgutilgx RRI:USCP-0:7D1:IN,:,,,12,13:1::NCAC=0 | Parameters | Man.| Description | | call_id | Yes | Call ID | | ipbr_id_1 | Yes | IPBR ID | | params | No | traffic parameters used for leg creation | | computer | No | Recovery Unit specified to create leg, default is USCP-0 | | Return value | an instance of CommonItem | Example | result | create_iur_leg_with_cac_params | ${Call_ID} | ${IPBR_ID_1} | NCAC=0 | ${USCP-0}| """ command = """lgutilgx RRI:%s:%s:IN,:,,,%s:1::%s""" %(computer, call_id, ipbr_id, params) print "execute command:", command exec_output = connections.execute_mml_without_check(command) result = _parse_in_leg_creation_output(exec_output) result.computer = computer return result
def Generic_Send_Msg(selffamily, target, number='', length='', sequence='', interval='', back_groud='', quite_flag=''): command = "dmx_generic_stub send " + selffamily + " " + target if number != '': command += " -n " + number if length != '': command += " -l " + length if sequence != '': command += " -s " + sequence if interval != '': command += " -i " + interval if quite_flag != '': command += " -q " if back_groud != '': command += "&" out = connections.execute_mml_without_check(command) return out
def dmxcli2_Config_grp_addr_1(grp_addr, processor_index, uindex_offset): """This keyword Config group address. This will modify the group table. #COMMAND: dmxcli2 -G grp,num,addr1, | Parameters | Man. | Description | | grp_addr | Yes | Group Address | | processor_index | Yes | processor index | | uindex_offset | Yes | uindex offset | | Return value | **SUCCESS** of **FAILURE** | Example | ${result} | dmxcli2 -G FF7,2,0,100. | """ processor_index = "0x" + processor_index uindex_offset = "0x" + uindex_offset sum = int(processor_index, 16) + int(uindex_offset, 16) sum = hex(sum) addr = str(sum) print addr command = "dmxcli2 -G " + str(grp_addr) + ",1," + addr out = connections.execute_mml_without_check(command) return out
def Get_Snapshot_Sender_And_Signal_Count(log_file, send_fam, signal_num): cmd = "grep " + "'kernel: dmxmsg: snapshot:'" + " " + log_file output = connections.execute_mml_without_check(cmd) dumplog_list = output.strip().splitlines() log_cout = len(dumplog_list) msg_num = 0 i = 0 signal_hex_number = int(signal_num) while i < log_cout: log_item = dumplog_list[i].strip() re_item_sig = "(?<=number:)\d*%X," % signal_hex_number match_sig = re.findall(re_item_sig, log_item) if match_sig: re_item_fam = "(?<=PID:\d{4}:)\d*%s:\d{4}, attr:" % send_fam match_fam = re.findall(re_item_fam, log_item) if match_fam: doc_len = len(log_item.split(',')) msg_num_str = log_item.split(',')[doc_len - 1] msg_num = msg_num_str.strip().split(' ')[1] return msg_num i += 1 print "There is no log with sender family 0x%x, number 0x%X " % ( send_fam, signal_hex_number) return msg_num
def inquiry_gtp_conn_resource_info(ip_address='', teid='', vrf_id='', filter = 'true'): """ This keyword is used to inquiry specified GTP connection resource in CACPRB #COMMAND: iltrmcli -S -g TEID | Parameters | Man.| Description | | ip_addr | Yes | IP address | | teid | Yes | GTP tunnel ID | | vrf_id | No | Instance ID of virtual routing forward | | filter | No | Filter whether add the reserved, free, buffer info into the list | | Return value | an instance of CommonItem | Example | result | inquiry gtp conn resource info | ${IP_address} | ${GTP_TEID} | """ teid_hex = "0x%s" %(teid) command = "iltrmcli -S -g %s" %(teid_hex) #if vrf_id !='' and connections.execute_mml('echo $HW_PLATFORM').count('FTLB') == 0: # command = command + " -v %s" %(vrf_id) print "Command:", command exec_output = connections.execute_mml_without_check(command) return _parse_conn_info(exec_output, filter)
def copy_file(file1, file2): """This keyword is to copy file1 to file2 us cp command #COMMAND: cp | Parameters | Man. | Description | | file1 | Yes | source file name | file2 | Yes | destination name | Return value | Successful: True, Failure: False | Example | ${result} | copy_file | test.txt | test.bak | | Should Be True | ${result} | """ #just copying file/folder but not symbol links command = "cp -rfL %s %s" % (file1, file2) out = connections.execute_mml_without_check(command, 'y') if out.count("Read-only file system") != 0: connections.execute_mml("mount -o rw,remount /mnt/sysimg") connections.execute_cli(command, 'y') return True
def release_all_udp_conn_resource(): """ This keyword is used to release all UDP connection resource in CACPRB #COMMAND: iltrmcli -D -u all | Parameters | Man.| Description | | | | | | Return value | an instance of String, success or failed | Example | result | release all udp conn resource | """ command = "iltrmcli -D -u all" print "Command:", command exec_output = connections.execute_mml_without_check(command) return_value = CommonItem() if (-1 != exec_output.lower().find("success")): return_value.result = "success" else: return_value.result = "failed" return return_value
def dmxcli2_launch_command(cmd, param): command = "dmxcli2 " + cmd + " " + param out = connections.execute_mml_without_check(command) return out
def Get_Snapshot_Family_Count(log_file, recv_fam): cmd = "grep " + "'kernel: dmxmsg: snapshot:'" + " " + log_file + " | " + "grep " + "'next:[0-9A-F]\{4\}, PID:[0-9A-F]\{4\}:0\{0,3\}'" + recv_fam + "':[0-9A-F]\{4\},'" + " | wc -l" dumplog = connections.execute_mml_without_check(cmd) log_count = dumplog.strip() return str(log_count)
def create_low_memory(disk_file): command = "free" output = connections.execute_mml_without_check(command) print output command = "free -g | grep Mem: |awk -F \" \" \'{print $4}\'" output = connections.execute_mml_without_check(command) memo_g = output.strip() print "create memory %s G" % memo_g mount_size = int(memo_g) + 1 mount_size = str(mount_size) command = 'mkdir ' + disk_file connections.execute_mml_without_check(command) command = 'mount -t tmpfs -o nosuid,mode=777,size=' + mount_size + 'G,rw tmpfs ' + disk_file connections.execute_mml_without_check(command) command = 'cd ' + disk_file connections.execute_mml_without_check(command) command = 'dd if=/dev/zero of=emptyfile bs=1M count=' + memo_g + '000' output = connections.execute_mml_without_check(command) command = "free" output = connections.execute_mml_without_check(command) print output command = "free -m | grep Mem: |awk -F \" \" \'{print $4}\'" output = connections.execute_mml_without_check(command) memo_m = output.strip() print "memo_m is: %s M" % memo_m cp_size = int(memo_m, 10) cp_size = cp_size / 2 - 10 size = str(cp_size) print "write buffer %s M" % size command = 'dd if=/dev/zero of=occupyfile bs=1M count=' + size output = connections.execute_mml_without_check(command) command = 'cd /root;' output = connections.execute_mml_without_check(command) command = 'free;ll ' + disk_file + "/*" output = connections.execute_mml_without_check(command) print output