def getFlashStatus(): restapi = "/api/maintenance/firmware/flash-progress" cmd = "curl -X GET -H \"X-CSRFTOKEN:%s\" http://%s%s -b cookie 2>/dev/null" % ( CSRFToken, IP, restapi) wait_time = 300 start_time = datetime.datetime.now() while CMM.calc_time_interval(start_time, datetime.datetime.now()) < wait_time: status, output = CMM.retry_run_cmd(cmd) message = "Get Flash Status\n{0}\nreturncode: {1}\n{2}".format( cmd, status, output) CMM.save_data(main_log, message, timestamp=False) try: json_data = json.loads(output) except Exception as e: temp_text = "[Exception] {0}".format(e) CMM.show_message(temp_text, timestamp=False, color="red") CMM.save_data(main_log, temp_text, timestamp=False) else: if re.search(r'Completed', json_data.get("progress"), re.IGNORECASE): break time.sleep(0.5) else: return False return True
def CMMColdReset(max_time=300): global RESET_OK cmd = "{0} {1}".format(IPMITOOL,RESET_OEM) status,output = CMM.retry_run_cmd(cmd) if status == 0: message = "CMM Cold Reset Command OK." show_step_result("CMM Cold Reset Command",flag="PASS") CMM.save_data(main_log,message) else: message = "CMM Cold Reset Command FAIL !\n{0}".format(output) show_step_result("CMM Cold Reset Command", flag="FAIL") CMM.save_data(main_log,message) RESET_OK = False return False time.sleep(10) start_time = datetime.datetime.now() while CMM.calc_time_interval(start_time, datetime.datetime.now()) < max_time: cmd = "{0} raw 0x06 0x01".format(IPMITOOL) status,output = CMM.retry_run_cmd(cmd) if status == 0: break time.sleep(1) else: if not Remote.ping_test(IP): temp_text = "Connected {0} FAIL !".format(IP) else: temp_text = "Connected {0} OK.".format(IP) message = "CMM status is still FAIL after {0} seconds, {1}".format(max_time,temp_text) CMM.show_message(message,timestamp=False,color="red") MAIN_LOG_list.append(message) CMM.save_data(main_log,message,timestamp=False) RESET_OK = False
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 c_cold_reset(self): global CASE_PASS temp_text = "CMM Cold Reset" CMM.show_message(format_item(temp_text),color="green",timestamp=False) FW_status = CollectFWInfo(baseline=True) SDR_status = CollectSDRInfo(baseline=True) CMM_status = CollectAPIInfo(baseline=True) CMM.save_data(main_log,"[API info]\n{0}".format(str(API_BASELINE)),timestamp=False) CMM.save_data(main_log,"[OEM info]\n{0}".format(str(OEM_BASELINE)),timestamp=False) if not FW_status or not SDR_status or not CMM_status: CASE_PASS = False message = "Collect baseline FAIL !" CMM.save_data(main_log, message,timestamp=False) MAIN_LOG_list.append(message) show_step_result("Collect baseline",flag="FAIL") return False else: show_step_result("Collect baseline",flag="PASS") start_time = datetime.datetime.now() while CMM.calc_time_interval(start_time, datetime.datetime.now()) < STRESS_TIME: cold_reset_time = CMMColdReset() if not RESET_OK: CASE_PASS = False break else: message = "Cold Reset Time: {0}s\n".format(cold_reset_time) RESET_TIME.append(int(cold_reset_time)) CMM.show_message(message,timestamp=False,color="blue") CMM.save_data(main_log,message,timestamp=False) CollectFWInfo() CollectSDRInfo() CollectAPIInfo() CMM.save_data(main_log,"[API info]\n{0}".format(str(API_TEMP)),timestamp=False) CMM.save_data(main_log,"[OEM info]\n{0}".format(str(OEM_TEMP)),timestamp=False) API_fail = False OEM_fail = False if API_BASELINE != API_TEMP: CASE_PASS = False message = "[API] The CMM info is changed !" CMM.show_message(message,timestamp=False,color="red") MAIN_LOG_list.append(message) CMM.save_data(main_log,message,timestamp=False) # temp_list = CMM.compare_dict(API_BASELINE,API_TEMP) # MAIN_LOG_list.extend(temp_list) baselineList,loopdataList = CMM.compare_dict(API_BASELINE,API_TEMP) MAIN_LOG_list.append("[Baseline]") MAIN_LOG_list.extend(baselineList) MAIN_LOG_list.append("[LoopData]") MAIN_LOG_list.extend(loopdataList) temp_baselines = [] temp_values = [] for key in API_BASELINE: temp_baseline = API_BASELINE.get(key) temp_value = API_TEMP.get(key) if temp_baseline != temp_value: temp_baselines.append({key:temp_baseline}) temp_values.append({key:temp_value}) baseline_text = "[Baseline]" for item in temp_baselines: key = item.keys()[0] value = item.get(key) info = "{0}: {1}".format(key,value) baseline_text = " ".join([baseline_text,info]) loop_text = "[LoopData]" for item in temp_values: key = item.keys()[0] value = item.get(key) info = "{0}: {1}".format(key,value) loop_text = " ".join([loop_text,info]) CMM.show_message(baseline_text,timestamp=False) # MAIN_LOG_list.append(baseline_text) CMM.show_message(loop_text,timestamp=False) # MAIN_LOG_list.append(loop_text) CMM.save_data(main_log,baseline_text,timestamp=False) CMM.save_data(main_log,loop_text,timestamp=False) API_fail = True else: message = "[API] Check CMM info OK." show_step_result("[API] Check CMM info",flag="PASS") CMM.save_data(main_log,message,timestamp=False) if OEM_BASELINE != OEM_TEMP: CASE_PASS = False message = "[OEM] The CMM info is changed !" CMM.show_message(message, timestamp=False, color="red") MAIN_LOG_list.append(message) CMM.save_data(main_log, message, timestamp=False) temp_baselines = [] temp_values = [] for key in OEM_BASELINE: temp_baseline = OEM_BASELINE.get(key) temp_value = OEM_TEMP.get(key) if temp_baseline != temp_value: temp_baselines.append({key: temp_baseline}) temp_values.append({key: temp_value}) baseline_text = "[Baseline]" for item in temp_baselines: key = item.keys()[0] value = item.get(key) info = "{0}: {1}".format(key, value) baseline_text = " ".join([baseline_text, info]) loop_text = "[LoopData]" for item in temp_values: key = item.keys()[0] value = item.get(key) info = "{0}: {1}".format(key, value) loop_text = " ".join([loop_text, info]) CMM.show_message(baseline_text, timestamp=False) MAIN_LOG_list.append(baseline_text) CMM.show_message(loop_text, timestamp=False) MAIN_LOG_list.append(loop_text) CMM.save_data(main_log, baseline_text, timestamp=False) CMM.save_data(main_log, loop_text, timestamp=False) OEM_fail = True else: message = "[OEM] Check CMM info OK." show_step_result("[OEM] Check CMM info",flag="PASS") CMM.save_data(main_log,message,timestamp=False) if API_fail or OEM_fail: break else: average_time = sum(RESET_TIME)/len(RESET_TIME) message = "[Stress] CMM Cold Reset" show_step_result(message,flag="PASS") CMM.save_step_result(main_log,message,flag="PASS") temp_text = "Stress Time: {0}s".format(STRESS_TIME) CMM.show_message(temp_text,timestamp=False,color="blue") CMM.save_data(main_log, temp_text, timestamp=False) temp_text = "Average Reset Time: {0}s".format(average_time) CMM.show_message(temp_text,timestamp=False,color="blue") CMM.save_data(main_log, temp_text, timestamp=False) MAIN_LOG_list.append("- Stress Time: {0}s".format(STRESS_TIME)) MAIN_LOG_list.append("- Average Reset Time: {0}s".format(average_time))
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")