def preprocess_hostOS_vm_running(parser): """ preprocess vm become running :called func: preprocess_hostOS_vm :param parser: is a dict, get from Test config file """ ssh = shell_server.get_ssh(parser["PrimaryOS_ip"], parser["PrimaryOS_usr"], parser["PrimaryOS_pwd"]) #獲得ssh if FTVM.is_running(parser["vm_name"], parser["PrimaryOS_ip"], ssh): print 59 if "pre_hostOS_VM_restart" in parser.keys( ) and parser["pre_hostOS_VM_restart"] == "yes": #根據參數若VM需重新啟動 print 54 prepocess_hostOS_vm_restart(parser) print 55 time.sleep(float(parser["pre_hostOS_VM_boot_time"])) elif FTVM.is_shutoff(parser["vm_name"], parser["PrimaryOS_ip"], ssh): print 56 prepocess_hostOS_vm_start(parser) print 57 time.sleep(float(parser["pre_hostOS_VM_boot_time"])) print 58 if not FTVM.is_running(parser["vm_name"], parser["PrimaryOS_ip"], ssh): ssh.close() raise TA_error.Preprocess_Error("PrimaryOS VM: %s can not start" % parser["vm_name"]) ssh.close()
def postprocess_slaveOS_vm_shutdown(parser): """ postprocess backupOS vm become shutdown :called func: postprocess_backupOS_vm :param parser: is a dict, get from Test config file """ ssh = shell_server.get_ssh(parser["SlaveOS_ip"], parser["SlaveOS_usr"], parser["SlaveOS_pwd"]) #獲得ssh if FTVM.is_running(parser["vm_name"], parser["SlaveOS_ip"], ssh): FTVM.destroy(parser["vm_name"], parser["SlaveOS_ip"], ssh) time.sleep(float(parser["pos_slaveOS_VM_shutdown_time"])) elif FTVM.is_paused(parser["vm_name"], parser["SlaveOS_ip"], ssh): FTVM.resume(parser["vm_name"], parser["SlaveOS_ip"], ssh) FTVM.destroy(parser["vm_name"], parser["SlaveOS_ip"], ssh) time.sleep(float(parser["pos_slaveOS_VM_shutdown_time"])) times = 0 while times < 30: print "check slave os vm status" if FTVM.is_running(parser["vm_name"], parser["SlaveOS_ip"], ssh): print "destroy slave os vm " FTVM.destroy(parser["vm_name"], parser["SlaveOS_ip"], ssh) break time.sleep(float(1)) times += 1 if not FTVM.is_shutoff(parser["vm_name"], parser["SlaveOS_ip"], ssh): ssh.close() raise TA_error.Postprocess_Error("SlaveOS %s can not shutdown" % parser["vm_name"]) ssh.close()
def vm_running_in_slaveOS(parser): """ vm is running in SlaveOS or not :param parser: config :return: True/raise exception """ ssh = shell_server.get_ssh(parser["SlaveOS_ip"], parser["SlaveOS_usr"], parser["SlaveOS_pwd"]) #獲得ssh t_end = time.time() if "ast_vm_running_wait_time" in parser.keys( ): #若參數ast_vm_running_wait_time存在於parser,則進入 t_end = time.time() + float( parser["ast_vm_running_wait_time"]) #計算出等待之時間,並存於t_end while time.time() < t_end: #超過t_end則跳出迴圈 #每sleep一秒就詢問一次狀態 time.sleep(1) if FTVM.is_running(parser["vm_name"], parser["SlaveOS_ip"], ssh): #狀態為running就跳出迴圈 break if FTVM.is_running(parser["vm_name"], parser["SlaveOS_ip"], ssh): #若回傳之狀態是running,則test oracle通過,否則raise exception ssh.close() return True ssh.close() raise TA_error.Assert_Error("VM (name : %s) is not running in SlaveOS" % parser["vm_name"])
def postprocess_hostOS_vm_running(parser): """ postrocess vm become running """ if FTVM.is_running(parser["vm_name"], parser["HostOS_ip"]): FTVM.restart(parser["vm_name"], parser["HostOS_ip"]) elif FTVM.is_shutoff(parser["vm_name"], parser["HostOS_ip"]): FTVM.start(parser["vm_name"], parser["HostOS_ip"]) time.sleep(float(parser["pos_hostOS_VM_boot_time"])) if not FTVM.is_running(parser["vm_name"], parser["HostOS_ip"]): raise TA_error.Postprocess_Error("HostOS %s can not start" % parser["vm_name"])
def postprocess_slaveOS_vm_running(parser): """ Slave OS vm become running """ ssh = shell_server.get_ssh(parser["SlaveOS_ip"], parser["SlaveOS_usr"], parser["SlaveOS_pwd"]) if FTVM.is_running(parser["vm_name"], parser["SlaveOS_ip"], ssh): print 59 elif FTVM.is_shutoff(parser["vm_name"], parser["SlaveOS_ip"], ssh): print 56 postprocess_slaveOS_vm_start(parser) print 57 time.sleep(float(parser["pos_slaveOS_VM_boot_time"])) if not FTVM.is_running(parser["vm_name"], parser["SlaveOS_ip"], ssh): ssh.close() raise TA_error.Postprocess_Error("SlaveOS VM: %s can not start" % parser["vm_name"]) ssh.close()
def postprocess_backupOS_vm_running(parser): """ postrocess vm become running :called func: postprocess_BackupOS_vm :param parser: is a dict, get from Test config file """ ssh = shell_server.get_ssh(parser["BackupOS_ip"], parser["BackupOS_usr"], parser["BackupOS_pwd"]) #獲得ssh if FTVM.is_running(parser["vm_name"], parser["BackupOS_ip"], ssh): FTVM.restart(parser["vm_name"], parser["BackupOS_ip"], ssh) elif FTVM.is_shutoff(parser["vm_name"], parser["BackupOS_ip"], ssh): FTVM.start(parser["vm_name"], parser["BackupOS_ip"], ssh) time.sleep(float(parser["pos_BackupOS_VM_boot_time"])) if not FTVM.is_running(parser["vm_name"], parser["BackupOS_ip"], ssh): ssh.close() raise TA_error.Postprocess_Error("BackupOS vm : %s can not start" % parser["vm_name"]) ssh.close()
def vm_running_in_backupOS(parser): """ vm is running in backupOS or not return True/False """ if "ast_vm_running_wait_time" in parser.keys(): time.sleep(int(parser["ast_vm_running_wait_time"])) if FTVM.is_running(parser["vm_name"], parser["backupOS_ip"]): return True raise TA_error.Assert_Error("VM (name : %s) is not running on backupOS" % parser["vm_name"])
def non_primary_rm_ftvm(parser): """ detect non primary remove ftvm :param parser: config :return: True/raise exception """ ssh = shell_server.get_ssh(parser["BackupOS_ip"], parser["BackupOS_usr"], parser["BackupOS_pwd"]) #獲得ssh if FTVM.is_shutoff(parser["vm_name"], parser["BackupOS_ip"], ssh): raise TA_error.Assert_Error("VM : %s shutoff" % parser["vm_name"]) if FTVM.is_running(parser["vm_name"], parser["BackupOS_ip"], ssh): out = FTVM.ftshutdown(parser["vm_name"], parser["BackupOS_ip"], ssh) expected = HAagent_terminal.Not_primary success = (out == expected) and FTVM.is_running( parser["vm_name"], parser["BackupOS_ip"], ssh) #shell message and FTVM running if success: return True raise TA_error.Assert_Error("remove non running ftvm : %s fail" % parser["vm_name"])
def postprocess_backupOS_vm_shutdown(parser): """ postprocess backupOS vm shutdown """ if FTVM.is_running(parser["vm_name"], parser["backupOS_ip"]): FTVM.shutdown(parser["vm_name"], parser["backupOS_ip"]) elif FTVM.is_paused(parser["vm_name"], parser["backupOS_ip"]): FTVM.resume(parser["vm_name"], parser["backupOS_ip"]) FTVM.shutdown(parser["vm_name"], parser["backupOS_ip"]) time.sleep(float(parser["pos_backupOS_VM_shutdown_time"])) if not FTVM.is_shutoff(parser["vm_name"], parser["backupOS_ip"]): raise TA_error.Postprocess_Error("backupOS %s can not shutdown" % parser["vm_name"])
def vm_running_in_hostOS(parser): """ vm is running in hostOS or not cfg var: ast_vm_running_wait_time return True/raise exception """ if "ast_vm_running_wait_time" in parser.keys(): time.sleep(int(parser["ast_vm_running_wait_time"])) if FTVM.is_running(parser["vm_name"], parser["HostOS_ip"]): return True raise TA_error.Assert_Error("VM (name : %s) is not running on hostOS" % parser["vm_name"])
def preprocess_hostOS_vm_shutdown(parser): """ preprocess hostOS vm become shutdown """ if FTVM.is_running(parser["vm_name"], parser["HostOS_ip"]): FTVM.shutdown(parser["vm_name"], parser["HostOS_ip"]) time.sleep(float(parser["pre_hostOS_VM_shutdown_time"])) elif FTVM.is_paused(parser["vm_name"], parser["HostOS_ip"]): FTVM.resume(parser["vm_name"], parser["HostOS_ip"]) FTVM.shutdown(parser["vm_name"], parser["HostOS_ip"]) time.sleep(float(parser["pre_hostOS_VM_shutdown_time"])) if not FTVM.is_shutoff(parser["vm_name"], parser["HostOS_ip"]): raise TA_error.Preprocess_Error("HostOS %s can not shutdown" % parser["vm_name"])
def detect_rm_non_running_ftvm(parser): ssh = shell_server.get_ssh(parser["PrimaryOS_ip"], parser["PrimaryOS_usr"], parser["PrimaryOS_pwd"]) #獲得ssh if FTVM.is_running(parser["vm_name"], parser["PrimaryOS_ip"], ssh): raise TA_error.Assert_Error("VM : %s running in PrimaryOS" % parser["vm_name"]) if FTVM.is_shutoff(parser["vm_name"], parser["PrimaryOS_ip"], ssh): out = HAagent.remove_ftvm(parser["vm_name"], parser, ssh) expected = HAagent_terminal.Vm_not_exist success = (out == expected) if success: return True raise TA_error.Assert_Error("rm non running vm fail")
def preprocess_slaveOS_vm_running(parser): """ preprocess vm become running :called func: preprocess_slaveOS_vm :param parser: is a dict, get from Test config file """ ssh = shell_server.get_ssh(parser["SlaveOS_ip"], parser["SlaveOS_usr"], parser["SlaveOS_pwd"]) #獲得ssh if FTVM.is_running(parser["vm_name"], parser["SlaveOS_ip"], ssh): pass print 59 elif FTVM.is_shutoff(parser["vm_name"], parser["SlaveOS_ip"], ssh): print 56 prepocess_slaveOS_vm_start(parser) print 57 time.sleep(float(parser["pre_slaveOS_VM_boot_time"])) print 58 if not FTVM.is_running(parser["vm_name"], parser["SlaveOS_ip"], ssh): ssh.close() raise TA_error.Preprocess_Error("SlaveOS VM: %s can not start" % parser["vm_name"]) ssh.close()
def rm_non_running_ftvm(parser): """ detect remove non running ftvm :param parser: config :return: True/raise exception """ ssh = shell_server.get_ssh(parser["PrimaryOS_ip"], parser["PrimaryOS_usr"], parser["PrimaryOS_pwd"]) #獲得ssh if FTVM.is_running(parser["vm_name"], parser["PrimaryOS_ip"], ssh): raise TA_error.Assert_Error("VM : %s already in running" % parser["vm_name"]) if FTVM.is_shutoff(parser["vm_name"], parser["PrimaryOS_ip"], ssh): out = FTVM.ftshutdown(parser["vm_name"], parser["PrimaryOS_ip"], ssh) expected = HAagent_terminal.Vm_not_exist success = (out == expected) if success: return True raise TA_error.Assert_Error("remove non running ftvm : %s fail" % parser["vm_name"])
def preprocess_slaveOS_vm_shutdown(parser): """ preprocess backupOS vm become shutdown :called func: preprocess_backupOS_vm :param parser: is a dict, get from Test config file """ ssh = shell_server.get_ssh(parser["SlaveOS_ip"], parser["SlaveOS_usr"], parser["SlaveOS_pwd"]) #獲得ssh if FTVM.is_running(parser["vm_name"], parser["SlaveOS_ip"], ssh): FTVM.destroy(parser["vm_name"], parser["SlaveOS_ip"], ssh) time.sleep(float(parser["pre_slaveOS_VM_shutdown_time"])) elif FTVM.is_paused(parser["vm_name"], parser["SlaveOS_ip"], ssh): FTVM.resume(parser["vm_name"], parser["SlaveOS_ip"], ssh) FTVM.destroy(parser["vm_name"], parser["SlaveOS_ip"], ssh) time.sleep(float(parser["pre_slaveOS_VM_shutdown_time"])) if not FTVM.is_shutoff(parser["vm_name"], parser["SlaveOS_ip"], ssh): ssh.close() raise TA_error.Preprocess_Error("SlaveOS %s can not shutdown" % parser["vm_name"]) ssh.close()
def non_primary_start_ftvm(parser): """ check non primary node(backup node) can start ftvm or not :param parser: config :return: True/raise exception """ ssh = shell_server.get_ssh(parser["BackupOS_ip"], parser["BackupOS_usr"], parser["BackupOS_pwd"]) #獲得ssh if FTVM.is_running(parser["vm_name"], parser["BackupOS_ip"], ssh): raise TA_error.Assert_Error("VM : %s already in running" % parser["vm_name"]) if FTVM.is_shutoff(parser["vm_name"], parser["BackupOS_ip"], ssh): out = FTVM.ftstart(parser["BackupOS_name"], parser["vm_name"], parser["BackupOS_ip"], ssh) expected = HAagent_terminal.Not_primary success = (out == expected) and FTVM.is_shutoff( parser["vm_name"], parser["BackupOS_ip"], ssh) # shell message and FTVM shutoff if success: return True raise TA_error.Assert_Error("non primary start ftvm : %s fail" % parser["vm_name"])
def vm_duplicate_start(parser): """ check vm can duplicate start or not :param parser: config :return: True/raise exception """ ssh = shell_server.get_ssh(parser["PrimaryOS_ip"], parser["PrimaryOS_usr"], parser["PrimaryOS_pwd"]) #獲得ssh if FTVM.is_shutoff(parser["vm_name"], parser["PrimaryOS_ip"], ssh): raise TA_error.Assert_Error("VM name : %s is shut off in PrimaryOS") if FTVM.is_running(parser["vm_name"], parser["PrimaryOS_ip"], ssh): out = FTVM.duplicate_ftstart(parser["PrimaryOS_name"], parser["vm_name"], parser["PrimaryOS_ip"], ssh) expected = HAagent_terminal.Startvm_addVM_failed % ( HAagent_terminal.Vm_has_exist) success = (out == expected) if success: return True raise TA_error.Assert_Error("vm : %s duplicate start fail" % parser["vm_name"])