Exemple #1
0
def run_virsh_hostname(test, params, env):
    """
    Test the command virsh hostname

    (1) Call virsh hostname
    (2) Call virsh hostname with an unexpected option
    (3) Call virsh hostname with libvirtd service stop
    """
    def virsh_hostname(option):
        cmd = "virsh hostname  %s" % option
        cmd_result = utils.run(cmd, ignore_status=True)
        logging.debug("Output: %s", cmd_result.stdout.strip())
        logging.debug("Error: %s", cmd_result.stderr.strip())
        logging.debug("Status: %d", cmd_result.exit_status)
        return cmd_result.exit_status, cmd_result.stdout.strip()

    hostname_result = utils.run("hostname", ignore_status=True)
    hostname = hostname_result.stdout.strip()

    # Prepare libvirtd service
    check_libvirtd = params.has_key("libvirtd")
    if check_libvirtd:
        libvirtd = params.get("libvirtd")
        if libvirtd == "off":
            libvirt_vm.libvirtd_stop()

    # Run test case
    option = params.get("options")
    status, hostname_test = virsh_hostname(option)

    # Recover libvirtd service start
    if libvirtd == "off":
        libvirt_vm.libvirtd_start()

    # Check status_error
    status_error = params.get("status_error")
    if status_error == "yes":
        if status == 0:
            raise error.TestFail("Command 'virsh hostname %s' succeeded "
                                 "(incorrect command)" % option)
    elif status_error == "no":
        if cmp(hostname, hostname_test) != 0:
            raise error.TestFail("Virsh cmd gives wrong hostname.")
        if status != 0:
            raise error.TestFail("Command 'virsh hostname %s' failed "
                                 "(correct command)" % option)
Exemple #2
0
def run_virsh_hostname(test, params, env):
    """
    Test the command virsh hostname

    (1) Call virsh hostname
    (2) Call virsh hostname with an unexpected option
    (3) Call virsh hostname with libvirtd service stop
    """

    hostname_result = utils.run("hostname", ignore_status=True)
    hostname = hostname_result.stdout.strip()

    # Prepare libvirtd service
    check_libvirtd = params.has_key("libvirtd")
    if check_libvirtd:
        libvirtd = params.get("libvirtd")
        if libvirtd == "off":
            libvirt_vm.libvirtd_stop()

    # Run test case
    option = params.get("virsh_hostname_options")
    try:
        hostname_test = virsh.hostname(option,
                                       ignore_status=False,
                                       debug=True)
        status = 0 # good
    except error.CmdError:
        status = 1 # bad
        hostname_test = None

    # Recover libvirtd service start
    if libvirtd == "off":
        libvirt_vm.libvirtd_start()

    # Check status_error
    status_error = params.get("status_error")
    if status_error == "yes":
        if status == 0:
            raise error.TestFail("Command 'virsh hostname %s' succeeded "
                                 "(incorrect command)" % option)
    elif status_error == "no":
        if cmp(hostname, hostname_test) != 0:
            raise error.TestFail("Virsh cmd gives hostname %s != %s." % (hostname_test, hostname))
        if status != 0:
            raise error.TestFail("Command 'virsh hostname %s' failed "
                                 "(correct command)" % option)
Exemple #3
0
def run_virsh_hostname(test, params, env):
    """
    Test the command virsh hostname

    (1) Call virsh hostname
    (2) Call virsh hostname with an unexpected option
    (3) Call virsh hostname with libvirtd service stop
    """

    hostname_result = utils.run("hostname", ignore_status=True)
    hostname = hostname_result.stdout.strip()

    # Prepare libvirtd service
    check_libvirtd = params.has_key("libvirtd")
    if check_libvirtd:
        libvirtd = params.get("libvirtd")
        if libvirtd == "off":
            libvirt_vm.libvirtd_stop()

    # Run test case
    option = params.get("virsh_hostname_options")
    try:
        hostname_test = virsh.hostname(option, ignore_status=False, debug=True)
        status = 0  # good
    except error.CmdError:
        status = 1  # bad
        hostname_test = None

    # Recover libvirtd service start
    if libvirtd == "off":
        libvirt_vm.libvirtd_start()

    # Check status_error
    status_error = params.get("status_error")
    if status_error == "yes":
        if status == 0:
            raise error.TestFail("Command 'virsh hostname %s' succeeded "
                                 "(incorrect command)" % option)
    elif status_error == "no":
        if cmp(hostname, hostname_test) != 0:
            raise error.TestFail("Virsh cmd gives hostname %s != %s." %
                                 (hostname_test, hostname))
        if status != 0:
            raise error.TestFail("Command 'virsh hostname %s' failed "
                                 "(correct command)" % option)
Exemple #4
0
def run_virsh_version(test, params, env):
    """
    Test the command virsh version

    (1) Call virsh version
    (2) Call virsh version with an unexpected option
    (3) Call virsh version with libvirtd service stop
    """

    connect_uri = libvirt_vm.normalize_connect_uri(
        params.get("connect_uri", "default"))

    # Prepare libvirtd service
    check_libvirtd = params.has_key("libvirtd")
    if check_libvirtd:
        libvirtd = params.get("libvirtd")
        if libvirtd == "off":
            libvirt_vm.libvirtd_stop()

    # Run test case
    option = params.get("virsh_version_options")
    try:
        output = virsh.version(option,
                               uri=connect_uri,
                               ignore_status=False,
                               debug=True)
        status = 0  #good
    except error.CmdError:
        status = 1  #bad

    # Recover libvirtd service start
    if libvirtd == "off":
        libvirt_vm.libvirtd_start()

    # Check status_error
    status_error = params.get("status_error")
    if status_error == "yes":
        if status == 0:
            raise error.TestFail("Command 'virsh version %s' succeeded "
                                 "(incorrect command)" % option)
    elif status_error == "no":
        if status != 0:
            raise error.TestFail("Command 'virsh version %s' failed "
                                 "(correct command)" % option)
Exemple #5
0
def run_virsh_version(test, params, env):
    """
    Test the command virsh version

    (1) Call virsh version
    (2) Call virsh version with an unexpected option
    (3) Call virsh version with libvirtd service stop
    """

    connect_uri = libvirt_vm.normalize_connect_uri( params.get("connect_uri",
                                                               "default") )

    # Prepare libvirtd service
    check_libvirtd = params.has_key("libvirtd")
    if check_libvirtd:
        libvirtd = params.get("libvirtd")
        if libvirtd == "off":
            libvirt_vm.libvirtd_stop()

    # Run test case
    option = params.get("virsh_version_options")
    try:
        output = virsh.version(option, uri=connect_uri,
                               ignore_status=False, debug=True)
        status = 0 #good
    except error.CmdError:
        status = 1 #bad

    # Recover libvirtd service start
    if libvirtd == "off":
        libvirt_vm.libvirtd_start()

    # Check status_error
    status_error = params.get("status_error")
    if status_error == "yes":
        if status == 0:
            raise error.TestFail("Command 'virsh version %s' succeeded "
                                 "(incorrect command)" % option)
    elif status_error == "no":
        if status != 0:
            raise error.TestFail("Command 'virsh version %s' failed "
                                 "(correct command)" % option)
Exemple #6
0
        logging.debug("Turning libvirtd into certain status.")
        if libvirtd_state == "off":
            libvirt_vm.libvirtd_stop()

        # Test uni-direction migration.
        logging.debug("Doing migration test.")
        if vm_ref != vm_name:
            vm.name = vm_ref    # For vm name error testing.
        ret_migrate = do_migration(delay, vm, dest_uri, options, extra)
        if vm_ref != vm_name:
            vm.name = vm_name

        # Recover libvirtd state.
        logging.debug("Recovering libvirtd status.")
        if libvirtd_state == "off":
            libvirt_vm.libvirtd_start()

        # Check vm state on destination.
        logging.debug("Checking %s state on %s." % (vm.name, vm.connect_uri))
        if options.count("dname") or extra.count("dname"):
            vm.name = extra.split()[1].strip()
        check_dest_state = True
        dest_state = params.get("virsh_migrate_dest_state", "running")
        check_dest_state = check_vm_state(vm, dest_state)
        logging.info("Supposed state: %s" % dest_state)
        logging.info("Actual state: %s" % vm.state())

        # Recover VM state.
        logging.debug("Recovering %s state." % vm.name)
        if src_state == "paused":
            vm.resume()
Exemple #7
0
        logging.debug("Turning libvirtd into certain status.")
        if libvirtd_state == "off":
            libvirt_vm.libvirtd_stop()

        # Test uni-direction migration.
        logging.debug("Doing migration test.")
        if vm_ref != vm_name:
            vm.name = vm_ref    # For vm name error testing.
        ret_migrate = do_migration(delay, vm, dest_uri, options, extra)
        if vm_ref != vm_name:
            vm.name = vm_name

        # Recover libvirtd state.
        logging.debug("Recovering libvirtd status.")
        if libvirtd_state == "off":
            libvirt_vm.libvirtd_start()

        # Check vm state on destination.
        logging.debug("Checking %s state on %s." % (vm.name, vm.connect_uri))
        if options.count("dname") or extra.count("dname"):
            vm.name = extra.split()[1].strip()
        check_dest_state = True
        dest_state = params.get("virsh_migrate_dest_state", "running")
        check_dest_state = check_vm_state(vm, dest_state)
        logging.info("Supposed state: %s" % dest_state)
        logging.info("Actual state: %s" % vm.state())

        # Recover VM state.
        logging.debug("Recovering %s state." % vm.name)
        if src_state == "paused":
            vm.resume()