#-*- coding: utf-8 -*-
importtimefrom login_model importloginfrom outlog_model importOutLogdeftest_flash(server_name,testip,fwname,webarg):
logger= OutLog(filepath='report/{}.log'.format('result'))try:
driver=login(testip, webarg)
driver.accept_next_alert=Trueprint('fwname:',fwname)print("Now begin to test flash {}".format(fwname))
time.sleep(25)try:
driver.find_element_by_id("dijit_MenuBarItem_0_text")except:
driver.quit()finally:
time.sleep(5)print("Web is ready now")
driver.find_element_by_id("dijit_PopupMenuBarItem_2_text").click()
driver.find_element_by_css_selector("#dijit_MenuItem_9_text > table > tbody > tr > td").click()
driver.find_element_by_id("btnUpdateFwDlg_label").click()
time.sleep(5)#.find_element_by_css_selector("input.dijitOffScreen").click()
#driver.find_element_by_name("uploadedfile").clear()
driver.find_element_by_name("uploadedfile").send_keys(fwname)if 'imm' infwname:try:try:
driver.find_element_by_id("updateServerFirmwareWizardbtnNext_label").click()finally:
time.sleep(10)print("Now upload {} image".format(fwname))
driver.find_element_by_id("updateServerFirmwareWizardbtnNext_label").click()
time.sleep(200)try:
driver.find_element_by_id("updateServerFirmwareWizardbtnNext_label").click()finally:
time.sleep(15)print("Wait to flash {} image finished".format(fwname))
driver.find_element_by_id("updateServerFirmwareWizardbtnNext_label").click()
time.sleep(5)
driver.find_element_by_id("updateServerFirmwareWizardbtnNext_label").click()
time.sleep(180)#driver.find_element_by_xpath("(//input[@value=''])[5]").click()
driver.find_element_by_id("restartIMMId_label").click()
time.sleep(5)if driver.find_element_by_id("commonPopupOk_label"):
result= 1logger.Write_info('[Pass] : IMM {} {} {}'.format(server_name,testip,fwname))else:
result=0
logger.Write_info('[Fail] : IMM {} {} {}'.format(server_name, testip, fwname))print("Reatart imm wait about 5 min")
driver.find_element_by_id("commonPopupOk_label").click()
time.sleep(720)print("Finish test to flash IMM fw.")try:print("Close")
driver.close()except:print("Quit")
driver.quit()finally:returnresultexcept:
driver.close()
result= -1logger.Write_error('[Fail] code:{} IMM {} {} {}'.format(result,server_name, testip, fwname))returnresult
time.sleep(20)elif 'uefi' infwname:try:try:
driver.find_element_by_id("updateServerFirmwareWizardbtnNext_label").click()finally:
time.sleep(10)print("Now upload UEFI image")
driver.find_element_by_id("updateServerFirmwareWizardbtnNext_label").click()
time.sleep(20)try:
driver.find_element_by_id("updateServerFirmwareWizardbtnNext_label").click()finally:
time.sleep(15)
driver.find_element_by_id("updateServerFirmwareWizardbtnNext_label").click()print("Wait to flash UEFI image finished,need 1 min 37 sec")
time.sleep(5)
driver.find_element_by_id("updateServerFirmwareWizardbtnNext_label").click()
time.sleep(110)#driver.find_element_by_xpath("(//input[@value=''])[4]").click()
if driver.find_element_by_id("restartOSId_label"):print("Restart OS")
time.sleep(10)
driver.find_element_by_id("restartOSId_label").click()else:
time.sleep(10)
driver.find_element_by_id("restartOSId_label").click()
time.sleep(5)
driver.find_element_by_id("commonPopupOk_label").click()
time.sleep(5)
driver.find_element_by_id("commonPopupClose_label").click()
time.sleep(10)
driver.find_element_by_id("dijit_MenuBarItem_0_text").click()
time.sleep(5)
driver.find_element_by_id("btnserverActionsListHealthSumm_label").click()
time.sleep(5)
driver.find_element_by_id("serverActionsListHealthSumm63_text").click()
time.sleep(5)
driver.find_element_by_id("commonPopupOk_label").click()
time.sleep(5)print("Reatart os,wait about 5 min")
time.sleep(300)print("Finish test to flash UEFI fw")if driver.find_element_by_id("commonPopupClose_label"):
result= 1logger.Write_info('[Pass] : UEFI {} {} {}'.format(server_name,testip,fwname))else:
result=0
logger.Write_info('[Fail] : UEFI {} {} {}'.format(server_name, testip, fwname))
driver.find_element_by_id("commonPopupClose_label").click()try:print("Quit")
driver.quit()except:print("Close")
driver.close()finally:returnresultexcept:
driver.close()
result= -1logger.Write_error('[Fail] code:{} UEFI {} {} {}'.format(result,server_name, testip, fwname))return -1
else:try:if driver.find_element_by_id("updateServerFirmwareWizardbtnNext_label"):
driver.find_element_by_id("updateServerFirmwareWizardbtnNext_label").click()print("1.Now upload DSA image,need about 250s")else:
time.sleep(10)print("2.Now upload DSA image,need about 250s")
driver.find_element_by_id("updateServerFirmwareWizardbtnNext_label").click()
time.sleep(420)if driver.find_element_by_id("updateServerFirmwareWizardbtnNext_label"):print("1.wait to flash dsa")
driver.find_element_by_id("updateServerFirmwareWizardbtnNext_label").click()else:
time.sleep(30)print("2.wait to flash dsa")
driver.find_element_by_id("updateServerFirmwareWizardbtnNext_label").click()
driver.find_element_by_id("updateServerFirmwareWizardbtnNext_label").click()print("Wait to flash DSA image finished,need 120 sec")
time.sleep(5)
driver.find_element_by_id("updateServerFirmwareWizardbtnNext_label").click()
time.sleep(5)
driver.find_element_by_id("updateServerFirmwareWizardbtnNext_label").click()
time.sleep(5)
driver.find_element_by_id("updateServerFirmwareWizardbtnNext_label").click()
time.sleep(200)#updateServerFirmwareWizardbtnFinish_label
if driver.find_element_by_id("updateServerFirmwareWizardbtnFinish_label"):
result= 1logger.Write_info('[Pass] : DSA {} {} {}'.format(server_name,testip,fwname))
driver.find_element_by_id("updateServerFirmwareWizardbtnFinish_label").click()else:
result=0
logger.Write_info('[Fail] : DSA {} {} {}'.format(server_name, testip, fwname))print("Finish test to flash DSA fw")try:print("Quit")
driver.quit()except:print("Close")
driver.close()finally:returnresultexcept:
driver.close()
result= -1logger.Write_error('[Fail] code:-1 DSA {} {} {}'.format(server_name, testip, fwname))returnresultfinally:#return result
driver.close()if __name__ == "__main__":pass