Beispiel #1
0
def preprocess_vm(test, params, env, name):
    """
    Preprocess a single VM object according to the instructions in params.
    Start the VM if requested and get a screendump.

    @param test: An Autotest test object.
    @param params: A dict containing VM preprocessing parameters.
    @param env: The environment (a dict-like object).
    @param name: The name of the VM object.
    """
    logging.debug("Preprocessing VM '%s'", name)
    vm = env.get_vm(name)
    if not vm:
        logging.debug("VM object for '%s' does not exist, creating it", name)
        vm_type = params.get('vm_type')
        if vm_type == 'kvm':
            vm = kvm_vm.VM(name, params, test.bindir, env.get("address_cache"))
        env.register_vm(name, vm)

    start_vm = False

    if params.get("restart_vm") == "yes":
        logging.debug("Param 'restart_vm' specified, (re)starting VM")
        start_vm = True
    elif params.get("migration_mode"):
        logging.debug("Param 'migration_mode' specified, starting VM in "
                      "incoming migration mode")
        start_vm = True
    elif params.get("start_vm") == "yes":
        if not vm.is_alive():
            logging.debug("VM is not alive, starting it")
            start_vm = True
        if vm.needs_restart(name=name, params=params, basedir=test.bindir):
            logging.debug("Current VM specs differ from requested one; "
                          "restarting it")
            start_vm = True

    if start_vm:
        # Start the VM (or restart it if it's already up)
        vm.create(name,
                  params,
                  test.bindir,
                  migration_mode=params.get("migration_mode"))
    else:
        # Don't start the VM, just update its params
        vm.params = params

    scrdump_filename = os.path.join(test.debugdir, "pre_%s.ppm" % name)
    try:
        if vm.monitor and params.get("take_regular_screendumps") == "yes":
            vm.monitor.screendump(scrdump_filename, debug=False)
    except kvm_monitor.MonitorError, e:
        logging.warning(e)
def preprocess_vm(test, params, env, name):
    """
    Preprocess a single VM object according to the instructions in params.
    Start the VM if requested and get a screendump.

    @param test: An Autotest test object.
    @param params: A dict containing VM preprocessing parameters.
    @param env: The environment (a dict-like object).
    @param name: The name of the VM object.
    """
    logging.debug("Preprocessing VM '%s'..." % name)
    vm = env.get_vm(name)
    if not vm:
        logging.debug("VM object does not exist; creating it")
        vm = kvm_vm.VM(name, params, test.bindir, env.get("address_cache"))
        env.register_vm(name, vm)

    start_vm = False

    if params.get("restart_vm") == "yes":
        logging.debug("'restart_vm' specified; (re)starting VM...")
        start_vm = True
    elif params.get("migration_mode"):
        logging.debug("Starting VM in incoming migration mode...")
        start_vm = True
    elif params.get("start_vm") == "yes":
        if not vm.is_alive():
            logging.debug("VM is not alive; starting it...")
            start_vm = True
        elif vm.make_qemu_command() != vm.make_qemu_command(
                name, params, test.bindir):
            logging.debug("VM's qemu command differs from requested one; "
                          "restarting it...")
            start_vm = True

    if start_vm:
        # Start the VM (or restart it if it's already up)
        vm.create(name,
                  params,
                  test.bindir,
                  migration_mode=params.get("migration_mode"))
    else:
        # Don't start the VM, just update its params
        vm.params = params

    scrdump_filename = os.path.join(test.debugdir, "pre_%s.ppm" % name)
    try:
        if vm.monitor:
            vm.monitor.screendump(scrdump_filename)
    except kvm_monitor.MonitorError, e:
        logging.warn(e)
Beispiel #3
0
def preprocess_vm(test, params, env, name):
    """
    Preprocess a single VM object according to the instructions in params.
    Start the VM if requested and get a screendump.

    @param test: An Autotest test object.
    @param params: A dict containing VM preprocessing parameters.
    @param env: The environment (a dict-like object).
    @param name: The name of the VM object.
    """
    vm = env.get_vm(name)
    vm_type = params.get('vm_type')
    target = params.get('target')
    if not vm:
        if vm_type == 'kvm':
            vm = kvm_vm.VM(name, params, test.bindir, env.get("address_cache"))
        if vm_type == 'libvirt':
            vm = libvirt_vm.VM(name, params, test.bindir,
                               env.get("address_cache"))
        if vm_type == 'v2v':
            if target == 'libvirt' or target is None:
                vm = libvirt_vm.VM(name, params, test.bindir,
                                   env.get("address_cache"))
            if target == 'ovirt':
                vm = ovirt.VMManager(name, params, test.bindir,
                                     env.get("address_cache"))
        env.register_vm(name, vm)

    remove_vm = False
    if params.get("force_remove_vm") == "yes":
        remove_vm = True

    if remove_vm:
        vm.remove()

    start_vm = False

    if params.get("restart_vm") == "yes":
        start_vm = True
    elif params.get("migration_mode"):
        start_vm = True
    elif params.get("start_vm") == "yes":
        # need to deal with libvirt VM differently than qemu
        if vm_type == 'libvirt' or vm_type == 'v2v':
            if not vm.is_alive():
                start_vm = True
        else:
            if not vm.is_alive():
                start_vm = True
            if vm.needs_restart(name=name, params=params, basedir=test.bindir):
                start_vm = True

    if start_vm:
        if vm_type == "libvirt" and params.get("type") != "unattended_install":
            vm.params = params
            vm.start()
        elif vm_type == "v2v":
            vm.params = params
            vm.start()
        else:
            # Start the VM (or restart it if it's already up)
            vm.create(name,
                      params,
                      test.bindir,
                      migration_mode=params.get("migration_mode"),
                      migration_fd=params.get("migration_fd"))
            if params.get("paused_after_start_vm") == "yes":
                if vm.state() != "paused":
                    vm.pause()
    else:
        # Don't start the VM, just update its params
        vm.params = params
def preprocess_vm(test, params, env, name):
    """
    Preprocess a single VM object according to the instructions in params.
    Start the VM if requested and get a screendump.

    @param test: An Autotest test object.
    @param params: A dict containing VM preprocessing parameters.
    @param env: The environment (a dict-like object).
    @param name: The name of the VM object.
    """
    logging.debug("Preprocessing VM '%s'", name)
    vm = env.get_vm(name)
    vm_type = params.get('vm_type')
    if not vm:
        logging.debug("VM object for '%s' does not exist, creating it", name)
        if vm_type == 'kvm':
            vm = kvm_vm.VM(name, params, test.bindir, env.get("address_cache"))
        if vm_type == 'libvirt':
            vm = libvirt_vm.VM(name, params, test.bindir,
                               env.get("address_cache"))
        env.register_vm(name, vm)

    remove_vm = False
    if params.get("force_remove_vm") == "yes":
        logging.debug("'force_remove_vm' specified; removing VM...")
        remove_vm = True

    if remove_vm:
        vm.remove()

    start_vm = False

    if params.get("restart_vm") == "yes":
        logging.debug("Param 'restart_vm' specified, (re)starting VM")
        start_vm = True
    elif params.get("migration_mode"):
        logging.debug("Param 'migration_mode' specified, starting VM in "
                      "incoming migration mode")
        start_vm = True
    elif params.get("start_vm") == "yes":
        # need to deal with libvirt VM differently than qemu
        if vm_type == 'libvirt':
            if not vm.is_alive():
                logging.debug("VM is not alive; starting it...")
                start_vm = True
        else:
            if not vm.is_alive():
                logging.debug("VM is not alive, starting it")
                start_vm = True
            if vm.needs_restart(name=name, params=params, basedir=test.bindir):
                logging.debug("Current VM specs differ from requested one; "
                              "restarting it")
                start_vm = True

    if start_vm:
        if vm_type == "libvirt" and params.get("type") != "unattended_install":
            vm.params = params
            vm.start()
        else:
            # Start the VM (or restart it if it's already up)
            vm.create(name,
                      params,
                      test.bindir,
                      migration_mode=params.get("migration_mode"),
                      migration_fd=params.get("migration_fd"))
    else:
        # Don't start the VM, just update its params
        vm.params = params