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') connect_uri = params.get('connect_uri') target = params.get('target') create_vm = False if not vm: create_vm = True elif vm_type == 'libvirt': connect_uri = libvirt_vm.normalize_connect_uri(connect_uri) if (not vm.connect_uri == connect_uri): create_vm = True else: pass if create_vm: vm = env.create_vm(vm_type, target, name, params, test.bindir) old_vm = copy.copy(vm) if vm_type == 'libvirt': if not vm.exists() and (params.get("type") != "unattended_install" and params.get("type") != "svirt_install"): error_msg = "Test VM %s does not exist." % name if name == params.get("main_vm"): error_msg += " You may need --install option to create the guest." raise error.TestError(error_msg) else: raise error.TestNAError(error_msg) remove_vm = False if params.get("force_remove_vm") == "yes": remove_vm = True if remove_vm: vm.remove() start_vm = False update_virtnet = False gracefully_kill = params.get("kill_vm_gracefully") == "yes" if 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 params.get("check_vm_needs_restart", "yes") == "yes": if vm.needs_restart(name=name, params=params, basedir=test.bindir): vm.devices = None start_vm = True old_vm.destroy(gracefully=gracefully_kill) update_virtnet = 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: if update_virtnet: vm.update_vm_id() vm.virtnet = utils_net.VirtNet(params, name, vm.instance) # Start the VM (or restart it if it's already up) if params.get("reuse_previous_config", "no") == "no": vm.create(name, params, test.bindir, migration_mode=params.get("migration_mode"), migration_fd=params.get("migration_fd"), migration_exec_cmd=params.get("migration_exec_cmd_dst")) else: vm.create(migration_mode=params.get("migration_mode"), migration_fd=params.get("migration_fd"), migration_exec_cmd=params.get("migration_exec_cmd_dst")) elif not vm.is_alive(): # VM is dead and won't be started, update params vm.devices = None vm.params = params else: # Only work when parameter 'start_vm' is no and VM is alive if params.get("kill_vm_before_test") == "yes" and\ params.get("start_vm") == "no": old_vm.destroy(gracefully=gracefully_kill) else: # VM is alive and we just need to open the serial console vm.create_serial_console() pause_vm = False if params.get("paused_after_start_vm") == "yes": pause_vm = True # Check the status of vm if (not vm.is_alive()) or (vm.is_paused()): pause_vm = False if pause_vm: vm.pause() if params.get("check_kernel_cmd_line_from_serial") == "yes": debug_msg = "" if vm.is_paused(): debug_msg += "VM is paused." elif not vm.is_alive(): debug_msg += "VM is not alive." elif vm.serial_console is None: debug_msg += "There is no serial console in VM." if debug_msg: debug_msg += " Skip the kernel command line check." logging.warn(debug_msg) return cmd_line = params.get("kernel_cmd_line_str", "Command line:") try: output = vm.serial_console.read_until_output_matches(cmd_line, timeout=60) kernel_cmd_line = re.findall("%s.*" % cmd_line, output[1])[0] kernel_options_exist = params.get("kernel_options_exist", "") kernel_options_not_exist = params.get("kernel_options_not_exist", "") err_msg = "" for kernel_option in kernel_options_exist.split(): if kernel_option not in kernel_cmd_line: err_msg += "%s not in kernel command line" % kernel_option err_msg += " as expect." for kernel_option in kernel_options_not_exist.split(): if kernel_option in kernel_cmd_line: err_msg += "%s exist in kernel command" % kernel_option err_msg += " line." if err_msg: err_msg += " Kernel command line get from" err_msg += " serial output is %s" % kernel_cmd_line raise error.TestError(err_msg) logging.info("Kernel command line get from serial port is" " as expect") except Exception, err: logging.warn("Did not get the kernel command line from serial " "port output. Skip the kernel command line check." "Error is %s" % err)
if vm_type == "libvirt": if params.get("setup_libvirt_polkit") == "yes": pol = test_setup.LibvirtPolkitConfig(params) try: pol.setup() except test_setup.PolkitWriteLibvirtdConfigError, e: logging.error("e") except test_setup.PolkitRulesSetupError, e: logging.error("e") except Exception, e: logging.error("Unexpected error:" % e) libvirtd_inst.restart() if vm_type == "libvirt": connect_uri = params.get("connect_uri") connect_uri = libvirt_vm.normalize_connect_uri(connect_uri) # Set the LIBVIRT_DEFAULT_URI to make virsh command # work on connect_uri as default behavior. os.environ['LIBVIRT_DEFAULT_URI'] = connect_uri # Execute any pre_commands if params.get("pre_command"): process_command(test, params, env, params.get("pre_command"), int(params.get("pre_command_timeout", "600")), params.get("pre_command_noncritical") == "yes") kernel_extra_params_add = params.get("kernel_extra_params_add") kernel_extra_params_remove = params.get("kernel_extra_params_remove") if params.get("disable_pci_msi"): disable_pci_msi = params.get("disable-pci_msi") if disable_pci_msi == "yes":
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') connect_uri = params.get('connect_uri') target = params.get('target') create_vm = False if not vm: create_vm = True elif vm_type == 'libvirt': connect_uri = libvirt_vm.normalize_connect_uri(connect_uri) if (not vm.connect_uri == connect_uri): create_vm = True else: pass if create_vm: vm = env.create_vm(vm_type, target, name, params, test.bindir) old_vm = copy.copy(vm) if vm_type == 'libvirt': if not vm.exists() and (params.get("type") != "unattended_install" and params.get("type") != "svirt_install"): error_msg = "Test VM %s does not exist." % name if name == params.get("main_vm"): error_msg += " You may need --install option to create the guest." raise error.TestError(error_msg) else: raise error.TestNAError(error_msg) remove_vm = False if params.get("force_remove_vm") == "yes": remove_vm = True if remove_vm: vm.remove() start_vm = False update_virtnet = False gracefully_kill = params.get("kill_vm_gracefully") == "yes" if 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 params.get("check_vm_needs_restart", "yes") == "yes": if vm.needs_restart(name=name, params=params, basedir=test.bindir): vm.devices = None start_vm = True old_vm.destroy(gracefully=gracefully_kill) update_virtnet = 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: if update_virtnet: vm.update_vm_id() vm.virtnet = utils_net.VirtNet(params, name, vm.instance) # Start the VM (or restart it if it's already up) if params.get("reuse_previous_config", "no") == "no": vm.create( name, params, test.bindir, migration_mode=params.get("migration_mode"), migration_fd=params.get("migration_fd"), migration_exec_cmd=params.get("migration_exec_cmd_dst")) else: vm.create( migration_mode=params.get("migration_mode"), migration_fd=params.get("migration_fd"), migration_exec_cmd=params.get("migration_exec_cmd_dst")) elif not vm.is_alive(): # VM is dead and won't be started, update params vm.devices = None vm.params = params else: # Only work when parameter 'start_vm' is no and VM is alive if params.get("kill_vm_before_test") == "yes" and\ params.get("start_vm") == "no": old_vm.destroy(gracefully=gracefully_kill) else: # VM is alive and we just need to open the serial console vm.create_serial_console() pause_vm = False if params.get("paused_after_start_vm") == "yes": pause_vm = True # Check the status of vm if (not vm.is_alive()) or (vm.is_paused()): pause_vm = False if pause_vm: vm.pause()
if vm_type == "libvirt": if params.get("setup_libvirt_polkit") == "yes": pol = test_setup.LibvirtPolkitConfig(params) try: pol.setup() except test_setup.PolkitWriteLibvirtdConfigError, e: logging.error("e") except test_setup.PolkitRulesSetupError, e: logging.error("e") except Exception, e: logging.error("Unexpected error:" % e) libvirtd_inst.restart() if vm_type == "libvirt": connect_uri = params.get("connect_uri") connect_uri = libvirt_vm.normalize_connect_uri(connect_uri) # Set the LIBVIRT_DEFAULT_URI to make virsh command # work on connect_uri as default behavior. os.environ['LIBVIRT_DEFAULT_URI'] = connect_uri # Execute any pre_commands if params.get("pre_command"): process_command(test, params, env, params.get("pre_command"), int(params.get("pre_command_timeout", "600")), params.get("pre_command_noncritical") == "yes") # if you want set "pci=nomsi" before test, set "disable_pci_msi = yes" # and pci_msi_sensitive = "yes" if params.get("pci_msi_sensitive", "no") == "yes": disable_pci_msi = params.get("disable_pci_msi", "no") image_filename = storage.get_image_filename(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. """ vm = env.get_vm(name) vm_type = params.get('vm_type') connect_uri = params.get('connect_uri') target = params.get('target') create_vm = False if not vm: create_vm = True elif vm_type == 'libvirt': connect_uri = libvirt_vm.normalize_connect_uri(connect_uri) if (not vm.connect_uri == connect_uri): create_vm = True else: pass if create_vm: vm = env.create_vm(vm_type, target, name, params, test.bindir) old_vm = copy.copy(vm) if vm_type == 'libvirt': if not vm.exists() and (params.get("type") != "unattended_install" and params.get("type") != "svirt_install"): error_msg = "Test VM %s does not exist." % name if name == params.get("main_vm"): error_msg += " You may need --install option to create the guest." raise error.TestError(error_msg) else: raise error.TestNAError(error_msg) remove_vm = False if params.get("force_remove_vm") == "yes": remove_vm = True if remove_vm: vm.remove() start_vm = False update_virtnet = False gracefully_kill = params.get("kill_vm_gracefully") == "yes" if 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 params.get("check_vm_needs_restart", "yes") == "yes": if vm.needs_restart(name=name, params=params, basedir=test.bindir): vm.devices = None start_vm = True old_vm.destroy(gracefully=gracefully_kill) update_virtnet = 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: if update_virtnet: vm.update_vm_id() vm.virtnet = utils_net.VirtNet(params, name, vm.instance) # Start the VM (or restart it if it's already up) if params.get("reuse_previous_config", "no") == "no": vm.create( name, params, test.bindir, migration_mode=params.get("migration_mode"), migration_fd=params.get("migration_fd"), migration_exec_cmd=params.get("migration_exec_cmd_dst")) else: vm.create( migration_mode=params.get("migration_mode"), migration_fd=params.get("migration_fd"), migration_exec_cmd=params.get("migration_exec_cmd_dst")) elif not vm.is_alive(): # VM is dead and won't be started, update params vm.devices = None vm.params = params else: # Only work when parameter 'start_vm' is no and VM is alive if params.get("kill_vm_before_test") == "yes" and\ params.get("start_vm") == "no": old_vm.destroy(gracefully=gracefully_kill) else: # VM is alive and we just need to open the serial console vm.create_serial_console() pause_vm = False if params.get("paused_after_start_vm") == "yes": pause_vm = True # Check the status of vm if (not vm.is_alive()) or (vm.is_paused()): pause_vm = False if pause_vm: vm.pause() if params.get("check_kernel_cmd_line_from_serial") == "yes": debug_msg = "" if vm.is_paused(): debug_msg += "VM is paused." elif not vm.is_alive(): debug_msg += "VM is not alive." elif vm.serial_console is None: debug_msg += "There is no serial console in VM." if debug_msg: debug_msg += " Skip the kernel command line check." logging.warn(debug_msg) return cmd_line = params.get("kernel_cmd_line_str", "Command line:") try: output = vm.serial_console.read_until_output_matches(cmd_line, timeout=60) kernel_cmd_line = re.findall("%s.*" % cmd_line, output[1])[0] kernel_options_exist = params.get("kernel_options_exist", "") kernel_options_not_exist = params.get("kernel_options_not_exist", "") err_msg = "" for kernel_option in kernel_options_exist.split(): if kernel_option not in kernel_cmd_line: err_msg += "%s not in kernel command line" % kernel_option err_msg += " as expect." for kernel_option in kernel_options_not_exist.split(): if kernel_option in kernel_cmd_line: err_msg += "%s exist in kernel command" % kernel_option err_msg += " line." if err_msg: err_msg += " Kernel command line get from" err_msg += " serial output is %s" % kernel_cmd_line raise error.TestError(err_msg) logging.info("Kernel command line get from serial port is" " as expect") except Exception, err: logging.warn("Did not get the kernel command line from serial " "port output. Skip the kernel command line check." "Error is %s" % err)
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') connect_uri = params.get('connect_uri') target = params.get('target') create_vm = False if not vm: create_vm = True elif vm_type == 'libvirt': connect_uri = libvirt_vm.normalize_connect_uri(connect_uri) if (not vm.connect_uri == connect_uri): create_vm = True else: pass if create_vm: vm = env.create_vm(vm_type, target, name, params, test.bindir) old_vm = copy.copy(vm) if vm_type == 'libvirt': if not vm.exists() and (params.get("type") != "unattended_install" and params.get("type") != "svirt_install"): error_msg = "Test VM %s does not exist." % name if name == params.get("main_vm"): error_msg += " You may need --install option to create the guest." raise error.TestError(error_msg) else: raise error.TestNAError(error_msg) remove_vm = False if params.get("force_remove_vm") == "yes": remove_vm = True if remove_vm: vm.remove() start_vm = False update_virtnet = False gracefully_kill = params.get("kill_vm_gracefully") == "yes" if 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 params.get("check_vm_needs_restart", "yes") == "yes": if vm.needs_restart(name=name, params=params, basedir=test.bindir): vm.devices = None start_vm = True old_vm.destroy(gracefully=gracefully_kill) update_virtnet = 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: if update_virtnet: vm.update_vm_id() vm.virtnet = utils_net.VirtNet(params, name, vm.instance) # Start the VM (or restart it if it's already up) if params.get("reuse_previous_config", "no") == "no": vm.create(name, params, test.bindir, migration_mode=params.get("migration_mode"), migration_fd=params.get("migration_fd"), migration_exec_cmd=params.get("migration_exec_cmd_dst")) else: vm.create(migration_mode=params.get("migration_mode"), migration_fd=params.get("migration_fd"), migration_exec_cmd=params.get("migration_exec_cmd_dst")) elif not vm.is_alive(): # VM is dead and won't be started, update params vm.devices = None vm.params = params else: # Only work when parameter 'start_vm' is no and VM is alive if params.get("kill_vm_before_test") == "yes" and\ params.get("start_vm") == "no": old_vm.destroy(gracefully=gracefully_kill) else: # VM is alive and we just need to open the serial console vm.create_serial_console() pause_vm = False if params.get("paused_after_start_vm") == "yes": pause_vm = True # Check the status of vm if (not vm.is_alive()) or (vm.is_paused()): pause_vm = False if pause_vm: vm.pause()