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 SetFanDutyViaOEM(id, Duty): ID = id - 1 cmd = "{0} {1} 0x0{2} 0x02 {3}".format(IPMITOOL, SET_FAN_OEM, ID, Duty) status, output = CMM.retry_run_cmd(cmd) message = "{0}\n{1}\nreturncode: {2}\n{3}".format("FAN {0}".format(id), cmd, status, output) CMM.save_data(main_log, message, timestamp=False)
def getSwitchNumber(): is_fail = False restapi = "/api/cmminfo/switchescount" cmd = "curl -X GET -H \"X-CSRFTOKEN:%s\" http://%s%s -b cookie 2>/dev/null" % ( CSRFToken, IP, restapi) status, output = CMM.retry_run_cmd(cmd) message = "[API] Get switch number\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) CMM.show_message(message, timestamp=False, color="red") CMM.save_data(main_log, message, timestamp=False) MAIN_LOG_list.append(message) else: switchtotal = json_data.get("switchtotal") swpresenttotal = json_data.get("swpresenttotal") if switchtotal != SWITCH_NUM: is_fail = True temp_text = "Switch total number: {0}".format(switchtotal) MAIN_LOG_list.append(temp_text) CMM.show_message(temp_text, timestamp=False, color="red") if swpresenttotal != len(Present_switch): is_fail = True temp_text = "Switch present number: {0}".format(swpresenttotal) MAIN_LOG_list.append(temp_text) CMM.show_message(temp_text, timestamp=False, color="red") else: is_fail = True return False if is_fail else True
def init(): if os.path.exists(LOG_DIR): shutil.rmtree(LOG_DIR) os.makedirs(LOG_DIR) cmm = CMM() cmm.save_data(MAIN_LOG, cmm.banner("Main log"), flag="w", timestamp=False) cmm.save_data(MAIN_LOG, "Test start...")
def c_check_node_present_via_ipmi(self): global Present_Node global NODE_INFO_DICT global CASE_PASS is_FAIL = False temp_text = "- Check Node present 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) message = temp_text.strip(" -") for node_id in range(NODE_NUM): NODE_INFO_DICT["Node{0}".format(node_id + 1)] = {} temp = check_node_Present(node_id) if temp == "01": Present_Node.append(node_id+1) CMM.show_message("Node{0} is present".format(node_id+1),timestamp=False) NODE_INFO_DICT["Node{0}".format(node_id + 1)]["Present"] = "Y" elif temp == "00": CMM.show_message("Node{0} is not present".format(node_id+1),timestamp=False) NODE_INFO_DICT["Node{0}".format(node_id + 1)]["Present"] = "N" else: is_FAIL = True NODE_INFO_DICT["Node{0}".format(node_id + 1)]["Present"] = "Unknown" if is_FAIL: CASE_PASS = False show_step_result(message,"FAIL") CMM.save_step_result(main_log,message,"FAIL") else: show_step_result(message,"PASS") CMM.save_step_result(main_log,message,"PASS")
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 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 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 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 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 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 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 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 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 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 getNetworkInfoViaOEM(): is_fail = False networkInfo = {} cmd = "{0} lan print {1}".format(IPMITOOL,LAN) status,output = CMM.retry_run_cmd(cmd) message = "[OEM] Get Network Info\n{0}\nreturncode: {1}\n{2}".format(cmd, status, output) CMM.save_data(main_log, message, timestamp=False) if status == 0: for line in output.splitlines(): if re.search(r'MAC Address',line,re.IGNORECASE): mac_address = line.split(":",1)[-1].strip() networkInfo["mac_address"] = mac_address.upper() elif re.search(r'Source',line,re.IGNORECASE): if re.search(r'dhcp',line,re.IGNORECASE): ipv4_dhcp_enable = 1 else: ipv4_dhcp_enable = 0 networkInfo["ipv4_dhcp_enable"] = ipv4_dhcp_enable elif re.search(r'IP Address',line,re.IGNORECASE): ipv4_address = line.split(":",1)[-1].strip() networkInfo["ipv4_address"] = ipv4_address elif re.search(r'Subnet Mask',line,re.IGNORECASE): ipv4_subnet = line.split(":",1)[-1].strip() networkInfo["ipv4_subnet"] = ipv4_subnet elif re.search(r'Default Gateway IP',line,re.IGNORECASE): ipv4_gateway = line.split(":",1)[-1].strip() networkInfo["ipv4_gateway"] = ipv4_gateway else: is_fail = True return {} if is_fail else networkInfo
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 z_finish(self): CMM.save_data( MAIN_LOG, "{0} {1}".format("PASS:"******"FAIL:", module_name)) infos = map(lambda x: "INFO: {0}".format(x), MAIN_LOG_list) for info in infos: CMM.save_data(MAIN_LOG, info, timestamp=False)
def GetSwitchInfoViaAPI(CSRFToken, id): switch_info = None 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, id, IP, GET_SWITCH_API) 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 = "[API] Get Switch{0} info FAIL !".format(id) MAIN_LOG_list.append(temp) CMM.show_message(temp, timestamp=False, color="red") else: try: switch_info = json.loads(output.strip()) if isinstance(switch_info, list): switch_info = switch_info[0] except Exception as e: temp = "[Switch{0}] {1}".format(id, e) CMM.show_message(temp, timestamp=False, color="red") else: if switch_info.get("error"): temp = "[API] Get Switch{0} info FAIL !".format(id) MAIN_LOG_list.append(temp) CMM.show_message(temp, timestamp=False, color="red") switch_info = None else: switch_info = unicode_convert(switch_info) return {} if not switch_info else switch_info
def getFanInfoViaSNMP(version,timeout=10): global ITEM_NUM if version == "3": comstr = "-u sugon -a SHA -A 11111111 -l authPriv -x DES -X 11111111" else: comstr = "-c rwcommstr" # fanCount fanCountCmd = "snmpwalk -v {0} {1} -t {2} {3} .1.3.6.1.4.1.27500.1.1.1.2.1.4.1".format(version, comstr, timeout, IP) # onlineCount onlineCountCmd = "snmpwalk -v {0} {1} -t {2} {3} .1.3.6.1.4.1.27500.1.1.1.2.1.4.2".format(version, comstr, timeout, IP) # fanIndex fanIndexCmd = "snmpwalk -v {0} {1} -t {2} {3} .1.3.6.1.4.1.27500.1.1.1.2.1.4.3.1.1".format(version, comstr, timeout, IP) # fanState fanStateCmd = "snmpwalk -v {0} {1} -t {2} {3} .1.3.6.1.4.1.27500.1.1.1.2.1.4.3.1.2".format(version, comstr, timeout, IP) # fanDuty fanDutyCmd = "snmpwalk -v {0} {1} -t {2} {3} .1.3.6.1.4.1.27500.1.1.1.2.1.4.3.1.3".format(version, comstr, timeout, IP) # fanSpeed1 fanSpeed1Cmd = "snmpwalk -v {0} {1} -t {2} {3} .1.3.6.1.4.1.27500.1.1.1.2.1.4.3.1.4".format(version, comstr, timeout, IP) # fanSpeed2 fanSpeed2Cmd = "snmpwalk -v {0} {1} -t {2} {3} .1.3.6.1.4.1.27500.1.1.1.2.1.4.3.1.5".format(version, comstr, timeout, IP) cmdDict = collections.OrderedDict() cmdDict["fanCount"] = fanCountCmd cmdDict["onlineCount"] = onlineCountCmd cmdDict["fanIndex"] = fanIndexCmd cmdDict["fanState"] = fanStateCmd cmdDict["fanDuty"] = fanDutyCmd cmdDict["fanSpeed1"] = fanSpeed1Cmd cmdDict["fanSpeed2"] = fanSpeed2Cmd ITEM_NUM = len(cmdDict.keys())-2 result_list = [] temp_list = [] for name,cmd in cmdDict.iteritems(): temp_data = [] status,output = CMM.retry_run_cmd(cmd) message = "\n{0}\nreturncode: {1}\n{2}".format(cmd,status,output) CMM.save_data(main_log,message,timestamp=False) if status == 0: for line in output.splitlines(): m = re.match(r'SNMP.*enterprises.*',line) if m: value = m.group().split(":")[-1].strip() if name == "fanCount" or name == "onlineCount": try: temp_data = int(value) except: temp_data = "Unknown" break else: temp_data.append(value) else: temp_text = "[SNMP] Get {0} info".format(name) MAIN_LOG_list.append("{0} FAIL !".format(temp_text)) show_step_result(temp_text, "FAIL") CMM.save_step_result(main_log, temp_text, "FAIL") temp_list.append(temp_data) result_list.extend(temp_list[:2]) for item in zip(temp_list[2],temp_list[3],temp_list[4],temp_list[5],temp_list[6]): result_list.append(list(item)) return result_list
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 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 checkCMMBlackBoxInfo(): """ Audit log: 对比API返回的日志数目和黑盒文件中的日志数目(AuditLog.txt) SEL: 对比IPMI命令返回值和黑盒文件中的日志数目(SEL_RAW.txt和SEL_TRANSLATE.txt) """ if os.path.exists(BLACK_BOX_FOLDER_PATH): shutil.rmtree(BLACK_BOX_FOLDER_PATH) os.mkdir(BLACK_BOX_FOLDER_PATH) cmd = "tar -xvf {0} -C {1}".format(BLACK_BOX_FILE_PATH, BLACK_BOX_FOLDER_PATH) status, output = CMM.run_cmd(cmd) message = "Uncompress tar file\n{0}\nreturncode: {1}\n{2}".format( cmd, status, output) CMM.save_data(main_log, message, timestamp=False) if status == 0: auditLogPath = os.path.join(BLACK_BOX_FOLDER_PATH, "var/bmcblackinfo/Log/AuditLog.txt") selRawPath = os.path.join(BLACK_BOX_FOLDER_PATH, "var/bmcblackinfo/Log/SEL_RAW.txt") selTranslatePath = os.path.join( BLACK_BOX_FOLDER_PATH, "var/bmcblackinfo/Log/SEL_TRANSLATE.txt") auditNumViaAPI = parseAuditAPI() auditNumViaBlackBox = parseAuditBlackBox(auditLogPath) selNumViaIPMI = parseSelIPMI() selNumViaRaw = parseSelRaw(selRawPath) selNumViaTranslate = parseSelTranslate(selTranslatePath) names = [ "Audit log number via API", "Audit log number via Black box(AuditLog.txt)", "SEL number via IPMI", "SEL number via Black box(SEL_RAW.txt)", "SEL number via Black box(SEL_TRANSLATE.txt)" ] nums = [ auditNumViaAPI, auditNumViaBlackBox, selNumViaIPMI, selNumViaRaw, selNumViaTranslate ] for index in range(len(names)): tempString = ": ".join([names[index], str(nums[index])]) CMM.save_data(main_log, tempString, timestamp=False) CMM.show_message(tempString, timestamp=False, color="blue") if auditNumViaAPI == auditNumViaBlackBox != "Unknown" and selNumViaIPMI == selNumViaRaw == selNumViaTranslate != "Unknown": pass else: text = "The number of log does not match !" MAIN_LOG_list.append(text) CMM.show_message(text, timestamp=False, color="red") return False else: texts = ["[Uncompress 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 init(): if os.path.exists(LOG_DIR): shutil.rmtree(LOG_DIR) os.makedirs(LOG_DIR) for item in ["images", "report", "tmp"]: temp = os.path.join(CURRENT_PATH, item) if os.path.exists(temp): shutil.rmtree(temp) os.makedirs(temp) cmm = CMM() cmm.save_data(MAIN_LOG, cmm.banner("Main log"), flag="w", timestamp=False) cmm.save_data(MAIN_LOG, "Test start...")
def check_node_Present(node_id): OEM_id = node_id API_id = node_id + 1 OEM_cmd = "{0} raw 0x3a 0x7c {1} 0x03 0x00 0x00".format(IPMITOOL, hex(OEM_id)) status, output = CMM.retry_run_cmd(OEM_cmd) message = "OEM Node{0} Present\n{1}\nreturncode: {2}\n{3}".format(API_id, OEM_cmd, status, output) CMM.save_data(main_log, message, timestamp=False) OEM_Present = "Unknown" if status == 0: temp_list = output.split() OEM_Present = temp_list[1] return OEM_Present
def verifyFirmware(): restapi = "/api/maintenance/firmware/verification" cmd = "curl -X GET -H \"X-CSRFTOKEN:%s\" http://%s%s -b cookie 2>/dev/null" % ( CSRFToken, IP, restapi) status, output = CMM.retry_run_cmd(cmd) message = "Verify Firmware\n{0}\nreturncode: {1}\n{2}".format( cmd, status, output) CMM.save_data(main_log, message, timestamp=False) message = "Verify Firmware" if status != 0 or not output: MAIN_LOG_list.append("{0} FAIL !".format(message)) return False return True
def enterFlashMode(): restapi = '/api/maintenance/flash' cmd = "curl -X PUT -H \"X-CSRFTOKEN:%s\" http://%s%s -b cookie 2>/dev/null" % ( CSRFToken, IP, restapi) status, output = CMM.retry_run_cmd(cmd) message = "Enter Flash Mode\n{0}\nreturncode: {1}\n{2}".format( cmd, status, output) CMM.save_data(main_log, message, timestamp=False) message = "Enter flash mode" if status != 0: MAIN_LOG_list.append("{0} FAIL !".format(message)) return False return True
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 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 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