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 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 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
Пример #5
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
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 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
Пример #8
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
Пример #9
0
 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)
Пример #10
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 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
Пример #13
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
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 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
Пример #16
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
Пример #18
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
Пример #19
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
Пример #20
0
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 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 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_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
Пример #24
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
Пример #25
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
Пример #26
0
 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)
Пример #27
0
 def c_check_sensor_table(self):
     global CASE_PASS
     message = "- Collect sensor table info -"
     CMM.show_message(format_item(message), timestamp=False, color="green")
     CMM.save_data(main_log, message, timestamp=False)
     MAIN_LOG_list.append(message)
     temp_text = message.strip(" -")
     is_FAIL = False
     OEM_data = getSensorTableViaOEM()
     if OEM_data:
         CMM.save_data(MAIN_LOG,
                       "OEM_Sensor_Table_INFO: {0}".format(OEM_data),
                       timestamp=False)
     else:
         is_FAIL = True
     if is_FAIL:
         CASE_PASS = False
         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 c_get_fan_via_ipmi(self):
     global Present_FAN
     global IPMI_FAN_INFO
     global IPMI_FAN_FAIL
     global CASE_PASS
     temp_text = "- Get FAN 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 fan_id in range(1,int(FAN_NUM)+1):
         fan = "FAN{0}".format(fan_id)
         is_fail = False
         OEM_id,OEM_FanStatus,OEM_Duty,OEM_FanSpeed1,OEM_FanSpeed2 = ["Unknown"]*5
         OEM_info = GetFanInfoViaOEM(fan_id)
         if OEM_info:
             temp_list = OEM_info.split()
             OEM_Present = parse_Present(temp_list)
             if OEM_Present[1] == 1:
                 Present_FAN.append(fan_id)
             OEM_id = parse_id(temp_list)
             OEM_FanStatus = parse_FanStatus(temp_list)
             OEM_Duty = parse_Duty(temp_list)
             OEM_FanSpeed1 = parse_FanSpeed(temp_list,1)
             OEM_FanSpeed2 = parse_FanSpeed(temp_list,2)
         else:
             is_fail = True
             IPMI_FAN_FAIL = True
         IPMI_FAN_INFO.append([OEM_id,OEM_FanStatus,OEM_Duty,OEM_FanSpeed1,OEM_FanSpeed2])
         temp_text = "[{0}] IPMI info".format(fan)
         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 FAN info list\n{0}".format(IPMI_FAN_INFO),timestamp=False)
Пример #29
0
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...")
Пример #30
0
 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")