Exemple #1
0
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 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()