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
示例#2
0
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 d_set_fan_duty_via_OEM(self):
     global CASE_PASS
     temp_text = "- Set FAN duty via OEM command -"
     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)
     # Switched manual mode
     status, output = CMM.retry_run_cmd(MANUAL_MODE_CMD)
     if status != 0:
         CASE_PASS = False
         fail_text = "[FAIL] Set cooling policy to manual mode."
         MAIN_LOG_list.append(fail_text)
         CMM.save_data(main_log, "{0}\n{1}".format(temp_text, output))
         show_step_result("Set cooling policy to manual mode", flag="FAIL")
         return False
     else:
         show_step_result("Set cooling policy to manual mode", flag="PASS")
     # Set and check FAN Duty
     Duty_fail = False
     Duty_list = [30, 40, 50, 60, 70, 80, 90, 100]
     temp_text = "Set and check FAN Duty: {0}".format(Duty_list)
     CMM.save_data(main_log, temp_text, timestamp=False)
     CMM.show_message(temp_text, timestamp=False, color="blue")
     for id in range(1, int(FAN_NUM) + 1):
         for Duty in Duty_list:
             SetFanDutyViaOEM(id, Duty)
             time.sleep(10)
             duty_pass, FanSpeed = CheckFanDuty(id, Duty)
             message = "FAN{0}_Duty{1}:{2}".format(id, Duty, FanSpeed)
             CMM.show_message(message, timestamp=False)
             CMM.save_data(MAIN_LOG, message, timestamp=False)
             if not duty_pass:
                 Duty_fail = True
     if Duty_fail:
         CASE_PASS = False
         show_step_result("Set and check FAN Duty", flag="FAIL")
         CMM.save_data(main_log,
                       "[FAIL] Set and check FAN Duty",
                       timestamp=False)
         MAIN_LOG_list.append("[FAIL] Set and check FAN Duty")
     else:
         show_step_result("Set and check FAN Duty", flag="PASS")
         CMM.save_data(main_log,
                       "[PASS] Set and check FAN Duty",
                       timestamp=False)
     # Restored auto mode
     status, output = CMM.retry_run_cmd(AUTO_MODE_CMD)
     if status != 0:
         CASE_PASS = False
         fail_text = "[FAIL] Set cooling policy to auto mode."
         MAIN_LOG_list.append(fail_text)
         CMM.save_data(main_log, "{0}\n{1}".format(temp_text, output))
         show_step_result("Set cooling policy to auto mode", flag="FAIL")
         return False
     else:
         show_step_result("Set cooling policy to auto mode", flag="PASS")
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 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 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 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 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
示例#9
0
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 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 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 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 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 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
示例#15
0
def CollectSDRInfo(baseline=False):
    global OEM_BASELINE
    global OEM_TEMP
    is_fail = False
    message = "Collect sdr info"
    sdr_infos = []
    cmd = "{0} sdr elist 2>/dev/null".format(IPMITOOL)
    status,output = CMM.retry_run_cmd(cmd)
    if status == 0:
        show_step_result(message,flag="PASS")
        CMM.save_step_result(main_log,message,flag="PASS")
    else:
        show_step_result(message,flag="FAIL")
        CMM.save_step_result(main_log,message,flag="FAIL")
        is_fail = True
    for line in output.splitlines():
        sdr_info = line.strip().split()[0].strip()
        sdr_infos.append(sdr_info)
    sorted(sdr_infos)
    if baseline:
        OEM_BASELINE["sdr"] = sdr_infos
    else:
        OEM_TEMP["sdr"] = sdr_infos
    if is_fail:
        return False
    return True
示例#16
0
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
示例#17
0
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
示例#18
0
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 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 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
示例#21
0
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 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 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
示例#24
0
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
示例#25
0
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
示例#26
0
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 parseSelIPMI():
    num = "Unknown"
    cmd = "{0} sel elist".format(IPMITOOL)
    status, output = CMM.retry_run_cmd(cmd)
    message = "[IPMI] Collect SEL info\n{0}\nreturncode: {1}\n{2}".format(
        cmd, status, output)
    CMM.save_data(main_log, message, timestamp=False)
    if status == 0:
        tempList = output.splitlines()
        if not tempList[-1]:
            num = tempList[-2].split("|")[0].strip()
            num = int(num, 16)
        else:
            num = tempList[-1].split("|")[0].strip()
            num = int(num, 16)
    return num
示例#28
0
def check_node_LAN(node_id):
    OEM_id = node_id
    API_id = node_id + 1
    temp_cmd = "{0} raw 0x3a 0x7c {1} 0x0b".format(IPMITOOL, hex(OEM_id))
    return_list = []
    for item, value in LAN_check_dict.iteritems():
        OEM_cmd = "{0} {1} {2}".format(temp_cmd, hex(1), hex(int(value)))
        status, output = CMM.retry_run_cmd(OEM_cmd)
        message = "OEM Node{0} LAN{1} {2}\n{3}\nreturncode: {4}\n{5}".format(
            API_id, 1, item, OEM_cmd, status, output)
        CMM.save_data(main_log, message, timestamp=False)
        temp = "Unknown"
        if status == 0:
            temp_list = output.split()
            temp = " ".join(temp_list[1:])
        return_list.append(temp)
    return return_list
示例#29
0
def CollectFWInfo(baseline=False):
    global OEM_BASELINE
    global OEM_TEMP
    is_fail = False
    message = "Collect FW info"
    cmd = "{0} raw 0x06 0x01 2>/dev/null".format(IPMITOOL)
    status, output = CMM.retry_run_cmd(cmd)
    if status == 0:
        show_step_result(message,flag="PASS")
        CMM.save_step_result(main_log,message,flag="PASS")
    else:
        show_step_result(message,flag="FAIL")
        CMM.save_step_result(main_log,message,flag="FAIL")
        is_fail = True
    if baseline:
        OEM_BASELINE["FW"] = output.strip()
    else:
        OEM_TEMP["FW"] = output.strip()
    if is_fail:
        return False
    return True
示例#30
0
def getSensorTableViaOEM():
    is_fail = False
    sensorTable = []
    cmd = "{0} sensor list".format(IPMITOOL)
    status, output = CMM.retry_run_cmd(cmd)
    message = "[OEM] Get Sensor Table 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():
            line = line.strip()
            if not line:
                continue
            else:
                # tempList = line.split("|")
                # lineList = map(lambda x : x.strip(), tempList)
                # sensorTable.append(lineList)
                sensorTable.append(line)
    else:
        is_fail = True
    return [] if is_fail else sensorTable