本文整理汇总了Python中virttest.env_process.preprocess_vm函数的典型用法代码示例。如果您正苦于以下问题:Python preprocess_vm函数的具体用法?Python preprocess_vm怎么用?Python preprocess_vm使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了preprocess_vm函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_guest_cpuid
def get_guest_cpuid(self, cpu_model, feature=None, extra_params=None, qom_mode=False):
if not qom_mode:
test_kernel_dir = os.path.join(data_dir.get_deps_dir(), "cpuid", "src")
os.chdir(test_kernel_dir)
utils.make("cpuid_dump_kernel.bin")
vm_name = params['main_vm']
params_b = params.copy()
if not qom_mode:
params_b["kernel"] = os.path.join(
test_kernel_dir, "cpuid_dump_kernel.bin")
params_b["cpu_model"] = cpu_model
params_b["cpu_model_flags"] = feature
del params_b["images"]
del params_b["nics"]
if extra_params:
params_b.update(extra_params)
env_process.preprocess_vm(self, params_b, env, vm_name)
vm = env.get_vm(vm_name)
dbg('is dead: %r', vm.is_dead())
vm.create()
self.vm = vm
if qom_mode:
return get_qom_cpuid(self, vm)
else:
return get_test_kernel_cpuid(self, vm)
示例2: run
def run(test, params, env):
"""
Qemu guest pxe boot test:
1). check npt/ept function enable, then boot vm
2). execute query/info cpus in loop
3). verify vm not paused during pxe booting
params:
:param test: QEMU test object
:param params: Dictionary with the test parameters
:param env: Dictionary with test environment.
"""
restore_mmu_cmd = None
pxe_timeout = int(params.get("pxe_timeout", 60))
error_context.context("Enable ept/npt", logging.info)
try:
flag = list(filter(lambda x: x in utils_misc.get_cpu_flags(),
['ept', 'npt']))[0]
except IndexError:
logging.info("Host doesn't support ept/npt, skip the configuration")
else:
enable_mmu_cmd = params["enable_mmu_cmd_%s" % flag]
check_mmu_cmd = params["check_mmu_cmd_%s" % flag]
restore_mmu_cmd = params["restore_mmu_cmd_%s" % flag]
status = process.system(check_mmu_cmd, timeout=120, ignore_status=True,
shell=True)
if status != 0:
_kill_vms(params, env)
process.run(enable_mmu_cmd, shell=True)
params["start_vm"] = "yes"
params["kvm_vm"] = "yes"
params["paused_after_start_vm"] = "yes"
error_context.context("Try to boot from NIC", logging.info)
env_process.preprocess_vm(test, params, env, params["main_vm"])
vm = env.get_vm(params["main_vm"])
bg = utils_misc.InterruptedThread(_capture_tftp, (test, vm, pxe_timeout))
count = 0
try:
bg.start()
error_context.context("Query cpus in loop", logging.info)
vm.resume()
while True:
count += 1
try:
vm.monitor.info("cpus")
vm.verify_status("running")
if not bg.is_alive():
break
except qemu_monitor.MonitorSocketError:
test.fail("Qemu looks abnormally, please read the log")
logging.info("Execute info/query cpus %d times", count)
finally:
bg.join()
if restore_mmu_cmd:
_kill_vms(params, env)
process.run(restore_mmu_cmd, shell=True)
示例3: get_guest_cpuid
def get_guest_cpuid(self, cpu_model, feature=None, extra_params=None):
test_kernel_dir = os.path.join(data_dir.get_deps_dir(), "cpuid", "src")
os.chdir(test_kernel_dir)
utils.make("cpuid_dump_kernel.bin")
vm_name = params['main_vm']
params_b = params.copy()
params_b["kernel"] = os.path.join(
test_kernel_dir, "cpuid_dump_kernel.bin")
params_b["cpu_model"] = cpu_model
params_b["cpu_model_flags"] = feature
del params_b["images"]
del params_b["nics"]
if extra_params:
params_b.update(extra_params)
env_process.preprocess_vm(self, params_b, env, vm_name)
vm = env.get_vm(vm_name)
dbg('is dead: %r', vm.is_dead())
vm.create()
self.vm = vm
vm.resume()
timeout = float(params.get("login_timeout", 240))
f = lambda: re.search("==END TEST==", vm.serial_console.get_output())
if not utils_misc.wait_for(f, timeout, 1):
raise error.TestFail("Could not get test complete message.")
test_output = parse_cpuid_dump(vm.serial_console.get_output())
if test_output is None:
raise error.TestFail("Test output signature not found in "
"output:\n %s", vm.serial_console.get_output())
vm.destroy(gracefully=False)
return test_output
示例4: run_valgrind_memalign
def run_valgrind_memalign(test, params, env):
"""
This case is from [general operation] Work around valgrind choking on our
use of memalign():
1.download valgrind form valgrind download page: www.valgrind.org.
2.install the valgrind in host.
3.run # valgrind /usr/libexec/qemu-kvm -vnc :0 -S -m 384 -monitor stdio
4.check the status and do continue the VM.
5.quit the VM.
@param test: QEMU test object
@param params: Dictionary with the test parameters
@param env: Dictionary with test environment
"""
interval = float(params.get("interval_time", "10"))
def valgrind_intall():
valgrind_install_cmd = params.get("valgrind_install_cmd")
s = utils.system(valgrind_install_cmd, timeout=3600)
if s != 0:
raise error.TestError("Fail to install valgrind")
else:
logging.info("Install valgrind successfully.")
valgring_support_check_cmd = params.get("valgring_support_check_cmd")
try:
utils.system(valgring_support_check_cmd,timeout=interval)
except Exception:
valgrind_intall()
params["start_vm"] = "yes"
env_process.preprocess_vm(test, params, env, params.get("main_vm"))
vm = env.get_vm(params["main_vm"])
time.sleep(interval)
vm.verify_status("running")
示例5: run
def run(test, params, env):
"""
Qemu invalid parameter in qemu command line test:
1) Try boot up guest with invalid parameters
2) Catch the error message shows by qemu process
:param test: QEMU test object
:param params: Dictionary with the test parameters
:param env: Dictionary with test environment.
"""
vm_name = params["main_vm"]
params['start_vm'] = "yes"
try:
error_context.context("Start guest with invalid parameters.")
env_process.preprocess_vm(test, params, env, vm_name)
vm = env.get_vm(vm_name)
vm.destroy()
except Exception as emsg:
error_context.context("Check guest exit status.")
if "(core dumped)" in str(emsg):
test.fail("Guest core dumped with invalid parameters.")
else:
logging.info("Guest quit as expect: %s" % str(emsg))
return
test.fail("Guest start normally, didn't quit as expect.")
示例6: start
def start(self):
"""
Start mlock basic test
"""
error_context.context("Get nr_mlock and nr_unevictable in host"
" before VM start!", logging.info)
self.mlock_pre = read_from_vmstat("nr_mlock")
self.unevictable_pre = read_from_vmstat("nr_unevictable")
logging.info("mlock_pre is %d and unevictable_pre is %d.",
self.mlock_pre, self.unevictable_pre)
self.params["start_vm"] = "yes"
error_context.context("Starting VM!", logging.info)
env_process.preprocess_vm(self.test, self.params,
self.env, self.params["main_vm"])
self.vm = self.env.get_vm(self.params["main_vm"])
self.vm.verify_alive()
error_context.context("Get nr_mlock and nr_unevictable in host"
" after VM start!", logging.info)
self.mlock_post = read_from_vmstat("nr_mlock")
self.unevictable_post = read_from_vmstat("nr_unevictable")
logging.info("mlock_post is %d and unevictable_post is %d.",
self.mlock_post, self.unevictable_post)
self._check_mlock_unevictable()
示例7: get_guest_cpuid
def get_guest_cpuid(self, cpu_model, feature=None):
test_kernel_dir = os.path.join(test.virtdir, "deps",
"cpuid_test_kernel")
os.chdir(test_kernel_dir)
utils.make("cpuid_dump_kernel.bin")
vm_name = params.get('main_vm')
params_b = params.copy()
params_b["kernel"] = os.path.join(test_kernel_dir, "cpuid_dump_kernel.bin")
params_b["cpu_model"] = cpu_model
params_b["cpu_model_flags"] = feature
del params_b["images"]
del params_b["nics"]
env_process.preprocess_vm(self, params_b, env, vm_name)
vm = env.get_vm(vm_name)
vm.create()
self.vm = vm
vm.resume()
timeout = float(params.get("login_timeout", 240))
f = lambda: re.search("==END TEST==", vm.serial_console.get_output())
if not utils_misc.wait_for(f, timeout, 1):
raise error.TestFail("Could not get test complete message.")
test_sig = re.compile("==START TEST==\n((?:.*\n)*)\n*==END TEST==")
test_output = test_sig.search(vm.serial_console.get_output())
if test_output == None:
raise error.TestFail("Test output signature not found in "
"output:\n %s", vm.serial_console.get_output())
self.clean()
return test_output.group(1)
示例8: run
def run(test, params, env):
"""
KVM boot with negative parameter test:
1) Try to boot VM with negative parameters.
2) Verify that qemu could handle the negative parameters.
Check the negative message (optional)
:param test: qemu test object
:param params: Dictionary with the test parameters
:param env: Dictionary with test environment.
"""
neg_msg = params.get("negative_msg")
if params.get("start_vm") == "yes":
test.error("Please set start_vm to no")
params["start_vm"] = "yes"
try:
error_context.context("Try to boot VM with negative parameters",
logging.info)
case_fail = False
env_process.preprocess_vm(test, params, env, params.get("main_vm"))
case_fail = True
except Exception as e:
if neg_msg:
error_context.context("Check qemu-qemu error message",
logging.info)
if neg_msg not in str(e):
msg = "Could not find '%s' in error message '%s'" % (
neg_msg, e)
test.fail(msg)
logging.debug("Could not boot up vm, %s" % e)
if case_fail:
test.fail("Did not raise exception during vm boot up")
示例9: get_vm
def get_vm(self):
params = self.params
vm_name = params["main_vm"]
params["start_vm"] = "yes"
vm = self.env.get_vm(vm_name)
env_process.preprocess_vm(self.test, params, self.env, vm_name)
vm.verify_alive()
return vm
示例10: run
def run(test, params, env):
"""
KVM shutdown test:
1) Log into a guest
2) Send a shutdown command to the guest, or issue a system_powerdown
monitor command (depending on the value of shutdown_method)
3) Wait until the guest is down
:param test: QEMU test object
:param params: Dictionary with the test parameters
:param env: Dictionary with test environment
"""
timeout = int(params.get("login_timeout", 360))
shutdown_count = int(params.get("shutdown_count", 1))
shutdown_method = params.get("shutdown_method", "shell")
sleep_time = float(params.get("sleep_before_powerdown", 10))
shutdown_command = params.get("shutdown_command")
for i in xrange(shutdown_count):
vm = env.get_vm(params["main_vm"])
vm.verify_alive()
session = vm.wait_for_login(timeout=timeout)
error.base_context("shutting down the VM %s/%s" % (i + 1,
shutdown_count),
logging.info)
if params.get("setup_runlevel") == "yes":
error.context("Setup the runlevel for guest", logging.info)
expect_runlevel = params.get("expect_runlevel", "3")
ori_runlevel = session.cmd("runlevel")
ori_runlevel = re.findall("\d+", ori_runlevel)[-1]
if ori_runlevel == expect_runlevel:
logging.info("Guest runlevel is the same as expect.")
else:
session.cmd("init %s" % expect_runlevel)
tmp_runlevel = session.cmd("runlevel")
tmp_runlevel = re.findall("\d+", tmp_runlevel)[-1]
if tmp_runlevel != expect_runlevel:
logging.warn("Failed to setup runlevel for guest")
if shutdown_method == "shell":
# Send a shutdown command to the guest's shell
session.sendline(shutdown_command)
error.context("waiting VM to go down (shutdown shell cmd)",
logging.info)
elif shutdown_method == "system_powerdown":
# Sleep for a while -- give the guest a chance to finish booting
time.sleep(sleep_time)
# Send a system_powerdown monitor command
vm.monitor.cmd("system_powerdown")
error.context("waiting VM to go down "
"(system_powerdown monitor cmd)", logging.info)
if not utils_misc.wait_for(vm.is_dead, 360, 0, 1):
raise error.TestFail("Guest refuses to go down")
if i < shutdown_count - 1:
session.close()
env_process.preprocess_vm(test, params, env, params["main_vm"])
示例11: run
def run(test, params, env):
"""
[pci-bridge]Check stress when 31 block devices attached to 1 pci-bridge, this case will:
1) Attach one pci-bridge to guest.
2) Create 31 disks to this pci-bridge.
3) Start the guest.
4) Check 'info block'.
5) Read and write data on disks under pci bridge.
:param test: QEMU test object
:param params: Dictionary with the test parameters
:param env: Dictionary with test environment.
"""
error_context.context("Modify params!", logging.info)
image_parent_bus = params.get("image_parent_bus")
image_num = int(params.get("image_num", 0))
if image_num != 0:
for index in xrange(image_num):
image = "stg%s" % index
params["images"] = ' '.join([params["images"], image])
params["disk_pci_bus_%s" % image] = image_parent_bus
params["image_name_%s" % image] = "images/%s" % image
params["image_size_%s" % image] = "100M"
params["force_create_image_%s" % image] = "yes"
params["remove_image_%s" % image] = "yes"
params["blk_extra_params_%s" % image] = "serial=TARGET_DISK%s" % index
env_process.process_images(env_process.preprocess_image, test, params)
env_process.preprocess_vm(test, params, env, params["main_vm"])
error_context.context("Get the main VM!", logging.info)
vm = env.get_vm(params["main_vm"])
vm.verify_alive()
login_timeout = int(params.get("login_timeout", 360))
session = vm.wait_for_login(timeout=login_timeout)
error_context.context("Check 'info block'!", logging.info)
monitor_info_block = vm.monitor.info_block(False)
if image_num + 1 != len(monitor_info_block.keys()):
raise error.TestFail("Check 'info block' failed!")
logging.info("Check 'info block' succeed!")
error_context.context("Read and write data on all disks!", logging.info)
sub_test_type = params.get("sub_test_type", "dd_test")
images = params["images"]
images = images.split()
images.pop(0)
for image in images:
if params.get("dd_if") == "ZERO":
params["dd_of"] = image
else:
params["dd_if"] = image
utils_test.run_virt_sub_test(test, params, env, sub_test_type)
logging.info("Read and write data on all disks succeed!")
session.close()
示例12: run
def run(test, params, env):
"""
KVM boot time test:
1) Set init run level to 1
2) Send a shutdown command to the guest, or issue a system_powerdown
monitor command (depending on the value of shutdown_method)
3) Boot up the guest and measure the boot time
4) set init run level back to the old one
:param test: QEMU test object
:param params: Dictionary with the test parameters
:param env: Dictionary with test environment
"""
vm = env.get_vm(params["main_vm"])
vm.verify_alive()
timeout = int(params.get("login_timeout", 360))
session = vm.wait_for_login(timeout=timeout)
error.context("Set guest run level to 1", logging.info)
single_user_cmd = params['single_user_cmd']
session.cmd(single_user_cmd)
try:
error.context("Shut down guest", logging.info)
session.cmd('sync')
vm.destroy()
error.context("Boot up guest and measure the boot time", logging.info)
utils_memory.drop_caches()
vm.create()
vm.verify_alive()
session = vm.wait_for_serial_login(timeout=timeout)
boot_time = utils_misc.monotonic_time() - vm.start_monotonic_time
test.write_test_keyval({'result': "%ss" % boot_time})
expect_time = int(params.get("expect_bootup_time", "17"))
logging.info("Boot up time: %ss" % boot_time)
finally:
try:
error.context("Restore guest run level", logging.info)
restore_level_cmd = params['restore_level_cmd']
session.cmd(restore_level_cmd)
session.cmd('sync')
vm.destroy(gracefully=False)
env_process.preprocess_vm(test, params, env, vm.name)
vm.verify_alive()
vm.wait_for_login(timeout=timeout)
except Exception:
logging.warning("Can not restore guest run level, "
"need restore the image")
params["restore_image_after_testing"] = "yes"
if boot_time > expect_time:
raise error.TestFail(
"Guest boot up is taking too long: %ss" % boot_time)
session.close()
示例13: test
def test(self):
create_floppy(params)
params["start_vm"] = "yes"
vm_name = params.get("main_vm", "vm1")
env_process.preprocess_vm(test, params, env, vm_name)
vm = env.get_vm(vm_name)
vm.verify_alive()
self.session = vm.wait_for_login(timeout=login_timeout)
self.dest_dir = params.get("mount_dir")
# If mount_dir specified, treat guest as a Linux OS
# Some Linux distribution does not load floppy at boot and Windows
# needs time to load and init floppy driver
if self.dest_dir:
lsmod = self.session.cmd("lsmod")
if not "floppy" in lsmod:
self.session.cmd("modprobe floppy")
else:
time.sleep(20)
error.context("Formating floppy disk before using it")
format_cmd = params["format_floppy_cmd"]
self.session.cmd(format_cmd, timeout=120)
logging.info("Floppy disk formatted successfully")
if self.dest_dir:
error.context("Mounting floppy")
self.session.cmd("mount -t vfat %s %s" % (guest_floppy_path, self.dest_dir))
error.context("Testing floppy")
self.session.cmd(params["test_floppy_cmd"])
error.context("Copying file to the floppy")
md5_cmd = params.get("md5_cmd")
if md5_cmd:
md5_source = self.session.cmd("%s %s" % (params["md5_cmd"], source_file))
try:
md5_source = md5_source.split(" ")[0]
except IndexError:
error.TestError("Failed to get md5 from source file," " output: '%s'" % md5_source)
else:
md5_source = None
self.session.cmd("%s %s %s" % (params["copy_cmd"], source_file, dest_file))
logging.info("Succeed to copy file '%s' into floppy disk" % source_file)
error.context("Checking if the file is unchanged after copy")
if md5_cmd:
md5_dest = self.session.cmd("%s %s" % (params["md5_cmd"], dest_file))
try:
md5_dest = md5_dest.split(" ")[0]
except IndexError:
error.TestError("Failed to get md5 from dest file," " output: '%s'" % md5_dest)
if md5_source != md5_dest:
raise error.TestFail("File changed after copy to floppy")
else:
md5_dest = None
self.session.cmd("%s %s %s" % (params["diff_file_cmd"], source_file, dest_file))
示例14: run
def run(test, params, env):
"""
Boots VMs until one of them becomes unresponsive, and records the maximum
number of VMs successfully started:
1) boot the first vm
2) boot the second vm cloned from the first vm, check whether it boots up
and all booted vms respond to shell commands
3) go on until cannot create VM anymore or cannot allocate memory for VM
:param test: kvm test object
:param params: Dictionary with the test parameters
:param env: Dictionary with test environment.
"""
error_context.base_context("waiting for the first guest to be up",
logging.info)
vm = env.get_vm(params["main_vm"])
vm.verify_alive()
login_timeout = float(params.get("login_timeout", 240))
session = vm.wait_for_login(timeout=login_timeout)
num = 2
sessions = [session]
# Boot the VMs
try:
try:
while num <= int(params.get("max_vms")):
# Clone vm according to the first one
error_context.base_context("booting guest #%d" % num,
logging.info)
vm_name = "vm%d" % num
vm_params = vm.params.copy()
curr_vm = vm.clone(vm_name, vm_params)
env.register_vm(vm_name, curr_vm)
env_process.preprocess_vm(test, vm_params, env, vm_name)
params["vms"] += " " + vm_name
session = curr_vm.wait_for_login(timeout=login_timeout)
sessions.append(session)
logging.info("Guest #%d booted up successfully", num)
# Check whether all previous shell sessions are responsive
for i, se in enumerate(sessions):
error_context.context("checking responsiveness of guest"
" #%d" % (i + 1), logging.debug)
se.cmd(params.get("alive_test_cmd"))
num += 1
except Exception as emsg:
test.fail("Expect to boot up %s guests."
"Failed to boot up #%d guest with "
"error: %s." % (params["max_vms"], num, emsg))
finally:
for se in sessions:
se.close()
logging.info("Total number booted: %d" % (num - 1))
示例15: boot_guest_with_vectors
def boot_guest_with_vectors(vectors):
error.context("Boot guest with vectors = %s" % vectors, logging.info)
params["vectors"] = vectors
params["start_vm"] = "yes"
try:
env_process.preprocess_vm(test, params, env, params.get("main_vm"))
except virt_vm.VMError, err:
if int(vectors) < 0:
txt = "Parameter 'vectors' expects uint32_t"
if re.findall(txt, str(err)):
return