def Gotoshell(): tn = globalvar.TN dirValue = globalvar.LOG_DIR f_name = sys._getframe().f_code.co_name logfile = os.path.join(dirValue, '%s.log') % f_name pattern = 'Password' p = re.compile(re.escape(pattern), re.DOTALL | re.IGNORECASE) tn.write('start shell' + ENTER) time.sleep(1) (index, match, data) = tn.expect([p], timeout=30) #work.writecmdlog(data) work.writelogtofile(logfile, data) if index == -1: strw = recode('板卡登陆shell失败1') print strw work.writerunlog(strw) pattern = 'root' p = re.compile(re.escape(pattern), re.DOTALL | re.IGNORECASE) tn.write('!@#' + ENTER) (index, match, data) = tn.expect([p], timeout=30) #work.writecmdlog(data) work.writelogtofile(logfile, data) if index == -1: strw = recode('板卡登陆shell失败2') print strw work.writerunlog(strw) return SUCCESS_RT
def BootAndGotoLinux(): '''reset and goto linux''' import sys f_name = sys._getframe().f_code.co_name logpath = os.path.join(globalvar.LOG_DIR, '%s.log' % f_name) tn = globalvar.TN cfginfos = globalvar.CFG_INFOS gatewayip = cfginfos['IPINFO']['gateway_ip'] tftp_dir = cfginfos['DL_FILE_VER']['tftp_dir'] linux_file = cfginfos['DL_FILE_VER']['linux_file'] networkip = cfginfos['IPINFO']['network_ip'] print 'BootAndGotoLinux的BOARD_TYPE为 ' + globalvar.BOARD_TYPE if globalvar.BOARD_TYPE == 'YES': cmd0 = 'cpldwrite 0x1c 0x1' cmd1 = 'ifaddr eth0 %s:%s::%s' % (globalvar.IP, networkip, gatewayip) cmd2 = 'load %s%s' % (tftp_dir, linux_file) cmd_list = [cmd0, cmd1, cmd2] for cmd in cmd_list: print '运行命令:' + cmd p = cmd + '.+' + 'PMON' pattern = [re.compile(p, re.IGNORECASE | re.DOTALL)] tn.read_very_eager() time.sleep(0.5) for i in cmd: tn.write(i) time.sleep(0.1) tn.write(ENTER) (index, match, data) = tn.expect(pattern, timeout=400) #work.writecmdlog(data) work.writelogtofile(logpath, data) if index == -1: strw = recode('命令%s执行失败' % cmd) print strw work.writerunlog(strw) return ERROR_RT cmd3 = 'g rdinit=/sbin/init console=ttyS0,115200 bootimage=image bootpart=al0' tn.write(cmd3 + ENTER) # TODO 检查 clock p = cmd3 + '.+' + 'Waiting the system initialize' pattern = [re.compile(p, re.IGNORECASE | re.DOTALL)] tn.read_very_eager() time.sleep(0.5) (index, match, data) = tn.expect(pattern, timeout=400) work.writelogtofile(logpath, data) if index == -1: strw = recode('检查 RTC 失败1') print strw work.writerunlog(strw) return ERROR_RT elif 'setting system clock' not in data: strw = recode('检查 RTC 失败2') print strw work.writerunlog(strw) return ERROR_RT return SUCCESS_RT
def ListenAndGotoUboot(): '''Detect the console info and login the Uboot shell''' import sys f_name = sys._getframe().f_code.co_name logpath = os.path.join(globalvar.LOG_DIR, '%s.log' % f_name) tn = globalvar.TN strw = recode('正在等待板卡进入Uboot...') print strw work.writerunlog(strw) while True: pattern = 'ctrl-p' p = re.compile(pattern, re.DOTALL | re.IGNORECASE) (index, match, data) = tn.expect([p], timeout=300) print data work.writecmdlog(data) work.writelogtofile(logpath, data) if index == -1: strw = recode('板卡进入PMON失败1') print strw work.writerunlog(strw) return ERROR_RT # TODO 检查 mtd1, 不是则 reboot if 'mtd1' in data.split('/dev/fs/')[-1]: tn.write(chr(16)) tn.write(chr(16)) time.sleep(1) tn.write('reboot' + ENTER) else: break if globalvar.BOARD_TYPE == 'YES': tn.write(chr(16)) tn.write(chr(16)) (index, match, data) = tn.expect(['PMON>'], timeout=20) work.writecmdlog(data) work.writelogtofile(logpath, data) if index == -1: strw = recode('板卡进入PMON失败2') print strw work.writerunlog(strw) return ERROR_RT strw = recode('板卡已经进入PMON') print strw work.writerunlog(strw) return SUCCESS_RT
def lowtemp_gotolinuxcheckport(): '''Detect the console info and login the kernel shell''' try: import sys f_name = sys._getframe().f_code.co_name logpath = os.path.join(globalvar.LOG_DIR, '%s.log' % f_name) tn = globalvar.TN tn.read_very_eager() data_log = '' dirValue = globalvar.LOG_DIR logfile = os.path.join(dirValue, '%s.log') % f_name flag = 'PASS' strw = recode('正在等待板卡进入linux kernel...') print strw work.writerunlog(strw) # tn.write(ENTER) # pattern1 = 'The system is going down NOW!' pattern = 'Press RETURN to get started' # pattern = pattern1 + '.+' + pattern2 + '$' p = re.compile(pattern, re.DOTALL | re.IGNORECASE) (index, match, data) = tn.expect([p], timeout=300) print data work.writecmdlog(data) work.writelogtofile(logpath, data) if index == -1: strw = recode('板卡进入linux kernel失败') print strw work.writerunlog(strw) return ERROR_RT # if not globalvar.BOARD_TYPE == 'YES': # if 'setting system clock' not in data: # strw = recode('检查 RTC 失败') # print strw # work.writerunlog(strw) # return ERROR_RT tn.write(ENTER) time.sleep(10) tn.write(ENTER) (index, match, data) = tn.expect(['Switch'], timeout=500) work.writecmdlog(data) work.writelogtofile(logpath, data) if index == -1: strw = recode('板卡登陆linux失败') print strw work.writerunlog(strw) return ERROR_RT pattern = 'Password' p = re.compile(re.escape(pattern), re.DOTALL | re.IGNORECASE) tn.write('enable' + ENTER) (index, match, data) = tn.expect([p], timeout=5) work.writecmdlog(data) work.writelogtofile(logpath, data) if index == -1: strw = recode('板卡登陆linux失败') print strw work.writerunlog(strw) return ERROR_RT pattern = 'Switch#' p = re.compile(re.escape(pattern), re.DOTALL | re.IGNORECASE) tn.write('admin' + ENTER) (index, match, data) = tn.expect([p], timeout=5) work.writecmdlog(data) work.writelogtofile(logpath, data) if index == -1: strw = recode('板卡登陆linux失败') print strw work.writerunlog(strw) return ERROR_RT cmd = 'ctc_shell' tn.write(cmd + ENTER) pattern = 'CTC_CLI\(ctc\-sdk\)#\s*' pattern = re.compile(pattern, re.IGNORECASE | re.DOTALL) (index, match, data) = tn.expect([pattern], timeout=10) data_log = data_log + data work.writecmdlog(data) work.writelogtofile(logfile, data) if index == -1: strw = recode('进入CTC_CLI失败') print strw work.writerunlog(strw) flag = 'FAIL' cmd = 'show port mac-link' for i in cmd: time.sleep(0.2) tn.write(i) tn.write(ENTER) pattern = 'CTC_CLI\(ctc\-sdk\)#' pattern = re.compile(pattern, re.IGNORECASE | re.DOTALL) (index, match, data) = tn.expect([pattern], timeout=10) data_log = data_log + data work.writecmdlog(data) work.writelogtofile(logfile, data) if index == -1: strw = recode('show port mac-link失败') print strw work.writerunlog(strw) flag = 'FAIL' pattern = 'down' p = re.compile(pattern, re.IGNORECASE | re.DOTALL) if p.search(data) != None: strw = recode('抓取到port有down状态...') print strw work.writerunlog(strw) flag = 'FAIL' if flag == "PASS": return SUCCESS_RT else: return ERROR_RT except KeyboardInterrupt: strw = recode('程序执行到[connection.%s]被手动终止' % f_name) print strw return OTHER_ERROR except Exception, err: strw = recode('程序执行到[connection.%s]异常退出!异常信息为%s' % (f_name, err)) print strw return ERROR_RT
def ListenAndGotoLinux(): '''Detect the console info and login the kernel shell''' import sys tt = globalvar.tt f_name = sys._getframe().f_code.co_name logpath = os.path.join(globalvar.LOG_DIR, '%s.log' % f_name) tn = globalvar.TN tn.read_very_eager() strw = recode('正在等待板卡进入linux kernel...') print strw work.writerunlog(strw) # tn.write(ENTER) # pattern1 = 'The system is going down NOW!' pattern = 'Press RETURN to get started' # pattern = pattern1 + '.+' + pattern2 + '$' p = re.compile(pattern, re.DOTALL | re.IGNORECASE) (index, match, data) = tn.expect([p], timeout=300) print data work.writecmdlog(data) work.writelogtofile(logpath, data) if index == -1: strw = recode('板卡进入linux kernel失败') print strw work.writerunlog(strw) return ERROR_RT # if not globalvar.BOARD_TYPE == 'YES': # if 'setting system clock' not in data: # strw = recode('检查 RTC 失败') # print strw # work.writerunlog(strw) # return ERROR_RT tn.write(ENTER) time.sleep(10) tn.write(ENTER) (index, match, data) = tn.expect(['Switch'], timeout=500) work.writecmdlog(data) work.writelogtofile(logpath, data) if index == -1: strw = recode('板卡登陆linux失败') print strw work.writerunlog(strw) return ERROR_RT pattern = 'Password' p = re.compile(re.escape(pattern), re.DOTALL | re.IGNORECASE) tn.write('enable' + ENTER) (index, match, data) = tn.expect([p], timeout=5) work.writecmdlog(data) work.writelogtofile(logpath, data) if index == -1: strw = recode('板卡登陆linux失败') print strw work.writerunlog(strw) return ERROR_RT pattern = 'Switch#' p = re.compile(re.escape(pattern), re.DOTALL | re.IGNORECASE) tn.write('admin' + ENTER) (index, match, data) = tn.expect([p], timeout=5) work.writecmdlog(data) work.writelogtofile(logpath, data) if index == -1: strw = recode('板卡登陆linux失败') print strw work.writerunlog(strw) return ERROR_RT if special.checkportmac() == ERROR_RT: return ERROR_RT strw = recode('板卡已经进入linux kernel') print strw work.writerunlog(strw) time.sleep(5) return SUCCESS_RT
def UpdateFRU(): try: loginfos = globalvar.loginfos tn = globalvar.TN f_name = sys._getframe().f_code.co_name dirValue = globalvar.LOG_DIR logfile = os.path.join(dirValue, '%s.log') % f_name data_log = '' flag = 'PASS' getinfos = globalvar.getinfos if globalvar.BOARD_TYPE == 'YES': # get infos product = runconfig.product connection.Gotoshell() now_time = '"' + time.strftime('%m/%d/%Y %H:%M:%S') + '"' cmd_list = [ 'onie-syseeprom -s 0x21=HW-VX3100A4', 'onie-syseeprom -s 0x2a=32', 'onie-syseeprom -s 0x28=2H-CTC5160-26x1Q', 'onie-syseeprom -s 0x25=%s' % now_time, 'onie-syseeprom -s 0x23=%s' % getinfos['ps'], 'onie-syseeprom -s 0x24=%s' % getinfos['mac'], ] for cmd in cmd_list: pattern, timeout = '$', 10 data = command.CmdGet(tn, cmd, [pattern], timeout) data_log = data_log + data work.writelogtofile(logfile, data) if data == ERROR_RT: flag = 'FAIL' tn.read_very_eager() tn.write(ENTER) tn.expect(['$'], 5) fru_list = [ 'Product Name 0x21 12 HW-VX3100A3', 'MAC Addresses 0x2A 2 32', 'Platform Name 0x28 26 2H-CTC5160-25x1Q', 'Serial Number 0x23 11 %s' % getinfos['ps'], 'Base MAC Address 0x24 6 %s' % getinfos['mac'], ] print getinfos['mac'] cmd = 'onie-syseeprom' pattern = 'Checksum is valid' data = command.CmdGet(tn, cmd, [pattern], timeout) print data data_log = data_log + data work.writelogtofile(logfile, data) if data == ERROR_RT: strw = recode('读取fru信息失败') print strw work.writerunlog(strw) flag = 'FAIL' for pattern in fru_list: p = re.search(pattern, data) if p: strw = recode('更新FRU %s信息成功' % pattern) print strw work.writerunlog(strw) else: strw = recode('更新FRU %s信息成功' % pattern) print strw work.writerunlog(strw) tn.write('exit' + ENTER) loginfos[f_name] = data_log globalvar.loginfos = loginfos strw = recode('%s ...... %s' % (f_name, flag)) print strw work.writerunlog(strw) if flag == "PASS": return SUCCESS_RT else: return ERROR_RT except KeyboardInterrupt: strw = recode('程序执行到[%s]被手动终止' % f_name) print strw work.writerunlog(strw) return OTHER_ERROR except Exception, err: strw = recode('程序执行到[%s]异常退出!异常信息为%s' % (f_name, err)) print strw work.writerunlog(strw) return ERROR_RT