def z_finish(self): CMM.save_data( MAIN_LOG, "{0} {1}".format("PASS:"******"FAIL:", module_name.replace("_", " "))) infos = map(lambda x: "INFO: {0}".format(x), MAIN_LOG_list) for info in infos: CMM.save_data(MAIN_LOG, info, timestamp=False) time.sleep(5) if not CASE_PASS: temp_text = "Flash CMM firmware FAIL, exit..." CMM.save_data(MAIN_LOG, temp_text) CMM.show_message(temp_text, timestamp=False, color="red") os._exit(1) else: """ 刷新固件后 如果不能正常登录网页(retry_count=3) 则退出整个测试 """ time.sleep(CMM_RESTORE_TIME) status, output = CMM.curl_login_logout(IP, flag="login", username=USERNAME, password=PASSWORD, retry_count=3) if status == 0 and output: csrftoken = output.strip() time.sleep(1) current_version = checkFwVersion() temp_text = "- Current FW version: {0}".format(current_version) CMM.save_data(MAIN_LOG, "INFO: {0}".format(temp_text), timestamp=False) CMM.save_data(main_log, temp_text, timestamp=False) if current_version == "Unknown": CMM.show_message(temp_text, timestamp=False, color="red") os._exit(1) else: CMM.show_message(temp_text, timestamp=False, color="blue") time.sleep(1) status, output = CMM.curl_login_logout(IP, flag="logout", username=USERNAME, password=PASSWORD, csrf_token=csrftoken) if status != 0: temp_text = "Logout Web FAIL after update firmware, exit..." CMM.save_data(MAIN_LOG, temp_text, timestamp=False) CMM.show_message(temp_text, timestamp=False, color="red") os._exit(1) else: temp_text = "Login Web FAIL after update firmware, exit..." CMM.save_data(MAIN_LOG, temp_text, timestamp=False) CMM.show_message(temp_text, timestamp=False, color="red") os._exit(1)
def c_curl_login(self): global CASE_PASS global LOGIN_FAIL global CSRFToken if DOWNLOAD_FW_FAIL: LOGIN_FAIL = True return False CMM.show_message(format_item("Login Web"), color="green", timestamp=False) status, output = CMM.curl_login_logout(IP, flag="login", username=USERNAME, password=PASSWORD) if status == 0: message = "[curl] Login Web successfully." CMM.save_data(main_log, message, timestamp=False) show_step_result("[curl] Login Web", flag="PASS") CSRFToken = output.strip() else: CASE_PASS = False message = "[curl] Login Web FAIL !" MAIN_LOG_list.append(message) message = "{0}\n{1}".format(message, output) CMM.save_data(main_log, message, timestamp=False) show_step_result("[curl] Login Web", flag="FAIL") LOGIN_FAIL = True
def y_curl_logout(self): if LOGIN_FAIL: return False message = "Logout Web" CMM.show_message(format_item(message),color="green",timestamp=False) status, output = CMM.curl_login_logout(IP, flag="logout", username=USERNAME, password=PASSWORD, csrf_token=CSRFToken) if status == 0: show_step_result(message,"PASS") CMM.save_step_result(main_log,message,"PASS") else: show_step_result(message,"FAIL") CMM.save_step_result(main_log,message,"FAIL")
def b_curl_login(self): global CASE_PASS global LOGIN_FAIL global CSRFToken message = "Login Web" CMM.show_message(format_item(message),color="green",timestamp=False) status, output = CMM.curl_login_logout(IP, flag="login", username=USERNAME, password=PASSWORD) if status == 0: show_step_result(message, flag="PASS") CMM.save_step_result(main_log,message,"PASS") CSRFToken = output.strip() else: LOGIN_FAIL = True CASE_PASS = False show_step_result(message,"FAIL") CMM.save_step_result(main_log,message,"FAIL") MAIN_LOG_list.append("{0} FAIL !".format(message))
def y_curl_logout(self): global CASE_PASS if LOGIN_FAIL: return False message = "- Logout Web -" CMM.show_message(format_item(message), color="green", timestamp=False) temp_text = message.strip(" -") status, output = CMM.curl_login_logout(IP, flag="logout", username=USERNAME, password=PASSWORD, csrf_token=CSRFToken) if status == 0: show_step_result(temp_text, "PASS") CMM.save_step_result(main_log, temp_text, "PASS") else: CASE_PASS = False show_step_result(temp_text, "FAIL") CMM.save_step_result(main_log, temp_text, "FAIL")
def f_curl_login(self): global CASE_PASS global LOGIN_FAIL global CSRFToken if PING_FAIL: LOGIN_FAIL = True return False message = "- Login Web -" CMM.show_message(format_item(message), color="green", timestamp=False) temp_text = message.strip(" -") status, output = CMM.curl_login_logout(IP, flag="login", username=USERNAME, password=PASSWORD, retry_count=3) if status == 0: CSRFToken = output.strip() show_step_result(temp_text, "PASS") CMM.save_step_result(main_log, temp_text, "PASS") else: LOGIN_FAIL = True CASE_PASS = False show_step_result(temp_text, "FAIL") CMM.save_step_result(main_log, temp_text, "FAIL")
def CollectAPIInfo(baseline=False,login_time=300): global CSRFToken global API_TEMP global API_BASELINE API_TEMP = {} collect_baseline = True LOGIN_FAIL = False output = "" start_time = datetime.datetime.now() """ Retry login after CMM reset """ while CMM.calc_time_interval(start_time, datetime.datetime.now()) < login_time: status, output = CMM.curl_login_logout(IP, flag="login", username=USERNAME, password=PASSWORD) if status == 0: message = "Login Web" CMM.save_step_result(main_log,message,flag="PASS") show_step_result(message,flag="PASS") CSRFToken = output.strip() break time.sleep(10) else: message = "[curl] Login Web FAIL after {0} seconds !\n{1}".format(login_time,output) CMM.save_data(main_log, message,timestamp=False) CMM.show_message(message,timestamp=False,color="red") MAIN_LOG_list.append(message) LOGIN_FAIL = True if not LOGIN_FAIL: """ API检测PSU信息 """ for psu_id in range(1,PSU_NUM+1): temp_dict = {} # check_list = ["Vendor","isPSUOn","SN","psuPresent","Model","FanDuty","id","Present"] check_list = ["Vendor","isPSUOn","SN","psuPresent","Model","id","Present"] cmd = "curl -X POST -H \"Content-Type:application/json\" -H \"X-CSRFTOKEN:%s\" -d \"{'id':%s}\" http://%s%s -b cookie 2>/dev/null" % (CSRFToken, psu_id, IP, GET_PSU_API) if baseline: status, output = CMM.retry_run_cmd(cmd) if status == 0: try: temp = eval(output) except Exception as e: message = "[PSU{0}] {1}".format(psu_id,e) CMM.show_message(message,timestamp=False,color="red") CMM.save_data(main_log,message,timestamp=False) collect_baseline = False else: if temp.get("error"): collect_baseline = False else: for item in check_list: temp_dict[item] = temp.get(item) else: collect_baseline = False API_BASELINE["psu_{0}".format(psu_id)] = temp_dict else: status, output = CMM.retry_run_cmd(cmd) if status == 0: try: temp = eval(output) except Exception as e: message = "[PSU{0}] {1}".format(psu_id,e) CMM.show_message(message,timestamp=False,color="red") CMM.save_data(main_log, message, timestamp=False) else: if not temp.get("error"): for item in check_list: temp_dict[item] = temp.get(item) API_TEMP["psu_{0}".format(psu_id)] = temp_dict time.sleep(1) """ API检测FAN信息 """ for fan_id in range(1,FAN_NUM+1): temp_dict = {} # check_list = ["id","FanPresent","Present","FanStatus","Duty"] check_list = ["id","FanPresent","Present","FanStatus"] cmd = "curl -X POST -H \"Content-Type:application/json\" -H \"X-CSRFTOKEN:%s\" -d \"{'id':%s}\" http://%s%s -b cookie 2>/dev/null" %(CSRFToken,fan_id,IP,GET_FAN_API) if baseline: status, output = CMM.retry_run_cmd(cmd) if status == 0: try: temp = eval(output) except Exception as e: message = "[FAN{0}] {1}".format(fan_id,e) CMM.show_message(message,timestamp=False,color="red") CMM.save_data(main_log, message, timestamp=False) collect_baseline = False else: if isinstance(temp,list): temp = temp[0] if temp.get("error"): collect_baseline = False else: for item in check_list: temp_dict[item] = temp.get(item) else: collect_baseline = False API_BASELINE["fan_{0}".format(fan_id)] = temp_dict else: status, output = CMM.retry_run_cmd(cmd) if status == 0: try: temp = eval(output) except Exception as e: message = "[FAN{0}] {1}".format(fan_id,e) CMM.show_message(message,timestamp=False,color="red") CMM.save_data(main_log, message, timestamp=False) else: if isinstance(temp, list): temp = temp[0] if not temp.get("error"): for item in check_list: temp_dict[item] = temp.get(item) API_TEMP["fan_{0}".format(fan_id)] = temp_dict time.sleep(1) """ API检测Switch信息 """ for switch_id in range(1,SWITCH_NUM+1): temp_dict = {} check_list = ["id","swPresent","Present","Status","Vendor","SwitchType","IP","Netmask","Gateway"] cmd = "curl -X POST -H \"Content-Type:application/json\" -H \"X-CSRFTOKEN:%s\" -d \"{'id':%s}\" http://%s%s -b cookie 2>/dev/null" %(CSRFToken,switch_id,IP,GET_SWITCH_API) if baseline: status, output = CMM.retry_run_cmd(cmd) if status == 0: try: temp = eval(output) except Exception as e: message = "[Switch{0}] {1}".format(switch_id,e) CMM.show_message(message,timestamp=False,color="red") CMM.save_data(main_log, message, timestamp=False) collect_baseline = False else: if temp.get("error"): collect_baseline = False else: for item in check_list: temp_dict[item] = temp.get(item) else: collect_baseline = False API_BASELINE["switch_{0}".format(switch_id)] = temp_dict else: status, output = CMM.retry_run_cmd(cmd) if status == 0: try: temp = eval(output) except Exception as e: message = "[Switch{0}] {1}".format(switch_id,e) CMM.show_message(message,timestamp=False,color="red") CMM.save_data(main_log, message, timestamp=False) else: if not temp.get("error"): for item in check_list: temp_dict[item] = temp.get(item) API_TEMP["switch_{0}".format(switch_id)] = temp_dict time.sleep(1) """ API检测Node信息 """ for node_id in range(NODE_NUM): API_id = node_id + 1 temp_dict = {} check_list = { "present": "curl -X POST -H \"Content-Type:application/json\" -H \"X-CSRFTOKEN:%s\" -d \"{'nodeid':%s,'parameter':3,'paramdata1':%s,'paramdata2':%s}\" http://%s%s -b cookie 2>/dev/null" %(CSRFToken,API_id,"0","0",IP,GET_SINGLENODE_API), "PwrState": "curl -X POST -H \"Content-Type:application/json\" -H \"X-CSRFTOKEN:%s\" -d \"{'nodeid':%s,'parameter':1,'paramdata1':%s,'paramdata2':%s}\" http://%s%s -b cookie 2>/dev/null" %(CSRFToken,API_id,"0","0",IP,GET_SINGLENODE_API), "UID": "curl -X POST -H \"Content-Type:application/json\" -H \"X-CSRFTOKEN:%s\" -d \"{'nodeid':%s,'parameter':7,'paramdata1':%s,'paramdata2':%s}\" http://%s%s -b cookie 2>/dev/null" %(CSRFToken,API_id,"0","0",IP,GET_SINGLENODE_API), "LAN1_IPv4Addr": "curl -X POST -H \"Content-Type:application/json\" -H \"X-CSRFTOKEN:%s\" -d \"{'nodeid':%s,'parameter':11,'paramdata1':%s,'paramdata2':%s}\" http://%s%s -b cookie 2>/dev/null" %(CSRFToken,API_id,1,3,IP,GET_SINGLENODE_API), "LAN8_IPv4Addr": "curl -X POST -H \"Content-Type:application/json\" -H \"X-CSRFTOKEN:%s\" -d \"{'nodeid':%s,'parameter':11,'paramdata1':%s,'paramdata2':%s}\" http://%s%s -b cookie 2>/dev/null" %(CSRFToken,API_id,8,3,IP,GET_SINGLENODE_API), "LAN1_IPv4Src": "curl -X POST -H \"Content-Type:application/json\" -H \"X-CSRFTOKEN:%s\" -d \"{'nodeid':%s,'parameter':11,'paramdata1':%s,'paramdata2':%s}\" http://%s%s -b cookie 2>/dev/null" %(CSRFToken,API_id,1,4,IP,GET_SINGLENODE_API), "LAN8_IPv4Src": "curl -X POST -H \"Content-Type:application/json\" -H \"X-CSRFTOKEN:%s\" -d \"{'nodeid':%s,'parameter':11,'paramdata1':%s,'paramdata2':%s}\" http://%s%s -b cookie 2>/dev/null" %(CSRFToken,API_id,8,4,IP,GET_SINGLENODE_API), "LAN1_MACAddr": "curl -X POST -H \"Content-Type:application/json\" -H \"X-CSRFTOKEN:%s\" -d \"{'nodeid':%s,'parameter':11,'paramdata1':%s,'paramdata2':%s}\" http://%s%s -b cookie 2>/dev/null" % (CSRFToken, API_id, 1, 5, IP, GET_SINGLENODE_API), "LAN8_MACAddr": "curl -X POST -H \"Content-Type:application/json\" -H \"X-CSRFTOKEN:%s\" -d \"{'nodeid':%s,'parameter':11,'paramdata1':%s,'paramdata2':%s}\" http://%s%s -b cookie 2>/dev/null" % (CSRFToken, API_id, 8, 5, IP, GET_SINGLENODE_API), "LAN1_IPv4SubMask": "curl -X POST -H \"Content-Type:application/json\" -H \"X-CSRFTOKEN:%s\" -d \"{'nodeid':%s,'parameter':11,'paramdata1':%s,'paramdata2':%s}\" http://%s%s -b cookie 2>/dev/null" % (CSRFToken, API_id, 1, 6, IP, GET_SINGLENODE_API), "LAN8_IPv4SubMask": "curl -X POST -H \"Content-Type:application/json\" -H \"X-CSRFTOKEN:%s\" -d \"{'nodeid':%s,'parameter':11,'paramdata1':%s,'paramdata2':%s}\" http://%s%s -b cookie 2>/dev/null" % (CSRFToken, API_id, 8, 6, IP, GET_SINGLENODE_API), "LAN1_IPv4DefGateway": "curl -X POST -H \"Content-Type:application/json\" -H \"X-CSRFTOKEN:%s\" -d \"{'nodeid':%s,'parameter':11,'paramdata1':%s,'paramdata2':%s}\" http://%s%s -b cookie 2>/dev/null" % (CSRFToken, API_id, 1, 12, IP, GET_SINGLENODE_API), "LAN8_IPv4DefGateway": "curl -X POST -H \"Content-Type:application/json\" -H \"X-CSRFTOKEN:%s\" -d \"{'nodeid':%s,'parameter':11,'paramdata1':%s,'paramdata2':%s}\" http://%s%s -b cookie 2>/dev/null" % (CSRFToken, API_id, 8, 12, IP, GET_SINGLENODE_API), "LAN1_VlanID": "curl -X POST -H \"Content-Type:application/json\" -H \"X-CSRFTOKEN:%s\" -d \"{'nodeid':%s,'parameter':11,'paramdata1':%s,'paramdata2':%s}\" http://%s%s -b cookie 2>/dev/null" % (CSRFToken, API_id, 1, 20, IP, GET_SINGLENODE_API), "LAN8_VlanID": "curl -X POST -H \"Content-Type:application/json\" -H \"X-CSRFTOKEN:%s\" -d \"{'nodeid':%s,'parameter':11,'paramdata1':%s,'paramdata2':%s}\" http://%s%s -b cookie 2>/dev/null" % (CSRFToken, API_id, 8, 20, IP, GET_SINGLENODE_API), "LAN1_IPv6Enable": "curl -X POST -H \"Content-Type:application/json\" -H \"X-CSRFTOKEN:%s\" -d \"{'nodeid':%s,'parameter':11,'paramdata1':%s,'paramdata2':%s}\" http://%s%s -b cookie 2>/dev/null" % (CSRFToken, API_id, 1, 195, IP, GET_SINGLENODE_API), "LAN8_IPv6Enable": "curl -X POST -H \"Content-Type:application/json\" -H \"X-CSRFTOKEN:%s\" -d \"{'nodeid':%s,'parameter':11,'paramdata1':%s,'paramdata2':%s}\" http://%s%s -b cookie 2>/dev/null" % (CSRFToken, API_id, 8, 195, IP, GET_SINGLENODE_API), "LAN1_IPv6Src": "curl -X POST -H \"Content-Type:application/json\" -H \"X-CSRFTOKEN:%s\" -d \"{'nodeid':%s,'parameter':11,'paramdata1':%s,'paramdata2':%s}\" http://%s%s -b cookie 2>/dev/null" % (CSRFToken, API_id, 1, 196, IP, GET_SINGLENODE_API), "LAN8_IPv6Src": "curl -X POST -H \"Content-Type:application/json\" -H \"X-CSRFTOKEN:%s\" -d \"{'nodeid':%s,'parameter':11,'paramdata1':%s,'paramdata2':%s}\" http://%s%s -b cookie 2>/dev/null" % (CSRFToken, API_id, 8, 196, IP, GET_SINGLENODE_API), "LAN1_IPv6Addr": "curl -X POST -H \"Content-Type:application/json\" -H \"X-CSRFTOKEN:%s\" -d \"{'nodeid':%s,'parameter':11,'paramdata1':%s,'paramdata2':%s}\" http://%s%s -b cookie 2>/dev/null" % (CSRFToken, API_id, 1, 197, IP, GET_SINGLENODE_API), "LAN8_IPv6Addr": "curl -X POST -H \"Content-Type:application/json\" -H \"X-CSRFTOKEN:%s\" -d \"{'nodeid':%s,'parameter':11,'paramdata1':%s,'paramdata2':%s}\" http://%s%s -b cookie 2>/dev/null" % (CSRFToken, API_id, 8, 197, IP, GET_SINGLENODE_API), "LAN1_IPv6Gateway": "curl -X POST -H \"Content-Type:application/json\" -H \"X-CSRFTOKEN:%s\" -d \"{'nodeid':%s,'parameter':11,'paramdata1':%s,'paramdata2':%s}\" http://%s%s -b cookie 2>/dev/null" % (CSRFToken, API_id, 1, 199, IP, GET_SINGLENODE_API), "LAN8_IPv6Gateway": "curl -X POST -H \"Content-Type:application/json\" -H \"X-CSRFTOKEN:%s\" -d \"{'nodeid':%s,'parameter':11,'paramdata1':%s,'paramdata2':%s}\" http://%s%s -b cookie 2>/dev/null" % (CSRFToken, API_id, 8, 199, IP, GET_SINGLENODE_API), "LAN1_NCSIPortNum": "curl -X POST -H \"Content-Type:application/json\" -H \"X-CSRFTOKEN:%s\" -d \"{'nodeid':%s,'parameter':11,'paramdata1':%s,'paramdata2':%s}\" http://%s%s -b cookie 2>/dev/null" % (CSRFToken, API_id, 1, 204, IP, GET_SINGLENODE_API), "LAN8_NCSIPortNum": "curl -X POST -H \"Content-Type:application/json\" -H \"X-CSRFTOKEN:%s\" -d \"{'nodeid':%s,'parameter':11,'paramdata1':%s,'paramdata2':%s}\" http://%s%s -b cookie 2>/dev/null" % (CSRFToken, API_id, 8, 204, IP, GET_SINGLENODE_API), } if baseline: for name,cmd in check_list.iteritems(): status, output = CMM.retry_run_cmd(cmd) if status == 0: try: temp = eval(output) except Exception as e: message = "[Node{0}] {1}".format(API_id, e) CMM.show_message(message, timestamp=False, color="red") CMM.save_data(main_log, message, timestamp=False) collect_baseline = False else: if temp.get("error"): collect_baseline = False else: temp_dict[name] = temp else: collect_baseline = False time.sleep(1) API_BASELINE["Node_{0}".format(API_id)] = temp_dict else: for name, cmd in check_list.iteritems(): status, output = CMM.retry_run_cmd(cmd) if status == 0: try: temp = eval(output) except Exception as e: message = "[Node{0}] {1}".format(API_id, e) CMM.show_message(message, timestamp=False, color="red") CMM.save_data(main_log, message, timestamp=False) else: if not temp.get("error"): temp_dict[name] = temp time.sleep(1) API_TEMP["Node_{0}".format(API_id)] = temp_dict time.sleep(3) else: return False status, output = CMM.curl_login_logout(IP, flag="logout", username=USERNAME, password=PASSWORD, csrf_token=CSRFToken) if status == 0: message = "Logout Web" CMM.save_step_result(main_log,message,flag="PASS") show_step_result(message,flag="PASS") else: message = "[curl] Logout Web FAIL !\n{0}".format(output) CMM.save_data(main_log, message, timestamp=False) show_step_result("Logout Web",flag="FAIL") if baseline: return collect_baseline return True
def d_flash_fw_stress(self): global LOGIN_FAIL, CSRFToken, ENTER_FLASH_MODE, UPLOAD_IMAGE, VERIFY_IMAGE global CASE_PASS if DOWNLOAD_FW_FAIL: return False loop_num = 0 start_time = datetime.datetime.now() baseline_vers = "" while CMM.calc_time_interval(start_time, datetime.datetime.now()) < STRESS_TIME: LOGIN_FAIL = False CSRFToken = "" ENTER_FLASH_MODE = False UPLOAD_IMAGE = False VERIFY_IMAGE = False loop_num += 1 vers = checkFwVersion() temp_text = "\n[Loop{0}] Currert FW version: {1}\n".format( loop_num, vers) CMM.show_message(temp_text, timestamp=False, color="blue") CMM.save_data(main_log, temp_text, timestamp=False) if loop_num == 1 and vers != "Unknown": baseline_vers = vers else: if baseline_vers: if baseline_vers != vers: CASE_PASS = False temp_text = "Expect CMM version: {0}".format( baseline_vers) MAIN_LOG_list.append(temp_text) CMM.save_data(main_log, temp_text, timestamp=False) CMM.show_message(temp_text, timestamp=False, color="red") temp_text = "Current CMM version: {0}".format(vers) MAIN_LOG_list.append(temp_text) CMM.save_data(main_log, temp_text, timestamp=False) CMM.show_message(temp_text, timestamp=False, color="red") return False else: CASE_PASS = False temp_text = "Check FW version: {0}".format(vers) MAIN_LOG_list.append(temp_text) CMM.save_data(main_log, temp_text, timestamp=False) CMM.show_message(temp_text, timestamp=False, color="red") return False # Login web message = "Login Web" CMM.show_message(format_item(message), color="green", timestamp=False) status, output = CMM.curl_login_logout(IP, flag="login", username=USERNAME, password=PASSWORD, retry_count=1) if status == 0: CSRFToken = output.strip() show_step_result(message, "PASS") CMM.save_step_result(main_log, message, "PASS") else: LOGIN_FAIL = True CASE_PASS = False show_step_result(message, "FAIL") CMM.save_step_result(main_log, message, "FAIL") # Enter flash mode if LOGIN_FAIL: return False message = "Enter flash mode" CMM.show_message(format_item(message), color="green", timestamp=False) status = enterFlashMode() if status: ENTER_FLASH_MODE = True show_step_result(message, flag="PASS") CMM.save_step_result(main_log, message, flag="PASS") else: CASE_PASS = False show_step_result(message, flag="FAIL") CMM.save_step_result(main_log, message, flag="FAIL") # Upload firmware image if not ENTER_FLASH_MODE: return False message = "Upload firmware" CMM.show_message(format_item(message), color="green", timestamp=False) status = uploadFirmware() if status: UPLOAD_IMAGE = True show_step_result(message, flag="PASS") CMM.save_step_result(main_log, message, flag="PASS") else: CASE_PASS = False show_step_result(message, flag="FAIL") CMM.save_step_result(main_log, message, flag="FAIL") # Verify firmware image if not UPLOAD_IMAGE: return False message = "Verify firmware" CMM.show_message(format_item(message), color="green", timestamp=False) status = verifyFirmware() if status: VERIFY_IMAGE = True show_step_result(message, flag="PASS") CMM.save_step_result(main_log, message, flag="PASS") else: CASE_PASS = False show_step_result(message, flag="FAIL") CMM.save_step_result(main_log, message, flag="FAIL") # Flash firmware if not VERIFY_IMAGE: return False message = "Flash firmware" CMM.show_message(format_item(message), color="green", timestamp=False) status = flashFirmware() if status: complete_status = getFlashStatus() if complete_status: show_step_result(message, flag="PASS") CMM.save_step_result(main_log, message, flag="PASS") else: CASE_PASS = False show_step_result(message, flag="FAIL") CMM.save_step_result(main_log, message, flag="FAIL") else: CASE_PASS = False show_step_result(message, flag="FAIL") CMM.save_step_result(main_log, message, flag="FAIL") # 刷新步骤结束 检测是否刷新完成继续下一次刷新 if not CASE_PASS: temp_text = "[Loop{0}] Flash CMM firmware FAIL, exit...".format( loop_num) CMM.save_data(MAIN_LOG, temp_text) CMM.show_message(temp_text, timestamp=False, color="red") break else: """ 刷新固件后 如果不能正常登录网页(retry_count=3) 则停止测试 刷新后 第一次登录会失败 """ time.sleep(CMM_RESTORE_TIME) status, output = CMM.curl_login_logout(IP, flag="login", username=USERNAME, password=PASSWORD, retry_count=3) if status == 0 and output: csrftoken = output.strip() time.sleep(1) status, output = CMM.curl_login_logout( IP, flag="logout", username=USERNAME, password=PASSWORD, csrf_token=csrftoken) if status != 0: temp_text = "Logout Web FAIL after update firmware, exit..." CMM.save_data(MAIN_LOG, temp_text, timestamp=False) CMM.show_message(temp_text, timestamp=False, color="red") break else: temp_text = "Login Web FAIL after update firmware, exit..." CMM.save_data(MAIN_LOG, temp_text, timestamp=False) CMM.show_message(temp_text, timestamp=False, color="red") break else: temp_text = "- Stress Time: {0}s, loop number: {1}".format( STRESS_TIME, loop_num) MAIN_LOG_list.append(temp_text) CMM.save_data(main_log, temp_text, timestamp=False) CMM.show_message(temp_text, timestamp=False, color="blue")