Beispiel #1
0
 def attach_hook():
     """
     Check attach hooks.
     """
     # Start a domain with qemu command.
     disk_src = vm.get_first_disk_devices()['source']
     vm_test = "foo"
     prepare_hook_file(hook_script %
                       (vm_test, hook_log))
     qemu_bin = params.get("qemu_bin", "/usr/libexec/qemu-kvm")
     if "ppc" in platform.machine():
         qemu_bin = "%s -machine pseries" % qemu_bin
     qemu_cmd = ("%s -drive file=%s,if=none,bus=0,unit=1"
                 " -monitor unix:/tmp/demo,"
                 "server,nowait -name %s" %
                 (qemu_bin, disk_src, vm_test))
     ret = process.run("%s &" % qemu_cmd, shell=True)
     pid = process.run("ps -ef | grep '%s' | grep -v grep | awk"
                       " '{print $2}'" % qemu_cmd, shell=True).stdout.strip()
     if not pid:
         test.fail("Cannot get pid of qemu command")
     ret = virsh.qemu_attach(pid, **virsh_dargs)
     if ret.exit_status:
         utils_misc.kill_process_tree(pid)
         test.fail("Cannot attach qemu process")
     else:
         virsh.destroy(vm_test)
     hook_str = hook_file + " " + vm_test + " attach begin -"
     if not check_hooks(hook_str):
         test.fail("Failed to check"
                   " attach hooks")
Beispiel #2
0
 def attach_hook():
     """
     Check attach hooks.
     """
     # Start a domain with qemu command.
     disk_src = vm.get_first_disk_devices()['source']
     vm_test = "foo"
     prepare_hook_file(hook_script %
                       (vm_test, hook_log))
     qemu_bin = params.get("qemu_bin", "/usr/libexec/qemu-kvm")
     if "ppc" in platform.machine():
         qemu_bin = "%s -machine pseries" % qemu_bin
     qemu_cmd = ("%s -drive file=%s,if=none,bus=0,unit=1"
                 " -monitor unix:/tmp/demo,"
                 "server,nowait -name %s" %
                 (qemu_bin, disk_src, vm_test))
     ret = utils.run("%s &" % qemu_cmd)
     pid = utils.run("ps -ef | grep '%s' | grep -v grep | awk"
                     " '{print $2}'" % qemu_cmd).stdout.strip()
     if not pid:
         raise error.TestFail("Cannot get pid of qemu command")
     ret = virsh.qemu_attach(pid, **virsh_dargs)
     if ret.exit_status:
         utils_misc.kill_process_tree(pid)
         raise error.TestFail("Cannot attach qemu process")
     else:
         virsh.destroy(vm_test)
     hook_str = hook_file + " " + vm_test + " attach begin -"
     if not check_hooks(hook_str):
         raise error.TestFail("Failed to check"
                              " attach hooks")
Beispiel #3
0
 def attach_hook():
     """
     Check attach hooks.
     """
     # Start a domain with qemu command.
     disk_src = vm.get_first_disk_devices()['source']
     vm_test = "foo"
     prepare_hook_file(hook_script % (vm_test, hook_log))
     qemu_bin = params.get("qemu_bin", "/usr/libexec/qemu-kvm")
     qemu_cmd = ("%s -cdrom %s -monitor unix:/tmp/demo,"
                 "server,nowait -name %s" % (qemu_bin, disk_src, vm_test))
     ret = utils.run("%s &" % qemu_cmd)
     pid = utils.run("ps -ef | grep '%s' | grep -v grep | awk"
                     " '{print $2}'" % qemu_cmd).stdout.strip()
     if not pid:
         raise error.TestFail("Cannot get pid of qemu command")
     ret = virsh.qemu_attach(pid, **virsh_dargs)
     if ret.exit_status:
         utils_misc.kill_process_tree(pid)
         raise error.TestFail("Cannot attach qemu process")
     else:
         virsh.destroy(vm_test)
     hook_str = hook_file + " " + vm_test + " attach begin -"
     if not check_hooks(hook_str):
         raise error.TestFail("Failed to check" " attach hooks")
Beispiel #4
0
 def attach_hook():
     """
     Check attach hooks.
     """
     # Start a domain with qemu command.
     disk_src = vm.get_first_disk_devices()['source']
     vm_test = "foo"
     prepare_hook_file(hook_script %
                       (vm_test, hook_log))
     qemu_bin = params.get("qemu_bin", "/usr/libexec/qemu-kvm")
     if "ppc" in platform.machine():
         qemu_cmd = ("%s -machine pseries"
                     " -drive file=%s,if=none,bus=0,unit=1"
                     " -monitor unix:/tmp/demo,"
                     "server,nowait -name %s" %
                     (qemu_bin, disk_src, vm_test))
     else:
         qemu_cmd = ("%s -drive file=%s,if=none,bus=0,unit=1"
                     " -monitor unix:/tmp/demo,"
                     "server,nowait -name %s" %
                     (qemu_bin, disk_src, vm_test))
     # After changed above command, qemu-attach failed
     os.system('%s &' % qemu_cmd)
     sta, pid = process.getstatusoutput("pgrep qemu-kvm")
     if not pid:
         test.fail("Cannot get pid of qemu command")
     ret = virsh.qemu_attach(pid, **virsh_dargs)
     if ret.exit_status:
         utils_misc.kill_process_tree(pid)
         test.fail("Cannot attach qemu process")
     else:
         virsh.destroy(vm_test)
     hook_str = hook_file + " " + vm_test + " attach begin -"
     if not check_hooks(hook_str):
         test.fail("Failed to check attach hooks")
Beispiel #5
0
def run(test, params, env):
    """
    Test command: virsh qemu-attach.
    """
    pid = params.get("pid", None)
    options = params.get("options", "")
    status_error = "yes" == params.get("status_error", "no")
    libvirtd_inst = utils_libvirtd.Libvirtd()
    new_vm = None

    try:
        # Prepare qemu-kvm process
        if pid is None:
            params_b = params.copy()
            new_vm = qemu_vm.VM('attach_dom', params_b, test.bindir,
                                env['address_cache'])
            new_vm.create()
            pid = new_vm.get_pid()

        # Run virsh command
        logging.debug("The qemu-kvm pid for attach is %s" % pid)
        cmd_result = virsh.qemu_attach(pid,
                                       options,
                                       ignore_status=True,
                                       debug=True)
        status = cmd_result.exit_status

        # Check result
        if not libvirtd_inst.is_running():
            test.fail("Libvirtd is not running after run command.")
        if status_error:
            if not status:
                test.fail("Expect fail, run succeed.")
            else:
                logging.debug("Command failed as expected.")
        else:
            if status:
                err_msg = "error: Failed to attach to pid"
                if err_msg in cmd_result.stderr:
                    test.fail("Command failed: %s" % cmd_result.stderr)
                list_output = virsh.dom_list().stdout.strip()
                if re.search('attach_dom', list_output):
                    test.fail("Command failed but domain found "
                              "in virsh list.")
                err_msg = "No worry, the command is explicitly unsupported, "
                err_msg += "it's a development crutch and not highly reliable"
                err_msg += " mechanism."
                test.cancel(err_msg)
    finally:
        # Cleanup
        if new_vm:
            if new_vm.is_alive():
                new_vm.destroy(gracefully=False)
        if not libvirtd_inst.is_running():
            libvirtd_inst.restart()
def run(test, params, env):
    """
    Test command: virsh qemu-attach.
    """
    pid = params.get("pid", None)
    options = params.get("options", "")
    status_error = "yes" == params.get("status_error", "no")
    libvirtd_inst = utils_libvirtd.Libvirtd()
    new_vm = None

    try:
        # Prepare qemu-kvm process
        if pid is None:
            params_b = params.copy()
            new_vm = qemu_vm.VM('attach_dom', params_b, test.bindir,
                                env['address_cache'])
            new_vm.create()
            pid = new_vm.get_pid()

        # Run virsh command
        logging.debug("The qemu-kvm pid for attach is %s" % pid)
        cmd_result = virsh.qemu_attach(pid, options,
                                       ignore_status=True,
                                       debug=True)
        status = cmd_result.exit_status

        # Check result
        if not libvirtd_inst.is_running():
            test.fail("Libvirtd is not running after run command.")
        if status_error:
            if not status:
                test.fail("Expect fail, run succeed.")
            else:
                logging.debug("Command failed as expected.")
        else:
            if status:
                err_msg = "error: Failed to attach to pid"
                if err_msg in cmd_result.stderr:
                    test.fail("Command failed: %s" % cmd_result.stderr)
                list_output = virsh.dom_list().stdout.strip()
                if re.search('attach_dom', list_output):
                    test.fail("Command failed but domain found "
                              "in virsh list.")
                err_msg = "No worry, the command is explicitly unsupported, "
                err_msg += "it's a development crutch and not highly reliable"
                err_msg += " mechanism."
                test.cancel(err_msg)
    finally:
        # Cleanup
        if new_vm:
            if new_vm.is_alive():
                new_vm.destroy(gracefully=False)
        if not libvirtd_inst.is_running():
            libvirtd_inst.restart()