Ejemplo n.º 1
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
Ejemplo n.º 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 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
Ejemplo n.º 4
0
 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 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 d_check_all_psu_pout_via_API(self):
     if LOGIN_FAIL:
         return False
     global CASE_PASS
     is_FAIL = False
     temp_text = "- Check all psu pout via API -"
     CMM.show_message(format_item(temp_text), color="green", timestamp=False)
     CMM.save_data(main_log, temp_text, timestamp=False)
     MAIN_LOG_list.append(temp_text)
     message = temp_text.strip(" -")
     json_data = getAllPsus()
     if json_data:
         if len(json_data) != PSU_NUM:
             is_FAIL = True
             MAIN_LOG_list.append("{0}".format(json_data))
             CMM.show_message("{0}".format(json_data),timestamp=False,color="red")
         else:
             for psu_id in range(1,PSU_NUM+1):
                 API_info = GetPSUInfoViaAPI(CSRFToken,psu_id)
                 expect_pout = API_info.get("Pout")
                 if not API_info:
                     is_FAIL = True
                 for item in json_data:
                     get_id = item.get("id")
                     if get_id == psu_id:
                         get_pout = item.get("Pout")
                         if get_id in Present_psu:
                             temp_pout = abs(int(get_pout)-int(expect_pout))
                             """ 两种方式的差值小于等于单一Node检测值的二分之一 即为PASS """
                             if temp_pout > int(expect_pout)/2:
                                 is_FAIL = True
                                 text = "[/cmminfo/psus] PSU{0} {1}".format(psu_id,expect_pout)
                                 MAIN_LOG_list.append(text)
                                 CMM.show_message(text,timestamp=False,color="red")
                                 CMM.save_data(main_log,text,timestamp=False)
                                 text = "[/cmmpower/allpsus] PSU{0} {1}".format(psu_id,get_pout)
                                 MAIN_LOG_list.append(text)
                                 CMM.show_message(text,timestamp=False,color="red")
                                 CMM.save_data(main_log,text,timestamp=False)
                         else:
                             if get_pout != "":
                                 is_FAIL = True
                                 text = "[PSU{0}] {1}".format(psu_id,get_pout)
                                 MAIN_LOG_list.append(text)
                                 CMM.show_message(text,timestamp=False,color="red")
                         break
                 else:
                     is_FAIL = True
     else:
         is_FAIL = True
     if is_FAIL:
         CASE_PASS = False
         show_step_result(message, flag="FAIL")
         CMM.save_step_result(main_log, message, flag="FAIL")
     else:
         show_step_result(message, flag="PASS")
         CMM.save_step_result(main_log, message, flag="PASS")
Ejemplo n.º 8
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)
Ejemplo n.º 9
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")
Ejemplo n.º 10
0
 def b_ping_test(self):
     global CASE_PASS
     global PING_FAIL
     message = "- Ping CMM IP -"
     CMM.show_message(format_item(message), color="green", timestamp=False)
     temp_text = message.strip(" -")
     status = Remote.ping_test(IP)
     if not status:
         CASE_PASS = False
         PING_FAIL = True
         show_step_result(temp_text, "FAIL")
         CMM.save_step_result(main_log, temp_text, "FAIL")
     else:
         show_step_result(temp_text, "PASS")
         CMM.save_step_result(main_log, temp_text, "PASS")
 def c_compare_fru_info(self):
     if LOGIN_FAIL:
         return False
     global CASE_PASS
     message = "- Compare FRU info -"
     CMM.show_message(format_item(message), timestamp=False, color="green")
     CMM.save_data(main_log, message, timestamp=False)
     temp_text = message.strip(" -")
     is_FAIL = False
     compareList = [
         "device_id", "chassis_type", "chassis_part_number",
         "chassis_serial", "chassis_extra", "board_manufacturer",
         "board_product", "board_serial", "board_part_number",
         "board_extra", "product_manufacturer", "product_name",
         "product_part_number", "product_version", "product_serial",
         "product_asset_tag", "product_extra"
     ]
     tempData = getCMMFruInfoViaAPI()
     if tempData:
         OEM_data = getCMMFruInfoViaOEM()
         API_data = tempData[0]
         API_data = parseAPIData(API_data)
         if API_data:
             for item in compareList:
                 apiValue = API_data.get(item)
                 oemValue = OEM_data.get(item)
                 if item == "device_id":
                     apiValue = str(apiValue)
                 if apiValue != oemValue:
                     is_FAIL = True
                     text = "[API] {0}: {1}".format(item, apiValue)
                     MAIN_LOG_list.append(text)
                     CMM.show_message(text, timestamp=False, color="red")
                     text = "[OEM] {0}: {1}".format(item, oemValue)
                     MAIN_LOG_list.append(text)
                     CMM.show_message(text, timestamp=False, color="red")
         else:
             is_FAIL = True
     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")
Ejemplo n.º 12
0
 def b_curl_login(self):
     global CASE_PASS
     global LOGIN_FAIL
     global CSRFToken
     message = "Login Web"
     CMM.show_message(format_item(message),color="green",timestamp=False)
     status, output = CMM.curl_login_logout(IP, flag="login", username=USERNAME, password=PASSWORD)
     if status == 0:
         show_step_result(message, flag="PASS")
         CMM.save_step_result(main_log,message,"PASS")
         CSRFToken = output.strip()
     else:
         LOGIN_FAIL = True
         CASE_PASS = False
         show_step_result(message,"FAIL")
         CMM.save_step_result(main_log,message,"FAIL")
         MAIN_LOG_list.append("{0} FAIL !".format(message))
 def d_save_configuration(self):
     global CASE_PASS
     global SAVE_CONFIG_FAIL
     if LOGIN_FAIL:
         return False
     message = "- Save BMC configuration -"
     CMM.show_message(format_item(message), color="green", timestamp=False)
     temp_text = message.strip(" -")
     status = saveConfiguration()
     if status:
         SAVE_CONFIG_FAIL = False
         show_step_result(temp_text, flag="PASS")
         CMM.save_step_result(main_log, temp_text, flag="PASS")
     else:
         CASE_PASS = False
         show_step_result(temp_text, flag="FAIL")
         CMM.save_step_result(main_log, temp_text, flag="FAIL")
 def d_get_switch_number(self):
     if LOGIN_FAIL:
         return False
     global CASE_PASS
     temp_text = "- Get Switch count -"
     CMM.show_message(format_item(temp_text),
                      timestamp=False,
                      color="green")
     CMM.save_data(main_log, temp_text, timestamp=False)
     MAIN_LOG_list.append(temp_text)
     message = temp_text.strip(" -")
     status = getSwitchNumber()
     if status:
         show_step_result(message, "PASS")
         CMM.save_step_result(main_log, message, "PASS")
     else:
         CASE_PASS = False
         show_step_result(message, "FAIL")
         CMM.save_step_result(main_log, message, "FAIL")
Ejemplo n.º 15
0
 def y_curl_logout(self):
     global CASE_PASS
     if LOGIN_FAIL:
         return False
     message = "- Logout Web -"
     CMM.show_message(format_item(message), color="green", timestamp=False)
     temp_text = message.strip(" -")
     status, output = CMM.curl_login_logout(IP,
                                            flag="logout",
                                            username=USERNAME,
                                            password=PASSWORD,
                                            csrf_token=CSRFToken)
     if status == 0:
         show_step_result(temp_text, "PASS")
         CMM.save_step_result(main_log, temp_text, "PASS")
     else:
         CASE_PASS = False
         show_step_result(temp_text, "FAIL")
         CMM.save_step_result(main_log, temp_text, "FAIL")
 def f_upload_fw(self):
     global CASE_PASS
     global UPLOAD_IMAGE
     if LOGIN_FAIL:
         return False
     elif not ENTER_FLASH_MODE:
         return False
     message = "- Upload firmware -"
     CMM.show_message(format_item(message), color="green", timestamp=False)
     temp_text = message.strip(" -")
     status = uploadFirmware()
     if status:
         UPLOAD_IMAGE = True
         show_step_result(temp_text, flag="PASS")
         CMM.save_step_result(main_log, temp_text, flag="PASS")
     else:
         CASE_PASS = False
         show_step_result(temp_text, flag="FAIL")
         CMM.save_step_result(main_log, temp_text, flag="FAIL")
 def g_verify_fw(self):
     global CASE_PASS
     global VERIFY_IMAGE
     if LOGIN_FAIL:
         return False
     elif not UPLOAD_IMAGE:
         return False
     message = "- Verify firmware -"
     CMM.show_message(format_item(message), color="green", timestamp=False)
     temp_text = message.strip(" -")
     status = verifyFirmware()
     if status:
         VERIFY_IMAGE = True
         show_step_result(temp_text, flag="PASS")
         CMM.save_step_result(main_log, temp_text, flag="PASS")
     else:
         CASE_PASS = False
         show_step_result(temp_text, flag="FAIL")
         CMM.save_step_result(main_log, temp_text, flag="FAIL")
Ejemplo n.º 18
0
 def c_check_all_module_status(self):
     if LOGIN_FAIL:
         return False
     global CASE_PASS
     temp_text = "- Check all module status via API -"
     CMM.show_message(format_item(temp_text),
                      color="green",
                      timestamp=False)
     CMM.save_data(main_log, temp_text, timestamp=False)
     MAIN_LOG_list.append(temp_text)
     message = temp_text.strip(" -")
     status = checkAllModuleStatus()
     if status:
         show_step_result(message, flag="PASS")
         CMM.save_step_result(main_log, message, flag="PASS")
     else:
         CASE_PASS = False
         show_step_result(message, flag="FAIL")
         CMM.save_step_result(main_log, message, flag="FAIL")
Ejemplo n.º 19
0
 def c_compare_network_info(self):
     if LOGIN_FAIL:
         return False
     global CASE_PASS
     message = "- Compare Network info -"
     CMM.show_message(format_item(message),timestamp=False,color="green")
     CMM.save_data(main_log, message, timestamp=False)
     temp_text = message.strip(" -")
     is_FAIL = False
     tempData = getNetworkInfoViaAPI()
     """ 判断API得到的返回值是 dict 或 list """
     API_data = {}
     if isinstance(tempData,list):
         for tempDict in tempData:
             if tempDict.get("channel_number") == LAN:
                 API_data = tempDict
                 break
     elif isinstance(tempData,dict):
         if tempData.get("channel_number") == LAN:
             API_data = tempData
     if not API_data:
         is_FAIL = True
     else:
         OEM_data = getNetworkInfoViaOEM()
         compareList = ["mac_address", "ipv4_dhcp_enable", "ipv4_address", "ipv4_subnet", "ipv4_gateway"]
         for item in compareList:
             apiValue = API_data.get(item)
             oemValue = OEM_data.get(item)
             if apiValue != oemValue:
                 text = "[API] {0}: {1}".format(item,apiValue)
                 MAIN_LOG_list.append(text)
                 CMM.show_message(text,timestamp=False,color="red")
                 text = "[OEM] {0}: {1}".format(item,oemValue)
                 MAIN_LOG_list.append(text)
                 CMM.show_message(text,timestamp=False,color="red")
                 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")
Ejemplo n.º 20
0
 def f_set_user_snmp(self):
     if IPMI_SWITCH_FAIL:
         return False
     global CASE_PASS
     global SET_USER_SNMP
     temp_text = "- Set user for SNMP V3 -"
     CMM.show_message(format_item(temp_text),timestamp=False,color="green")
     CMM.save_data(main_log,temp_text,timestamp=False)
     MAIN_LOG_list.append(temp_text)
     status = setUserSNMP()
     message = temp_text.strip(" -")
     if status:
         SET_USER_SNMP = True
         CMM.save_step_result(main_log,message,"PASS")
         show_step_result(message,"PASS")
         time.sleep(20)
     else:
         CASE_PASS = False
         CMM.save_step_result(main_log,message,"FAIL")
         show_step_result(message,"FAIL")
 def e_enter_flash_mode(self):
     global CASE_PASS
     global ENTER_FLASH_MODE
     if LOGIN_FAIL:
         return False
     # 考虑保存BMC配置进行刷新
     if SAVE_CONFIG_FAIL:
         return False
     message = "- Enter flash mode -"
     CMM.show_message(format_item(message), color="green", timestamp=False)
     temp_text = message.strip(" -")
     status = enterFlashMode()
     if status:
         ENTER_FLASH_MODE = True
         show_step_result(temp_text, flag="PASS")
         CMM.save_step_result(main_log, temp_text, flag="PASS")
     else:
         CASE_PASS = False
         show_step_result(temp_text, flag="FAIL")
         CMM.save_step_result(main_log, temp_text, flag="FAIL")
Ejemplo n.º 22
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
Ejemplo n.º 23
0
 def c_ipmi_test(self):
     global CASE_PASS
     global IPMI_FAIL
     message = "- Check IPMI command -"
     CMM.show_message(format_item(message), timestamp=False, color="green")
     if PING_FAIL:
         return False
     cmd = "{0} raw 0x06 0x01".format(IPMITOOL)
     temp_text = message.strip(" -")
     status, output = CMM.retry_run_cmd(cmd)
     info = "IPMI command\n{0}\nreturncode: {1}\n{2}".format(
         cmd, status, output)
     CMM.save_data(main_log, info, timestamp=False)
     if status == 0:
         show_step_result(temp_text, "PASS")
         CMM.save_step_result(main_log, temp_text, "PASS")
     else:
         IPMI_FAIL = True
         CASE_PASS = False
         CMM.show_message(output, timestamp=False)
         show_step_result(temp_text, "FAIL")
         CMM.save_step_result(main_log, temp_text, "FAIL")
 def b_download_fw(self):
     global CASE_PASS
     global DOWNLOAD_FW_FAIL
     global IMAGE_FILE
     message = "- Download CMM Firmware -"
     CMM.show_message(format_item(message), color="green", timestamp=False)
     temp_text = message.strip(" -")
     flag = "CMM"
     status = collectFirmware(flag)
     if not status:
         CASE_PASS = False
         MAIN_LOG_list.append("{0} FAIL !".format(temp_text))
         CMM.save_step_result(main_log, temp_text, "FAIL")
         show_step_result(temp_text, "FAIL")
     else:
         DOWNLOAD_FW_FAIL = False
         IMAGE_FILE = os.path.join(TMP_DIR, "{0}.ima".format(flag))
         CMM.save_data(main_log,
                       "Image file: {0}".format(IMAGE_FILE),
                       timestamp=False)
         CMM.save_step_result(main_log, temp_text, "PASS")
         show_step_result(temp_text, "PASS")
 def d_check_blackbox_info(self):
     if LOGIN_FAIL:
         return False
     if DUMP_FAIL:
         return False
     global CASE_PASS
     message = "- Check Black box 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
     status = checkCMMBlackBoxInfo()
     if not status:
         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")
Ejemplo n.º 26
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)
Ejemplo n.º 28
0
 def f_curl_login(self):
     global CASE_PASS
     global LOGIN_FAIL
     global CSRFToken
     if PING_FAIL:
         LOGIN_FAIL = True
         return False
     message = "- Login Web -"
     CMM.show_message(format_item(message), color="green", timestamp=False)
     temp_text = message.strip(" -")
     status, output = CMM.curl_login_logout(IP,
                                            flag="login",
                                            username=USERNAME,
                                            password=PASSWORD,
                                            retry_count=3)
     if status == 0:
         CSRFToken = output.strip()
         show_step_result(temp_text, "PASS")
         CMM.save_step_result(main_log, temp_text, "PASS")
     else:
         LOGIN_FAIL = True
         CASE_PASS = False
         show_step_result(temp_text, "FAIL")
         CMM.save_step_result(main_log, temp_text, "FAIL")
 def m_set_psu_power_state_via_API(self):
     if LOGIN_FAIL:
         return False
     global CASE_PASS
     temp_text = "- Set psu power state via API -"
     CMM.show_message(format_item(temp_text), color="green", timestamp=False)
     CMM.save_data(main_log, temp_text, timestamp=False)
     MAIN_LOG_list.append(temp_text)
     """
     1. 保证PSU在位数量大于1
     2. 保证所有的PSU均处于Power on状态
     """
     if len(Present_psu) > 1:
         for psu_id in range(1, int(PSU_NUM) + 1):
             if psu_id not in Present_psu:
                 continue
             text = "[PSU{0}] Init state to power on".format(psu_id)
             initStatus = init_psu_powerstate_via_API(psu_id)
             if initStatus:
                 show_step_result(text,flag="PASS")
                 CMM.save_step_result(main_log,text,flag="PASS")
             else:
                 show_step_result(text,flag="FAIL")
                 CMM.save_step_result(main_log,text,flag="FAIL")
                 CASE_PASS = False
                 return False
         for psu_id in range(1, int(PSU_NUM) + 1):
             if psu_id not in Present_psu:
                 continue
             status = set_psu_powerstate_via_API(psu_id)
             message = "[PSU{0}] {1}".format(psu_id,temp_text.strip(" -"))
             if status:
                 show_step_result(message,flag="PASS")
                 CMM.save_step_result(main_log,message,flag="PASS")
             else:
                 CASE_PASS = False
                 show_step_result(message,flag="FAIL")
                 CMM.save_step_result(main_log,message,flag="FAIL")
             time.sleep(1)
 def h_flash_firmware(self):
     global CASE_PASS
     if LOGIN_FAIL:
         return False
     if not VERIFY_IMAGE:
         return False
     message = "- Flash firmware -"
     CMM.show_message(format_item(message), color="green", timestamp=False)
     temp_text = message.strip(" -")
     status = flashFirmware()
     if status:
         complete_status = getFlashStatus()
         if complete_status:
             show_step_result(temp_text, flag="PASS")
             CMM.save_step_result(main_log, temp_text, flag="PASS")
         else:
             CASE_PASS = False
             show_step_result(temp_text, flag="FAIL")
             CMM.save_step_result(main_log, temp_text, flag="FAIL")
     else:
         CASE_PASS = False
         show_step_result(temp_text, flag="FAIL")
         CMM.save_step_result(main_log, temp_text, flag="FAIL")