def getCMMFruInfoViaAPI(): is_fail = False fru_info = {} cmd = "curl -X GET -H \"X-CSRFTOKEN:%s\" http://%s%s -b cookie 2>/dev/null" % ( CSRFToken, IP, GET_FRU_API) status, output = CMM.retry_run_cmd(cmd) message = "[API] Get FRU info\n{0}\nreturncode: {1}\n{2}".format( cmd, status, output) CMM.save_data(main_log, message, timestamp=False) if status == 0: try: json_data = json.loads(output) except Exception as e: is_fail = True message = "[Exception] {0}".format(e) MAIN_LOG_list.append(message) CMM.show_message(message, timestamp=False, color="red") CMM.save_data(main_log, message, timestamp=False) else: if isinstance(json_data, dict): if json_data.get("error"): is_fail = True else: fru_info = json_data CMM.save_data(MAIN_LOG, "FRU_INFO: {0}".format(fru_info), timestamp=False) else: is_fail = True return {} if is_fail else fru_info
def init_psu_powerstate_via_API(psu_id): # 执行命令后等待时间 waitTime = 5 is_fail = False restapi = "/api/cmmstate/psus" poweron_cmd = "curl -X POST -H \"X-CSRFTOKEN:%s\" -H \"Content-Type:application/json\" -d \"{'id':%s,'controlcommand':1}\" http://%s%s -b cookie 2>/dev/null" %(CSRFToken,psu_id,IP,restapi) initial_power = GetPSUInfoViaAPI(CSRFToken, psu_id).get("isPSUOn") # 初始化电源状态为ON if initial_power != "ON": status,output = CMM.retry_run_cmd(poweron_cmd) message = "Init psu{0} power state\n{1}\nreturncode: {2}\n{3}".format(psu_id,poweron_cmd,status,output) CMM.save_data(main_log, message, timestamp=False) try: json_data = json.loads(output) except Exception as e: is_fail = True message = "[Exception] {0}".format(e) CMM.show_message(message,timestamp=False,color="red") CMM.save_data(main_log,message,timestamp=False) else: if json_data.get("error"): is_fail = True MAIN_LOG_list.append(output) CMM.show_message(output,timestamp=False,color="red") time.sleep(waitTime) # 确认电源状态为ON 否则退出测试 initial_power = GetPSUInfoViaAPI(CSRFToken, psu_id).get("isPSUOn") if initial_power != "ON": is_fail = True return False if is_fail else True
def parseAuditAPI(): auditLogNum = "Unknown" auditAPI = "/api/logs/auditlog" cmd = "curl -X POST -H \"X-CSRFTOKEN:%s\" -H \"Content-Type: application/json\" -d \"{'audit_pagesize':20,'audit_pages':1,'log_starttime':-1,'log_endtime':-1,'log_selected':0}\" http://%s%s -b cookie 2>/dev/null" % ( CSRFToken, IP, auditAPI) status, output = CMM.retry_run_cmd(cmd) message = "[API] Collect Audit log info\n{0}\nreturncode: {1}\n{2}".format( cmd, status, output) CMM.save_data(main_log, message, timestamp=False) if status == 0: try: json_data = json.loads(output) except Exception as e: message = "[Collect audit log] {0}".format(e) CMM.save_data(main_log, message, timestamp=False) CMM.show_message(message, timestamp=False, color="red") MAIN_LOG_list.append(message) else: if isinstance(json_data, dict) and json_data.get("error"): CMM.show_message("{0}".format(output), timestamp=False, color="red") MAIN_LOG_list.append("{0}".format(output)) elif isinstance(json_data, list) and json_data: auditLogNum = json_data[0].get("total_count") return auditLogNum
def dumpCMMBlackBoxInfo(): dumpAPI = "/api/maintenance/dump_bmc_blackinfo" saveAPI = "/bsod/bmcblackinfo.tar" # Dump Black box info cmd = "curl -X PUT -H \"X-CSRFTOKEN:%s\" http://%s%s -b cookie" % ( CSRFToken, IP, dumpAPI) status, output = CMM.retry_run_cmd(cmd) message = "[API] Dump Black box info\n{0}\nreturncode: {1}\n{2}".format( cmd, status, output) CMM.save_data(main_log, message, timestamp=False) if status != 0: texts = ["[Dump Exception]", "{0}".format(output)] for text in texts: MAIN_LOG_list.append(text) CMM.show_message(text, timestamp=False, color="red") return False # Save Black box info if os.path.exists(BLACK_BOX_FILE_PATH): os.remove(BLACK_BOX_FILE_PATH) cmd = "curl -X GET -H \"X-CSRFTOKEN:%s\" http://%s%s -b cookie > %s" % ( CSRFToken, IP, saveAPI, BLACK_BOX_FILE_PATH) status, output = CMM.retry_run_cmd(cmd) message = "[API] Save Black box info\n{0}\nreturncode: {1}\n{2}".format( cmd, status, output) CMM.save_data(main_log, message, timestamp=False) if status != 0: texts = ["[Save Exception]", "{0}".format(output)] for text in texts: MAIN_LOG_list.append(text) CMM.show_message(text, timestamp=False, color="red") 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 getNodeCpuHealthViaAPI(node_id,index): # index和node_id 从0开始 API_id = node_id + 1 data = {} cmd = "curl -X POST -H \"X-CSRFTOKEN:%s\" -H \"Content-Type:application/json\" -d \"{'nodeid':%s,'parameter':12,'paramdata1':2,'paramdata2':%s,'paramdata3':0,'paramdata4':0}\" http://%s%s -b cookie 2>/dev/null" %(CSRFToken,API_id,index,IP,SINGLE_NODE_API) status,output = CMM.retry_run_cmd(cmd) message = "[Node{0}] Get cpu{1} health state\n{2}\nreturncode: {3}\n{4}".format(API_id,index,cmd,status,output) CMM.save_data(main_log,message,timestamp=False) if status == 0: try: json_data = json.loads(output) except Exception as e: temp_text = "[Exception] {0}".format(e) MAIN_LOG_list.append(temp_text) CMM.save_data(main_log,temp_text,timestamp=False) CMM.show_message(temp_text,timestamp=False,color="red") data = False else: if json_data.get("error"): temp_text = "[Node{0} CPU{1}] {2}".format(API_id,index,json_data) MAIN_LOG_list.append(temp_text) CMM.show_message(temp_text,timestamp=False,color="red") data = False else: data = json_data return data
def getNodeAssetPcieViaAPI(node_id): API_id = node_id + 1 data = [] restapi = "/api/noderepo/pcie" cmd = "curl -X POST -H \"X-CSRFTOKEN:%s\" -H \"Content-Type:application/json\" -d \"{'nodeid':%s}\" http://%s%s -b cookie 2>/dev/null" %(CSRFToken,API_id,IP,restapi) status,output = CMM.retry_run_cmd(cmd) message = "[Node{0}] Get pcie asset info\n{1}\nreturncode: {2}\n{3}".format(API_id,cmd,status,output) CMM.save_data(main_log,message,timestamp=False) if status == 0: try: json_data = json.loads(output) except Exception as e: temp_text = "[Exception] {0}".format(e) MAIN_LOG_list.append(temp_text) CMM.save_data(main_log,temp_text,timestamp=False) CMM.show_message(temp_text,timestamp=False,color="red") data = False else: if isinstance(json_data,dict) and json_data.get("error"): temp_text = "[Node{0}] {1}".format(API_id,json_data) MAIN_LOG_list.append(temp_text) CMM.show_message(temp_text,timestamp=False,color="red") data = False else: data = json_data return data
def saveConfiguration(): """ { "id": 1, "sdr": 0, "fru": 0, "sel": 0, "ipmi": 0, "network": 1, "ntp": 0, "snmp": 0, "ssh": 0, "kvm": 0, "authentication": 0, "syslog": 0, "web": 0, "redfish": 0 } """ is_FAIL = False restapi = "/api/maintenance/preserve" cmd = "curl -X PUT -H \"X-CSRFTOKEN:%s\" -H \"Content-Type:application/json\" -d \"{'id': 1, 'sdr': 0, 'fru': 0, 'sel': 0, 'ipmi': 0, 'network': 1, 'ntp': 0, 'snmp': 0, 'ssh': 0, 'kvm': 0, 'authentication': 0, 'syslog': 0, 'web': 0, 'redfish': 0}\" http://%s%s -b cookie 2>/dev/null" % ( CSRFToken, IP, restapi) status, output = CMM.retry_run_cmd(cmd) message = "Save BMC configuration\n{0}\nreturncode: {1}\n{2}".format( cmd, status, output) CMM.save_data(main_log, message, timestamp=False) message = "Save BMC configuration" if status == 0: try: json_data = json.loads(output) except Exception as e: is_FAIL = True MAIN_LOG_list.append(message) text = "[Exception] {0}".format(e) MAIN_LOG_list.append(text) CMM.save_data(main_log, text, timestamp=False) CMM.show_message(text, timestamp=False, color="red") else: if isinstance(json_data, dict) and json_data.has_key( "network") and json_data.has_key("redfish"): pass else: is_FAIL = True MAIN_LOG_list.append(message) MAIN_LOG_list.append("{0}".format(output)) else: is_FAIL = True return False if is_FAIL else True
def set_switch_ipv4_API(switch_id, ip, netmask, gateway): restapi = "/api/cmminfo/Setswitchipv4" cmd = "curl -X POST -H \"Content-Type:application/json\" -H \"X-CSRFTOKEN:%s\" -d \"{'id':%s,'cmdtype':3,'address':'%s','netmask':'%s','gateway':'%s'}\" http://%s%s -b cookie 2>/dev/null" % ( CSRFToken, switch_id, ip, netmask, gateway, IP, restapi) status, output = CMM.retry_run_cmd(cmd) message = "[API] Set switch{0} ipv4\n{1}\nreturncode: {2}\n{3}".format( switch_id, cmd, status, output) CMM.save_data(main_log, message, timestamp=False) set_value = {} if status == 0: try: temp = json.loads(output) except Exception as e: message = "[Switch{0}] {1}".format(switch_id, e) CMM.save_data(main_log, message, timestamp=False) CMM.show_message(message, timestamp=False, color="red") else: if temp.get("error"): CMM.show_message("{0}".format(temp), timestamp=False, color="red") else: set_value["IP"] = ip set_value["Netmask"] = netmask set_value["Gateway"] = gateway return set_value
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 flashFirmware(): is_fail = False restapi = "/api/maintenance/firmware/upgrade" cmd = "curl -X PUT -H \"X-CSRFTOKEN:%s\" -H \"Content-Type:application/json\" -d \"{'preserve_config':0,'flash_status':1}\" http://%s%s -b cookie 2>/dev/null" % ( CSRFToken, IP, restapi) status, output = CMM.retry_run_cmd(cmd) message = "Flash Firmware\n{0}\nreturncode: {1}\n{2}".format( cmd, status, output) CMM.save_data(main_log, message, timestamp=False) message = "Flash Firmware" if status == 0: 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 json_data.get("error"): is_fail = True MAIN_LOG_list.append("{0}".format(output)) else: is_fail = True if is_fail: MAIN_LOG_list.append("{0} FAIL !".format(message)) return False if is_fail else True
def c_StepB(self): name = "Step B" CMM.save_data(main_log, name) returnValue = run_caseB(name) message = "RunTime: {0}s".format(returnValue) CMM.show_message(message, timestamp=False, indent=CONSOLE_INDENT) CMM.save_data(main_log, message)
def uploadFirmware(): is_fail = False restapi = "/api/maintenance/firmware" if not IMAGE_FILE: temp_text = "Image name error !" MAIN_LOG_list.append(temp_text) CMM.show_message(temp_text, timestamp=False, color="red") CMM.save_data(main_log, temp_text, timestamp=False) return False cmd = "curl -F \"fwimage=@%s\" -H \"X-CSRFTOKEN:%s\" http://%s%s -b cookie 2>/dev/null" % ( IMAGE_FILE, CSRFToken, IP, restapi) status, output = CMM.retry_run_cmd(cmd) message = "Upload Firmware\n{0}\nreturncode: {1}\n{2}".format( cmd, status, output) CMM.save_data(main_log, message, timestamp=False) message = "Upload firmware" if status == 0: try: json_data = json.loads(output) except Exception as e: is_fail = True temp_text = "[Exception] {0}".format(e) CMM.show_message(temp_text, timestamp=False, color="red") CMM.save_data(temp_text, temp_text, timestamp=False) else: if json_data.get("cc") != 0: is_fail = True MAIN_LOG_list.append("{0}".format(output)) else: is_fail = True if is_fail: MAIN_LOG_list.append("{0} FAIL !".format(message)) return False if is_fail else True
def setUserSNMP(): is_fail = False restapi = "/api/settings/users/3" cmd1 = "curl -X PUT -H \"X-CSRFTOKEN:%s\" -H \"Content-Type: application/json\" -d \"{'id':3,'name':'sugon','access':1,'kvm':1,'vmedia':1,'snmp':1,'prev_snmp':1,'network_privilege':'administrator','fixed_user_count':1,'snmp_access':'read_write','OEMProprietary_level_Privilege':1,'privilege_limit_serial':'none','snmp_authentication_protocol':'sha','snmp_privacy_protocol':'des','email_id':'*****@*****.**','email_format':'ami_format','ssh_key':'Not Available','creation_time':1513303037,'priv_changed':0,'turnon_password_expiry':0,'expiry_date':'','belong_group':4,'group_name':'Unclassified','changepassword':1,'UserOperation':1,'password':'******','confirm_password':'******','password_size':'bytes_16'}\" http://%s%s -b cookie 2>/dev/null" %(CSRFToken,IP,restapi) restapi = "/api/settings/setpasswordexpiry" cmd2 = "curl -X PUT -H \"X-CSRFTOKEN:%s\" -H \"Content-Type: application/json\" -d \"{'userId':3,'userName':'******','expiry':0}\" http://%s%s -b cookie 2>/dev/null" %(CSRFToken,IP,restapi) restapi = "/api/settings/update_user_belong_group" cmd3 = "curl -X PUT -H \"X-CSRFTOKEN:%s\" -H \"Content-Type: application/json\" -d \"{'userId':3,'groupId':4,'type':1}\" http://%s%s -b cookie 2>/dev/null" %(CSRFToken,IP,restapi) for cmd in [cmd1,cmd2,cmd3]: status,output = CMM.retry_run_cmd(cmd) if status == 0: try: json_data = json.loads(output) except Exception as e: is_fail = True message = "[Exception] {0}".format(e) CMM.show_message(message,timestamp=False,color="red") CMM.save_data(main_log,message,timestamp=False) else: if json_data.get("error"): is_fail = True MAIN_LOG_list.append("{0}".format(output)) CMM.show_message("{0}".format(output),timestamp=False,color="red") else: is_fail = True if is_fail: return False return True
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 c_get_psu_via_ipmi(self): global Present_psu global IPMI_PSU_INFO global IPMI_PSU_FAIL global CASE_PASS temp_text = "- Get PSU info via IPMI -" CMM.show_message(format_item(temp_text),color="green",timestamp=False) CMM.save_data(main_log,temp_text,timestamp=False) MAIN_LOG_list.append(temp_text) for psu_id in range(1,int(PSU_NUM)+1): psu = "PSU{0}".format(psu_id) is_fail = False OEM_psuIndex, OEM_pwrState, OEM_statusWord, OEM_pout, OEM_pin, OEM_vout, OEM_vin, OEM_iout, OEM_iin, \ OEM_temperature1, OEM_temperature2, OEM_fanSpeed, OEM_fanDuty, OEM_vendor, OEM_psuModel, \ OEM_psuSN = ["Unknown"] * 16 OEM_info = GetPSUInfoViaOEM(psu_id) if OEM_info: temp_list = OEM_info.split() OEM_Present = parse_Present(temp_list) if OEM_Present[1] == 1: Present_psu.append(psu_id) OEM_isPSUOn = parse_isPSUOn(temp_list) if OEM_isPSUOn == "ON": OEM_pwrState = 2 elif OEM_isPSUOn == "OFF": OEM_pwrState = 1 else: OEM_pwrState = 0 OEM_statusWord = parse_statusWord(temp_list) OEM_psuIndex = parse_id(temp_list) OEM_pout = parse_Pout(temp_list) OEM_pin = parse_Pin(temp_list) OEM_vout = parse_Vout(temp_list) OEM_vin = parse_Vin(temp_list) OEM_iout = parse_Iout(temp_list) OEM_iin = parse_Iin(temp_list) temp = parse_Temp(temp_list) OEM_temperature1 = temp[0] if isinstance(temp,tuple) else temp OEM_temperature2 = temp[1] if isinstance(temp,tuple) else temp OEM_fanSpeed = parse_Fan1Speed(temp_list) OEM_fanDuty = parse_FanDuty(temp_list) OEM_vendor = parse_Vendor(temp_list) OEM_psuModel = parse_Model(temp_list) OEM_psuSN = parse_SN(temp_list) else: is_fail = True IPMI_PSU_FAIL = True IPMI_PSU_INFO.append([OEM_psuIndex, OEM_pwrState, OEM_statusWord, OEM_pout, OEM_pin, OEM_vout, OEM_vin, OEM_iout, OEM_iin,OEM_temperature1, OEM_temperature2, OEM_fanSpeed, OEM_fanDuty, OEM_vendor,OEM_psuModel, OEM_psuSN]) temp_text = "[{0}] IPMI info".format(psu) if is_fail: CASE_PASS = False CMM.save_step_result(main_log, temp_text, "FAIL") show_step_result(temp_text, "FAIL") MAIN_LOG_list.append("{0} FAIL !".format(temp_text)) else: CMM.save_step_result(main_log, temp_text, "PASS") show_step_result(temp_text, "PASS") CMM.save_data(main_log, "IPMI PSU info list\n{0}".format(IPMI_PSU_INFO), timestamp=False)
def d_check_all_psu_pout_via_API(self): if LOGIN_FAIL: return False global CASE_PASS is_FAIL = False temp_text = "- Check all psu pout via API -" CMM.show_message(format_item(temp_text), color="green", timestamp=False) CMM.save_data(main_log, temp_text, timestamp=False) MAIN_LOG_list.append(temp_text) message = temp_text.strip(" -") json_data = getAllPsus() if json_data: if len(json_data) != PSU_NUM: is_FAIL = True MAIN_LOG_list.append("{0}".format(json_data)) CMM.show_message("{0}".format(json_data),timestamp=False,color="red") else: for psu_id in range(1,PSU_NUM+1): API_info = GetPSUInfoViaAPI(CSRFToken,psu_id) expect_pout = API_info.get("Pout") if not API_info: is_FAIL = True for item in json_data: get_id = item.get("id") if get_id == psu_id: get_pout = item.get("Pout") if get_id in Present_psu: temp_pout = abs(int(get_pout)-int(expect_pout)) """ 两种方式的差值小于等于单一Node检测值的二分之一 即为PASS """ if temp_pout > int(expect_pout)/2: is_FAIL = True text = "[/cmminfo/psus] PSU{0} {1}".format(psu_id,expect_pout) MAIN_LOG_list.append(text) CMM.show_message(text,timestamp=False,color="red") CMM.save_data(main_log,text,timestamp=False) text = "[/cmmpower/allpsus] PSU{0} {1}".format(psu_id,get_pout) MAIN_LOG_list.append(text) CMM.show_message(text,timestamp=False,color="red") CMM.save_data(main_log,text,timestamp=False) else: if get_pout != "": is_FAIL = True text = "[PSU{0}] {1}".format(psu_id,get_pout) MAIN_LOG_list.append(text) CMM.show_message(text,timestamp=False,color="red") break else: is_FAIL = True else: is_FAIL = True if is_FAIL: CASE_PASS = False show_step_result(message, flag="FAIL") CMM.save_step_result(main_log, message, flag="FAIL") else: show_step_result(message, flag="PASS") CMM.save_step_result(main_log, message, flag="PASS")
def c_get_switch_via_ipmi(self): global Present_switch global IPMI_SWITCH_INFO global IPMI_SWITCH_FAIL global CASE_PASS temp_text = "- Get Switch info via IPMI -" CMM.show_message(format_item(temp_text),color="green",timestamp=False) CMM.save_data(main_log,temp_text,timestamp=False) MAIN_LOG_list.append(temp_text) for switch_id in range(1,int(SWITCH_NUM)+1): switch = "Switch{0}".format(switch_id) is_fail = False OEM_switchIndex, OEM_switchState, OEM_switchType, OEM_temperature, OEM_pwrConsump, \ OEM_ip, OEM_netmask, OEM_gateway, OEM_vendor = ["Unknown"] * 9 OEM_info = GetSwitchInfoViaOEM(switch_id) if OEM_info: temp_list = OEM_info.split() OEM_Present = parse_Present(temp_list) if OEM_Present[1] == 1: Present_switch.append(switch_id) OEM_Power = parse_Status(temp_list) if OEM_Power == "Power On": OEM_switchState = 2 elif OEM_Power == "Power Off": OEM_switchState = 1 elif OEM_Power == "Communication Lost": OEM_switchState = 7 elif OEM_Power == "Over Temp": OEM_switchState = 3 else: OEM_switchState = 0 OEM_switchIndex = parse_id(temp_list) temp = temp_list[19] OEM_switchType = int(temp,16) OEM_temperature = parse_Temperature(temp_list) OEM_pwrConsump = parse_Pwr_consump(temp_list) OEM_ip = parse_IP(temp_list) OEM_netmask = parse_Netmask(temp_list) OEM_gateway = parse_Gateway(temp_list) OEM_vendor = parse_Vendor(temp_list) else: is_fail = True IPMI_SWITCH_FAIL = True IPMI_SWITCH_INFO.append([OEM_switchIndex, OEM_switchState, OEM_switchType, OEM_temperature, OEM_pwrConsump, OEM_ip, OEM_netmask, OEM_gateway, OEM_vendor]) temp_text = "[{0}] IPMI info".format(switch) if is_fail: CASE_PASS = False CMM.save_step_result(main_log, temp_text, "FAIL") show_step_result(temp_text, "FAIL") MAIN_LOG_list.append("{0} FAIL !".format(temp_text)) else: CMM.save_step_result(main_log, temp_text, "PASS") show_step_result(temp_text, "PASS") CMM.save_data(main_log, "IPMI Switch info list\n{0}".format(IPMI_SWITCH_INFO), timestamp=False)
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 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 GetSwitchInfoViaOEM(id): cmd_id = id - 1 switch_info = None cmd = "{0} {1} 0x0{2} 2>/dev/null".format(IPMITOOL,GET_SWITCH_OEM,cmd_id) status,output = CMM.retry_run_cmd(cmd) message = "{0}\n{1}\nreturncode: {2}\n{3}".format("Switch {0}".format(id),cmd,status,output) CMM.save_data(main_log,message,timestamp=False) if status != 0: temp = "[OEM] Get Switch{0} info FAIL !".format(id) MAIN_LOG_list.append(temp) CMM.show_message(temp,timestamp=False,color="red") else: switch_info = output return "" if not switch_info else switch_info
def getNodePcieHealthViaOEM(node_id,index): API_id = node_id + 1 OEM_id = node_id cmd = "{0} {1} {2} 0x0c 0x09 {3}".format(IPMITOOL, SINGLE_NODE_OEM, hex(OEM_id), index) status, output = CMM.retry_run_cmd(cmd) message = "OEM Node{0} PCIE{4} health state\n{1}\nreturncode: {2}\n{3}".format(API_id, cmd, status, output, index) CMM.save_data(main_log, message, timestamp=False) if status == 0: temp_list = output.split() else: temp_list = [] text = "[Node{0} PCIE{1}] {2}".format(API_id,index,output) MAIN_LOG_list.append(text) CMM.show_message(text,timestamp=False,color="red") return temp_list
def b_ping_test(self): global CASE_PASS global PING_FAIL message = "- Ping CMM IP -" CMM.show_message(format_item(message), color="green", timestamp=False) temp_text = message.strip(" -") status = Remote.ping_test(IP) if not status: CASE_PASS = False PING_FAIL = True show_step_result(temp_text, "FAIL") CMM.save_step_result(main_log, temp_text, "FAIL") else: show_step_result(temp_text, "PASS") CMM.save_step_result(main_log, temp_text, "PASS")
def getNodeMemHealthViaOEM(node_id,channel_index,dimm_index): API_id = node_id + 1 OEM_id = node_id cmd = "{0} {1} {2} 0x0c 0x03 {2} {3} {4}".format(IPMITOOL,SINGLE_NODE_OEM,hex(OEM_id),hex(channel_index),hex(dimm_index)) status, output = CMM.retry_run_cmd(cmd) message = "OEM Node{0} channel{1} dimm{2} health state\n{3}\nreturncode: {4}\n{5}".format(API_id, channel_index, dimm_index, cmd, status, output) CMM.save_data(main_log, message, timestamp=False) if status == 0: temp_list = output.split() else: temp_list = [] text = "[Node{0} Channel{1} Dimm{2}] {3}".format(API_id,channel_index,dimm_index,output) MAIN_LOG_list.append(text) CMM.show_message(text,timestamp=False,color="red") return temp_list
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 d_save_configuration(self): global CASE_PASS global SAVE_CONFIG_FAIL if LOGIN_FAIL: return False message = "- Save BMC configuration -" CMM.show_message(format_item(message), color="green", timestamp=False) temp_text = message.strip(" -") status = saveConfiguration() if status: SAVE_CONFIG_FAIL = False show_step_result(temp_text, flag="PASS") CMM.save_step_result(main_log, temp_text, flag="PASS") else: CASE_PASS = False show_step_result(temp_text, flag="FAIL") CMM.save_step_result(main_log, temp_text, flag="FAIL")
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 d_get_switch_number(self): if LOGIN_FAIL: return False global CASE_PASS temp_text = "- Get Switch count -" CMM.show_message(format_item(temp_text), timestamp=False, color="green") CMM.save_data(main_log, temp_text, timestamp=False) MAIN_LOG_list.append(temp_text) message = temp_text.strip(" -") status = getSwitchNumber() if status: show_step_result(message, "PASS") CMM.save_step_result(main_log, message, "PASS") else: CASE_PASS = False show_step_result(message, "FAIL") CMM.save_step_result(main_log, message, "FAIL")
def g_verify_fw(self): global CASE_PASS global VERIFY_IMAGE if LOGIN_FAIL: return False elif not UPLOAD_IMAGE: return False message = "- Verify firmware -" CMM.show_message(format_item(message), color="green", timestamp=False) temp_text = message.strip(" -") status = verifyFirmware() if status: VERIFY_IMAGE = True show_step_result(temp_text, flag="PASS") CMM.save_step_result(main_log, temp_text, flag="PASS") else: CASE_PASS = False show_step_result(temp_text, flag="FAIL") CMM.save_step_result(main_log, temp_text, flag="FAIL")
def f_upload_fw(self): global CASE_PASS global UPLOAD_IMAGE if LOGIN_FAIL: return False elif not ENTER_FLASH_MODE: return False message = "- Upload firmware -" CMM.show_message(format_item(message), color="green", timestamp=False) temp_text = message.strip(" -") status = uploadFirmware() if status: UPLOAD_IMAGE = True show_step_result(temp_text, flag="PASS") CMM.save_step_result(main_log, temp_text, flag="PASS") else: CASE_PASS = False show_step_result(temp_text, flag="FAIL") CMM.save_step_result(main_log, temp_text, flag="FAIL")