Exemple #1
0
def libvirt_stop_start_ftvm(parser):
    """
	detect when libvirt daemon shutdown , can HAAgent start ftvm
	:param parser: config
	:return: True/raise exception
	"""
    ssh = shell_server.get_ssh(parser["PrimaryOS_ip"], parser["PrimaryOS_usr"],
                               parser["PrimaryOS_pwd"])  #獲得ssh

    cmd = cmd_HAagent.start_ftvm_cmd(parser["PrimaryOS_name"],
                                     parser["vm_name"])
    s_stdin, s_stdout, s_stderr = ssh.exec_command("sudo " + cmd)
    out = s_stdout.read()
    expected = HAagent_terminal.Startvm_create_vm_failed % (
        HAagent_terminal.Libvirt_connection_failed %
        HAagent_terminal.Libvirt_self_connection) + "\n"

    success = (out == expected)

    print out
    print expected

    FTsystem.start(ssh)

    #print success
    if success:
        return True
    raise TA_error.Assert_Error("libvirt stop then start ftvm fail")
Exemple #2
0
def stop_libvirt_process(parser):

    ssh = shell_server.get_ssh(parser["PrimaryOS_ip"], parser["PrimaryOS_usr"],
                               parser["PrimaryOS_pwd"])  #獲得ssh
    FTsystem.stop(ssh)
    if FTsystem.get_status(ssh) == "running":
        raise TA_error.Process_Error("libvirt in host OS cannot stop")
    ssh.close()
Exemple #3
0
def preprocess_backupOS_FTsystem(parser):
    """
  preprocess backupOS FTsystem
  
  check FTsystem status 

  start/stop FTsystem

  raise exception if FTsystem can not start/stop
  """
    if parser["pre_check_backupOS_FTsystem"] == "yes":
        ssh = shell_server.get_ssh(parser["BackupOS_ip"], parser["BackupOS_usr"], parser["BackupOS_pwd"])
        status = FTsystem.get_status(ssh)
        if status == "not running" and parser["pre_backupOS_FTsystem_start"] == "yes":
            FTsystem.start(ssh)
            time.sleep(float(parser["pre_backupOS_FTsystem_start_time"]))
            if FTsystem.get_status(ssh) == "not running":
                ssh.close()
                raise TA_error.Preprocess_Error("backupOS FTsystem can not start")
        if status == "running" and parser["pre_backupOS_FTsystem_start"] == "no":
            FTsystem.stop(ssh)
            time.sleep(float(parser["pre_backupOS_FTsystem_start_time"]))
            if FTsystem.get_status(ssh) == "running":
                ssh.close()
                raise TA_error.Preprocess_Error("backupOS FTsystem can not stop")
        ssh.close()
Exemple #4
0
def preprocess_slaveOS_FTsystem(parser):
    """
    preprocess backupOS FTsystem part
  
    check FTsystem status 

    start/stop FTsystem

    raise exception if FTsystem can not start/stop

    :called func: preprocess_backupOS_OS
    :param parser: is a dict, get from Test config file
    """
    if parser["pre_check_slaveOS_FTsystem"] == "yes":
        ssh = shell_server.get_ssh(parser["SlaveOS_ip"], parser["SlaveOS_usr"],
                                   parser["SlaveOS_pwd"])  #獲得ssh
        status = FTsystem.get_status(ssh)
        if status == "not running" and parser[
                "pre_slaveOS_FTsystem_start"] == "yes":  #若狀態不為running且根據參數必需是running則進入
            FTsystem.start(ssh)  #透過ssh開啟libvirt
            time.sleep(float(parser["pre_slaveOS_FTsystem_start_time"]))
        if FTsystem.get_status(
                ssh) == "not running":  #若狀態不為running則raise exception
            ssh.close()
            raise TA_error.Preprocess_Error("slaveOS FTsystem can not start")
        if status == "running" and parser[
                "pre_slaveOS_FTsystem_start"] == "no":  #若狀態為running且根據參數必需不是running則進入
            FTsystem.stop(ssh)
            time.sleep(float(parser["pre_slaveOS_FTsystem_start_time"]))
            if FTsystem.get_status(
                    ssh) == "running":  #若狀態為running則raise exception
                ssh.close()
                raise TA_error.Preprocess_Error(
                    "slaveOS FTsystem can not stop")
    ssh.close()
Exemple #5
0
def kill_libvirt_process(parser):
	"""
	kill libvirt process on hostOS
	"""
	ssh = shell_server.get_ssh(parser["GuestOS_ip"]
                              , parser["GuestOS_usr"]
                              , parser["GuestOS_pwd"])
	pid = FTsystem.get_pid(ssh)
	cmd = cmd_kill.kill_cmd(pid, 9)
	s_stdin, s_stdout, s_stderr = ssh.exec_command("sudo "+cmd)
	ssh.close()
Exemple #6
0
def FTsystem_running_in_hostOS(parser):
	"""
	FTsystem is running in hostOS or not

	return True/raise exception
	"""
	ssh = shell_server.get_ssh(parser["HostOS_ip"]
                              , parser["HostOS_usr"]
                              , parser["HostOS_pwd"])
	if FTsystem.get_status(ssh) == "running":
		return True
	raise TA_error.Assert_Error("FTsystem is not running on hostOS")
Exemple #7
0
def libvirt_running_in_hostOS(parser):
    """
	libvirt process is running in hostOS or not
	:param parser: config
	:return: True/raise exception
	"""
    if "ast_libvirt_running_wait_time" in parser.keys(
    ):  #若參數ast_libvirt_running_wait_time存在於parser,則進入
        time.sleep(float(parser["ast_libvirt_running_wait_time"]))
    ssh = shell_server.get_ssh(parser["PrimaryOS_ip"], parser["PrimaryOS_usr"],
                               parser["PrimaryOS_pwd"])  #獲得ssh
    if FTsystem.is_running(ssh):
        return True
    ssh.close()
    raise TA_error.Assert_Error("libivrt isn't running")
Exemple #8
0
def FTsystem_running_in_hostOS(parser):
    """
	FTsystem is running in hostOS 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 FTsystem.get_status(ssh) == "running":  #透過ssh詢問FTsystem之狀態是否為running
        ssh.close()
        return True

    ssh.close()
    raise TA_error.Assert_Error("FTsystem is not running in hostOS")
Exemple #9
0
def kill_libvirt_process(parser):
    """
	kill libvirt process on hostOS

	:param parser: is a dict, get from Test config file
	"""
    if "pro_wait_time_kill_libvirt_p" in parser.keys(
    ):  #若pro_wait_time_kill_libvirt_p存在於parser
        time.sleep(int(parser["pro_wait_time_kill_libvirt_p"]))

    ssh = shell_server.get_ssh(parser["PrimaryOS_ip"], parser["PrimaryOS_usr"],
                               parser["PrimaryOS_pwd"])  #獲得ssh
    pid = FTsystem.get_pid(ssh)  #透過ssh獲得libvirt之pid
    if pid == False:
        ssh.close()
        raise TA_error.Process_Error("can not get libvirt pid")
    print "libvirt pid %s" % pid
    cmd = cmd_kill.kill_cmd(pid, 9)  #獲得kill libvirt process之指令字串
    s_stdin, s_stdout, s_stderr = ssh.exec_command("sudo " + cmd)  #透過ssh執行指令
    ssh.close()
def postprocess_hostOS_FTsystem(parser):
    """
	postprocess PrimaryOS FTsystem part

	check FTsystem status 

	start/stop FTsystem

	raise exception if FTsystem can not start/stop

	:called func: postprocess_hostOS
	:param parser: is a dict, get from Test config file
	"""
    if parser["pos_check_hostOS_FTsystem"] == "yes":
        ssh = shell_server.get_ssh(parser["PrimaryOS_ip"],
                                   parser["PrimaryOS_usr"],
                                   parser["PrimaryOS_pwd"])  #獲得ssh
        status = FTsystem.get_status(ssh)  #獲得libvirt status
        if status == "not running" and parser[
                "pos_hostOS_FTsystem_start"] == "yes":  #若狀態不為running且根據參數pos_hostOS_FTsystem_start必須為running,則進入
            FTsystem.start(ssh)  #透過ssh開啟libvirt
            time.sleep(float(parser["pos_hostOS_FTsystem_start_time"]))
            if FTsystem.get_status(
                    ssh) == "not running":  #若狀態不為running則raise exception
                ssh.close()
                raise TA_error.Postprocess_Error(
                    "PrimaryOS FTsystem can not start")
        if status == "running" and parser[
                "pos_hostOS_FTsystem_start"] == "no":  #若狀態為running且根據參數pos_hostOS_FTsystem_start必須不為running,則進入
            FTsystem.stop(ssh)  #透過ssh關閉libvirt
            time.sleep(float(parser["pos_hostOS_FTsystem_start_time"]))
            if FTsystem.get_status(
                    ssh) == "running":  #若狀態為running則raise exception
                ssh.close()
                raise TA_error.Postprocess_Error(
                    "PrimaryOS FTsystem can not stop")
        ssh.close()