def preprocess(test, params, env): """ Preprocess all VMs and images according to the instructions in params. Also, collect some host information, such as the KVM version. @param test: An Autotest test object. @param params: A dict containing all VM and image parameters. @param env: The environment (a dict-like object). """ # Start tcpdump if it isn't already running if not env.has_key("address_cache"): env["address_cache"] = {} if env.has_key("tcpdump") and not env["tcpdump"].is_alive(): env["tcpdump"].close() del env["tcpdump"] if not env.has_key("tcpdump"): command = "/usr/sbin/tcpdump -npvi any 'dst port 68'" logging.debug("Starting tcpdump (%s)...", command) env["tcpdump"] = kvm_subprocess.kvm_tail( command=command, output_func=_update_address_cache, output_params=(env["address_cache"],)) if kvm_utils.wait_for(lambda: not env["tcpdump"].is_alive(), 0.1, 0.1, 1.0): logging.warn("Could not start tcpdump") logging.warn("Status: %s" % env["tcpdump"].get_status()) logging.warn("Output:" + kvm_utils.format_str_for_message( env["tcpdump"].get_output())) # Destroy and remove VMs that are no longer needed in the environment requested_vms = kvm_utils.get_sub_dict_names(params, "vms") for key in env.keys(): vm = env[key] if not kvm_utils.is_vm(vm): continue if not vm.name in requested_vms: logging.debug("VM '%s' found in environment but not required for" " test; removing it..." % vm.name) vm.destroy() del env[key] # 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") # Preprocess all VMs and images process(test, params, env, preprocess_image, preprocess_vm) # Get the KVM kernel module version and write it as a keyval logging.debug("Fetching KVM module version...") if os.path.exists("/dev/kvm"): kvm_version = os.uname()[2] try: file = open("/sys/module/kvm/version", "r") kvm_version = file.read().strip() file.close() except: pass else: kvm_version = "Unknown" logging.debug("KVM module not loaded") logging.debug("KVM version: %s" % kvm_version) test.write_test_keyval({"kvm_version": kvm_version}) # Get the KVM userspace version and write it as a keyval logging.debug("Fetching KVM userspace version...") qemu_path = kvm_utils.get_path(test.bindir, params.get("qemu_binary", "qemu")) version_line = commands.getoutput("%s -help | head -n 1" % qemu_path) exp = re.compile("[Vv]ersion .*?,") match = exp.search(version_line) if match: kvm_userspace_version = " ".join(match.group().split()[1:]).strip(",") else: kvm_userspace_version = "Unknown" logging.debug("Could not fetch KVM userspace version") logging.debug("KVM userspace version: %s" % kvm_userspace_version) test.write_test_keyval({"kvm_userspace_version": kvm_userspace_version})
def preprocess(test, params, env): """ Preprocess all VMs and images according to the instructions in params. Also, collect some host information, such as the KVM version. @param test: An Autotest test object. @param params: A dict containing all VM and image parameters. @param env: The environment (a dict-like object). """ # Destroy and remove VMs that are no longer needed in the environment requested_vms = kvm_utils.get_sub_dict_names(params, "vms") for key in env.keys(): vm = env[key] if not kvm_utils.is_vm(vm): continue if not vm.name in requested_vms: logging.debug("VM '%s' found in environment but not required for" " test; removing it..." % vm.name) vm.destroy() del env[key] # 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", ) # Preprocess all VMs and images process(test, params, env, preprocess_image, preprocess_vm) # Get the KVM kernel module version and write it as a keyval logging.debug("Fetching KVM module version...") if os.path.exists("/dev/kvm"): kvm_version = os.uname()[2] try: file = open("/sys/module/kvm/version", "r") kvm_version = file.read().strip() file.close() except: pass else: kvm_version = "Unknown" logging.debug("KVM module not loaded") logging.debug("KVM version: %s" % kvm_version) test.write_test_keyval({"kvm_version": kvm_version}) # Get the KVM userspace version and write it as a keyval logging.debug("Fetching KVM userspace version...") qemu_path = os.path.join(test.bindir, "qemu") version_line = commands.getoutput("%s -help | head -n 1" % qemu_path) exp = re.compile("[Vv]ersion .*?,") match = exp.search(version_line) if match: kvm_userspace_version = " ".join(match.group().split()[1:]).strip(",") else: kvm_userspace_version = "Unknown" logging.debug("Could not fetch KVM userspace version") logging.debug("KVM userspace version: %s" % kvm_userspace_version) test.write_test_keyval({"kvm_userspace_version": kvm_userspace_version})