本文整理汇总了Python中virttest.virsh.save函数的典型用法代码示例。如果您正苦于以下问题:Python save函数的具体用法?Python save怎么用?Python save使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了save函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: run_restart_save_restore
def run_restart_save_restore(params, libvirtd, vm):
"""
Save and restore a domain after restart daemon.
"""
libvirtd.restart()
save_path = os.path.join(data_dir.get_tmp_dir(), 'tmp.save')
virsh.save(vm.name, save_path)
virsh.restore(save_path)
开发者ID:balamuruhans,项目名称:tp-libvirt,代码行数:8,代码来源:crash_regression.py
示例2: operations
def operations():
"""
Do save | domstats | blkdeviotune operations
"""
if self.operation == "save":
virsh.save(self.vm_name, self.save_file, debug=True, timeout=self.operation_timeout)
if self.operation == "domstats":
virsh.domstats(self.vm_name, opertions=self.operation_option, debug=True, timeout=self.operation_timeout)
if self.operation == "blkdeviotune":
virsh.blkdeviotune(self.vm_name, self.disk_tgt, debug=True, timeout=self.operation_timeout)
开发者ID:balamuruhans,项目名称:tp-libvirt,代码行数:10,代码来源:resource_abnormal.py
示例3: run_job_acquire
def run_job_acquire(params, libvirtd, vm):
"""
Save domain after queried block info
"""
vm.start()
res = virsh.qemu_monitor_command(vm.name, 'info block', '--hmp')
logging.debug(res)
save_path = os.path.join(data_dir.get_tmp_dir(), 'tmp.save')
virsh.save(vm.name, save_path)
vm.wait_for_shutdown()
开发者ID:balamuruhans,项目名称:tp-libvirt,代码行数:10,代码来源:crash_regression.py
示例4: check_disk_save_restore
def check_disk_save_restore(save_file, device_targets,
startup_policy):
"""
Check domain save and restore operation.
"""
# Save the domain.
ret = virsh.save(vm_name, save_file,
**virsh_dargs)
libvirt.check_exit_status(ret)
# Restore the domain.
restore_error = False
# Check disk startup policy option
if "optional" in startup_policy:
os.remove(disks[0]["source"])
restore_error = True
ret = virsh.restore(save_file, **virsh_dargs)
libvirt.check_exit_status(ret, restore_error)
if restore_error:
return
# Connect to the domain and check disk.
try:
session = vm.wait_for_login()
cmd = ("ls /dev/%s && mkfs.ext3 -F /dev/%s && mount /dev/%s"
" /mnt && ls /mnt && touch /mnt/test && umount /mnt"
% (device_targets[0], device_targets[0], device_targets[0]))
s, o = session.cmd_status_output(cmd)
if s:
session.close()
raise error.TestError("Failed to read/write disk in VM:"
" %s" % o)
session.close()
except (remote.LoginError, virt_vm.VMError, aexpect.ShellError), e:
raise error.TestError(str(e))
开发者ID:nertpinx,项目名称:tp-libvirt,代码行数:35,代码来源:virtual_disks_multidisks.py
示例5: check_save_restore
def check_save_restore(save_file):
"""
Test domain save and restore.
"""
# Save the domain.
ret = virsh.save(vm_name, save_file, **virsh_dargs)
libvirt.check_exit_status(ret)
# Restore the domain.
ret = virsh.restore(save_file, **virsh_dargs)
libvirt.check_exit_status(ret)
开发者ID:lento-sun,项目名称:tp-libvirt,代码行数:11,代码来源:virtual_disks_iscsi.py
示例6: check_bootorder_snapshot
def check_bootorder_snapshot(disk_name):
"""
Check VM disk's bootorder option with snapshot.
:param disk_name. The target disk to be checked.
"""
logging.info("Checking diskorder option with snapshot...")
snapshot1 = "s1"
snapshot2 = "s2"
snapshot2_file = os.path.join(test.tmpdir, "s2")
ret = virsh.snapshot_create(vm_name, "", **virsh_dargs)
libvirt.check_exit_status(ret)
ret = virsh.snapshot_create_as(vm_name, "%s --disk-only" % snapshot1,
**virsh_dargs)
libvirt.check_exit_status(ret)
ret = virsh.snapshot_dumpxml(vm_name, snapshot1)
libvirt.check_exit_status(ret)
cmd = "echo \"%s\" | grep %s.%s" % (ret.stdout, disk_name, snapshot1)
if utils.run(cmd, ignore_status=True).exit_status:
raise error.TestError("Check snapshot disk failed")
ret = virsh.snapshot_create_as(vm_name,
"%s --memspec file=%s,snapshot=external"
% (snapshot2, snapshot2_file),
**virsh_dargs)
libvirt.check_exit_status(ret)
ret = virsh.dumpxml(vm_name)
libvirt.check_exit_status(ret)
cmd = ("echo \"%s\" | grep -A 16 %s.%s | grep \"boot order='%s'\""
% (ret.stdout, disk_name, snapshot2, bootorder))
if utils.run(cmd, ignore_status=True).exit_status:
raise error.TestError("Check snapshot disk with bootorder failed")
snap_lists = virsh.snapshot_list(vm_name)
if snapshot1 not in snap_lists or snapshot2 not in snap_lists:
raise error.TestError("Check snapshot list failed")
# Check virsh save command after snapshot.
save_file = "/tmp/%s.save" % vm_name
ret = virsh.save(vm_name, save_file, **virsh_dargs)
libvirt.check_exit_status(ret)
# Check virsh restore command after snapshot.
ret = virsh.restore(save_file, **virsh_dargs)
libvirt.check_exit_status(ret)
#Passed all test.
os.remove(save_file)
开发者ID:CongLi,项目名称:tp-libvirt,代码行数:53,代码来源:virtual_disks_multidisks.py
示例7: check_save_restore
def check_save_restore(vm_name):
"""
Do save/restore operation and check status
"""
save_file = os.path.join(data_dir.get_tmp_dir(), vm_name + ".save")
try:
result = virsh.save(vm_name, save_file, ignore_status=True, debug=True)
libvirt.check_exit_status(result)
result = virsh.restore(save_file, ignore_status=True, debug=True)
libvirt.check_exit_status(result)
finally:
os.remove(save_file)
开发者ID:balamuruhans,项目名称:tp-libvirt,代码行数:12,代码来源:virsh_attach_detach_interface.py
示例8: check_save_restore
def check_save_restore():
"""
Test save and restore operation
"""
save_file = os.path.join(test.tmpdir, "%s.save" % vm_name)
ret = virsh.save(vm_name, save_file, **virsh_dargs)
libvirt.check_exit_status(ret)
ret = virsh.restore(save_file, **virsh_dargs)
libvirt.check_exit_status(ret)
if os.path.exists(save_file):
os.remove(save_file)
# Login to check vm status
vm.wait_for_login().close()
开发者ID:uni-peter-zheng,项目名称:tp-libvirt,代码行数:13,代码来源:libvirt_mem.py
示例9: manipulate_domain
def manipulate_domain(vm_name, action, recover=False):
"""
Save/managedsave/S3/S4 domain or recover it.
"""
tmp_dir = data_dir.get_tmp_dir()
save_file = os.path.join(tmp_dir, vm_name + ".save")
if not recover:
if action == "save":
save_option = ""
result = virsh.save(vm_name, save_file, save_option,
ignore_status=True, debug=True)
libvirt.check_exit_status(result)
elif action == "managedsave":
managedsave_option = ""
result = virsh.managedsave(vm_name, managedsave_option,
ignore_status=True, debug=True)
libvirt.check_exit_status(result)
elif action == "s3":
suspend_target = "mem"
result = virsh.dompmsuspend(vm_name, suspend_target,
ignore_status=True, debug=True)
libvirt.check_exit_status(result)
elif action == "s4":
suspend_target = "disk"
result = virsh.dompmsuspend(vm_name, suspend_target,
ignore_status=True, debug=True)
libvirt.check_exit_status(result)
# Wait domain state change: 'in shutdown' -> 'shut off'
utils_misc.wait_for(lambda: virsh.is_dead(vm_name), 5)
else:
logging.debug("No operation for the domain")
else:
if action == "save":
if os.path.exists(save_file):
result = virsh.restore(save_file, ignore_status=True, debug=True)
libvirt.check_exit_status(result)
os.remove(save_file)
else:
raise error.TestError("No save file for domain restore")
elif action in ["managedsave", "s4"]:
result = virsh.start(vm_name, ignore_status=True, debug=True)
libvirt.check_exit_status(result)
elif action == "s3":
suspend_target = "mem"
result = virsh.dompmwakeup(vm_name, ignore_status=True, debug=True)
libvirt.check_exit_status(result)
else:
logging.debug("No need recover the domain")
开发者ID:nertpinx,项目名称:tp-libvirt,代码行数:49,代码来源:virsh_setmem.py
示例10: run_pm_test
def run_pm_test(params, libvirtd, vm):
"""
Destroy VM after executed a series of operations about S3 and save restore
"""
vm_name = vm.name
vm_xml = VMXML.new_from_inactive_dumpxml(vm_name)
vm_xml_backup = vm_xml.copy()
save_path = os.path.join(data_dir.get_tmp_dir(), 'tmp.save')
try:
pm_xml = VMPMXML()
pm_xml.mem_enabled = 'yes'
vm_xml.pm = pm_xml
vm_xml.sync()
vm.prepare_guest_agent()
virsh.dompmsuspend(vm.name, 'mem')
virsh.dompmwakeup(vm.name)
virsh.save(vm.name, save_path)
virsh.restore(save_path)
virsh.dompmsuspend(vm.name, 'mem')
virsh.save(vm.name, save_path)
virsh.destroy(vm.name)
finally:
vm_xml_backup.sync()
开发者ID:balamuruhans,项目名称:tp-libvirt,代码行数:24,代码来源:crash_regression.py
示例11: save_restore_hook
def save_restore_hook():
"""
Do save/restore operation and check the results.
"""
hook_para = "%s %s" % (hook_file, vm_name)
save_file = os.path.join(test.tmpdir,
"%s.save" % vm_name)
disk_src = vm.get_first_disk_devices()['source']
if domainxml_test:
disk_dist = "/tmp/%s.move" % vm_name
shutil.copy(disk_src, disk_dist)
script = (hook_script %
(vm_name, disk_src, disk_dist))
prepare_hook_file(script)
elif basic_test:
prepare_hook_file(hook_script %
(vm_name, hook_log))
ret = virsh.save(vm_name, save_file, **virsh_dargs)
libvirt.check_exit_status(ret)
if domainxml_test:
disk_src_save = vm.get_first_disk_devices()['source']
if disk_src != disk_src_save:
raise error.TestFail("Failed to check hooks for"
" save operation")
ret = virsh.restore(save_file, **virsh_dargs)
libvirt.check_exit_status(ret)
if os.path.exists(save_file):
os.remove(save_file)
if domainxml_test:
disk_src_restore = vm.get_first_disk_devices()['source']
if disk_dist != disk_src_restore:
raise error.TestFail("Failed to check hooks for"
" restore operation")
vm.destroy()
if os.path.exists(disk_dist):
os.remove(disk_dist)
vmxml_backup.sync()
if basic_test:
hook_str = hook_para + " restore begin -"
if not check_hooks(hook_str):
raise error.TestFail("Failed to check "
"restore hooks.")
开发者ID:lento-sun,项目名称:tp-libvirt,代码行数:42,代码来源:libvirt_hooks.py
示例12: trigger_events
def trigger_events(dom, events_list=[]):
"""
Trigger various events in events_list
:param dom: the vm objects corresponding to the domain
:return: the expected output that virsh event command prints out
"""
expected_events_list = []
tmpdir = data_dir.get_tmp_dir()
save_path = os.path.join(tmpdir, "%s_event.save" % dom.name)
new_disk = os.path.join(tmpdir, "%s_new_disk.img" % dom.name)
print dom.name
try:
for event in events_list:
if event in ['start', 'restore']:
if dom.is_alive():
dom.destroy()
else:
if not dom.is_alive():
dom.start()
dom.wait_for_login().close()
if event == "start":
virsh.start(dom.name, **virsh_dargs)
expected_events_list.append("'lifecycle' for %s:"
" Started Booted")
dom.wait_for_login().close()
elif event == "save":
virsh.save(dom.name, save_path, **virsh_dargs)
expected_events_list.append("'lifecycle' for %s:"
" Stopped Saved")
elif event == "restore":
if not os.path.exists(save_path):
logging.error("%s not exist", save_path)
else:
virsh.restore(save_path, **virsh_dargs)
expected_events_list.append("'lifecycle' for %s:"
" Started Restored")
elif event == "destroy":
virsh.destroy(dom.name, **virsh_dargs)
expected_events_list.append("'lifecycle' for %s:"
" Stopped Destroyed")
elif event == "reset":
virsh.reset(dom.name, **virsh_dargs)
expected_events_list.append("'reboot' for %s")
elif event == "vcpupin":
virsh.vcpupin(dom.name, '0', '0', **virsh_dargs)
expected_events_list.append("'tunable' for %s:"
"\n\tcputune.vcpupin0: 0")
elif event == "emulatorpin":
virsh.emulatorpin(dom.name, '0', **virsh_dargs)
expected_events_list.append("'tunable' for %s:"
"\n\tcputune.emulatorpin: 0")
elif event == "setmem":
mem_size = int(params.get("mem_size", 512000))
virsh.setmem(dom.name, mem_size, **virsh_dargs)
expected_events_list.append("'balloon-change' for %s:")
elif event == "detach-disk":
if not os.path.exists(new_disk):
open(new_disk, 'a').close()
# Attach disk firstly, this event will not be catched
virsh.attach_disk(dom.name, new_disk, 'vdb', **virsh_dargs)
virsh.detach_disk(dom.name, 'vdb', **virsh_dargs)
expected_events_list.append("'device-removed' for %s:"
" virtio-disk1")
else:
raise error.TestError("Unsupported event: %s" % event)
# Event may not received immediately
time.sleep(3)
finally:
if os.path.exists(save_path):
os.unlink(save_path)
if os.path.exists(new_disk):
os.unlink(new_disk)
return [(dom.name, event) for event in expected_events_list]
开发者ID:lento-sun,项目名称:tp-libvirt,代码行数:74,代码来源:virsh_event.py
示例13: set_condition
def set_condition(vm_name, condn, reset=False, guestbt=None):
"""
Set domain to given state or reset it.
"""
bt = None
if not reset:
if condn == "avocadotest":
bt = utils_test.run_avocado_bg(vm, params, test)
if not bt:
test.cancel("guest stress failed to start")
# Allow stress to start
time.sleep(condn_sleep_sec)
return bt
elif condn == "stress":
utils_test.load_stress("stress_in_vms", params=params, vms=[vm])
elif condn in ["save", "managedsave"]:
# No action
pass
elif condn == "suspend":
result = virsh.suspend(vm_name, ignore_status=True, debug=True)
libvirt.check_exit_status(result)
elif condn == "hotplug":
result = virsh.setvcpus(vm_name, max_vcpu, "--live",
ignore_status=True, debug=True)
libvirt.check_exit_status(result)
exp_vcpu = {'max_config': max_vcpu, 'max_live': max_vcpu,
'cur_config': current_vcpu, 'cur_live': max_vcpu,
'guest_live': max_vcpu}
result = utils_hotplug.check_vcpu_value(vm, exp_vcpu,
option="--live")
elif condn == "host_smt":
if cpu.get_cpu_arch() == 'power9':
result = process.run("ppc64_cpu --smt=4", shell=True)
else:
test.cancel("Host SMT changes not allowed during guest live")
else:
logging.debug("No operation for the domain")
else:
if condn == "save":
save_file = os.path.join(data_dir.get_tmp_dir(), vm_name + ".save")
result = virsh.save(vm_name, save_file,
ignore_status=True, debug=True)
libvirt.check_exit_status(result)
time.sleep(condn_sleep_sec)
if os.path.exists(save_file):
result = virsh.restore(save_file, ignore_status=True,
debug=True)
libvirt.check_exit_status(result)
os.remove(save_file)
else:
test.error("No save file for domain restore")
elif condn == "managedsave":
result = virsh.managedsave(vm_name,
ignore_status=True, debug=True)
libvirt.check_exit_status(result)
time.sleep(condn_sleep_sec)
result = virsh.start(vm_name, ignore_status=True, debug=True)
libvirt.check_exit_status(result)
elif condn == "suspend":
result = virsh.resume(vm_name, ignore_status=True, debug=True)
libvirt.check_exit_status(result)
elif condn == "avocadotest":
guestbt.join(ignore_status=True)
elif condn == "stress":
utils_test.unload_stress("stress_in_vms", params=params, vms=[vm])
elif condn == "hotplug":
result = virsh.setvcpus(vm_name, current_vcpu, "--live",
ignore_status=True, debug=True)
libvirt.check_exit_status(result)
exp_vcpu = {'max_config': max_vcpu, 'max_live': current_vcpu,
'cur_config': current_vcpu, 'cur_live': current_vcpu,
'guest_live': current_vcpu}
result = utils_hotplug.check_vcpu_value(vm, exp_vcpu,
option="--live")
elif condn == "host_smt":
result = process.run("ppc64_cpu --smt=2", shell=True)
# Change back the host smt
result = process.run("ppc64_cpu --smt=4", shell=True)
# Work around due to known cgroup issue after cpu hot(un)plug
# sequence
root_cpuset_path = utils_cgroup.get_cgroup_mountpoint("cpuset")
machine_cpuset_paths = []
if os.path.isdir(os.path.join(root_cpuset_path,
"machine.slice")):
machine_cpuset_paths.append(os.path.join(root_cpuset_path,
"machine.slice"))
if os.path.isdir(os.path.join(root_cpuset_path, "machine")):
machine_cpuset_paths.append(os.path.join(root_cpuset_path,
"machine"))
if not machine_cpuset_paths:
logging.warning("cgroup cpuset might not recover properly "
"for guests after host smt changes, "
"restore it manually")
root_cpuset_cpus = os.path.join(root_cpuset_path, "cpuset.cpus")
for path in machine_cpuset_paths:
machine_cpuset_cpus = os.path.join(path, "cpuset.cpus")
# check if file content differs
cmd = "diff %s %s" % (root_cpuset_cpus,
machine_cpuset_cpus)
#.........这里部分代码省略.........
开发者ID:balamuruhans,项目名称:tp-libvirt,代码行数:101,代码来源:guestpin.py
示例14: trigger_events
def trigger_events(events_list=[]):
"""
Trigger various events in events_list
"""
expected_events_list = []
tmpdir = data_dir.get_tmp_dir()
save_path = os.path.join(tmpdir, "vm_event.save")
new_disk = os.path.join(tmpdir, "new_disk.img")
try:
for event in events_list:
if event in ["start", "restore"]:
if vm.is_alive():
vm.destroy()
else:
if not vm.is_alive():
vm.start()
vm.wait_for_login().close()
if event == "start":
virsh.start(vm_name, **virsh_dargs)
expected_events_list.append("'lifecycle' for %s:" " Started Booted")
vm.wait_for_login().close()
elif event == "save":
virsh.save(vm_name, save_path, **virsh_dargs)
expected_events_list.append("'lifecycle' for %s:" " Stopped Saved")
elif event == "restore":
if not os.path.exists(save_path):
logging.error("%s not exist", save_path)
else:
virsh.restore(save_path, **virsh_dargs)
expected_events_list.append("'lifecycle' for %s:" " Started Restored")
elif event == "destroy":
virsh.destroy(vm_name, **virsh_dargs)
expected_events_list.append("'lifecycle' for %s:" " Stopped Destroyed")
elif event == "reset":
virsh.reset(vm_name, **virsh_dargs)
expected_events_list.append("'reboot' for %s")
elif event == "vcpupin":
virsh.vcpupin(vm_name, "0", "0", **virsh_dargs)
expected_events_list.append("'tunable' for %s:" "\n\tcputune.vcpupin0: 0")
elif event == "emulatorpin":
virsh.emulatorpin(vm_name, "0", **virsh_dargs)
expected_events_list.append("'tunable' for %s:" "\n\tcputune.emulatorpin: 0")
elif event == "setmem":
virsh.setmem(vm_name, 1048576, **virsh_dargs)
expected_events_list.append("'balloon-change' for %s:")
elif event == "detach-disk":
if not os.path.exists(new_disk):
open(new_disk, "a").close()
# Attach disk firstly, this event will not be catched
virsh.attach_disk(vm_name, new_disk, "vdb", **virsh_dargs)
virsh.detach_disk(vm_name, "vdb", **virsh_dargs)
expected_events_list.append("'device-removed' for %s:" " virtio-disk1")
else:
raise error.TestError("Unsupported event: %s" % event)
# Event may not received immediately
time.sleep(3)
finally:
if os.path.exists(save_path):
os.unlink(save_path)
if os.path.exists(new_disk):
os.unlink(new_disk)
return expected_events_list
开发者ID:OnePaaS,项目名称:tp-libvirt,代码行数:62,代码来源:virsh_event.py
示例15: edit_image_xml
# Process cartesian parameters
vm_name = params.get("main_vm")
vm = env.get_vm(vm_name)
vm.wait_for_login()
restore_state = params.get("restore_state", "running")
vm_save = params.get("vm_save", "vm.save")
try:
# Get a tmp_dir.
tmp_dir = data_dir.get_tmp_dir()
if os.path.dirname(vm_save) is "":
vm_save = os.path.join(tmp_dir, vm_save)
# Save the RAM state of a running domain
cmd_result = virsh.save(vm_name, vm_save, debug=True)
if cmd_result.exit_status:
raise error.TestFail("Failed to save running domain %s" % vm_name)
# Edit the xml in the saved state file
edit_image_xml()
# Restore domain
cmd_result = virsh.restore(vm_save, debug=True)
if cmd_result.exit_status:
raise error.TestFail("Failed to restore domain %s" % vm_name)
os.remove(vm_save)
vm_state_check()
finally:
开发者ID:Acidburn0zzz,项目名称:tp-libvirt,代码行数:31,代码来源:virsh_save_image_edit.py
示例16: run
def run(test, params, env):
"""
Test command: virsh dompmsuspend <domain> <target>
The command suspends a running domain using guest OS's power management.
"""
# MAIN TEST CODE ###
# Process cartesian parameters
vm_name = params.get("main_vm")
vm = env.get_vm(vm_name)
vm_state = params.get("vm_state", "running")
suspend_target = params.get("pm_suspend_target", "mem")
pm_enabled = params.get("pm_enabled", "not_set")
test_managedsave = "yes" == params.get("test_managedsave", "no")
test_save_restore = "yes" == params.get("test_save_restore", "no")
test_suspend_resume = "yes" == params.get("test_suspend_resume", "no")
pmsuspend_error = 'yes' == params.get("pmsuspend_error", 'no')
# Libvirt acl test related params
uri = params.get("virsh_uri")
unprivileged_user = params.get('unprivileged_user')
if unprivileged_user:
if unprivileged_user.count('EXAMPLE'):
unprivileged_user = 'testacl'
if not libvirt_version.version_compare(1, 1, 1):
if params.get('setup_libvirt_polkit') == 'yes':
raise error.TestNAError("API acl test not supported in current"
" libvirt version.")
# A backup of original vm
vmxml = vm_xml.VMXML.new_from_inactive_dumpxml(vm_name)
vmxml_backup = vmxml.copy()
# Expected possible fail patterns.
# Error output should match one of these patterns.
# An empty list mean test should succeed.
fail_pat = []
virsh_dargs = {'debug': True, 'ignore_status': True}
if params.get('setup_libvirt_polkit') == 'yes':
virsh_dargs_copy = virsh_dargs.copy()
virsh_dargs_copy['uri'] = uri
virsh_dargs_copy['unprivileged_user'] = unprivileged_user
if pmsuspend_error:
fail_pat.append('access denied')
# Setup possible failure patterns
if pm_enabled == 'not_set':
fail_pat.append('not supported')
if pm_enabled == 'no':
fail_pat.append('disabled')
if vm_state == 'paused':
fail_pat.append('not responding')
elif vm_state == 'shutoff':
fail_pat.append('not running')
try:
if vm.is_alive():
vm.destroy()
# Set pm tag in domain's XML if needed.
if pm_enabled == 'not_set':
try:
if vmxml.pm:
del vmxml.pm
except xcepts.LibvirtXMLNotFoundError:
pass
else:
pm_xml = vm_xml.VMPMXML()
if suspend_target == 'mem':
pm_xml.mem_enabled = pm_enabled
elif suspend_target == 'disk':
pm_xml.disk_enabled = pm_enabled
elif suspend_target == 'hybrid':
pm_xml.mem_enabled = pm_enabled
pm_xml.disk_enabled = pm_enabled
vmxml.pm = pm_xml
vmxml.sync()
vm.prepare_guest_agent()
# Create swap partition/file if nessesary.
need_mkswap = False
if suspend_target in ['disk', 'hybrid']:
need_mkswap = not vm.has_swap()
if need_mkswap:
logging.debug("Creating swap partition.")
vm.create_swap_partition()
try:
libvirtd = utils_libvirtd.Libvirtd()
savefile = os.path.join(test.tmpdir, "%s.save" % vm_name)
session = vm.wait_for_login()
# Touch a file on guest to test managed save command.
if test_managedsave:
session.cmd_status("touch pmtest")
# Set vm state
#.........这里部分代码省略.........
开发者ID:Chenditang,项目名称:tp-libvirt,代码行数:101,代码来源:virsh_dompmsuspend.py
示例17: int
logging.info("Trying to suspend/resume vm %s times", paused_times)
while paused_times > 0:
paused_times -= 1
try:
virsh.suspend(vm.name, debug=True, ignore_status=False)
virsh.resume(vm.name, debug=True, ignore_status=False)
except error.CmdError, detail:
err_msg = "Suspend-Resume %s failed: %s" % (vm.name, detail)
elif operation == "save_restore":
save_times = int(params.get("save_times", 10))
logging.info("Trying to save/restore vm %s times", save_times)
while save_times > 0:
save_times -= 1
save_path = os.path.join(data_dir.get_tmp_dir(), "save.file")
try:
virsh.save(vm.name, save_path, debug=True,
ignore_status=False)
virsh.restore(save_path, debug=True, ignore_status=False)
except error.CmdError, detail:
err_msg = "Save-Restore %s failed: %s" % (vm.name, detail)
try:
os.remove(save_path)
except OSError:
pass
else:
err_msg = "Unsupport operation in this function: %s" % operation
return err_msg
def translate_timer_name(timer_name):
"""
Translate timer name in XML to clock source name in VM.
开发者ID:Antique,项目名称:tp-libvirt,代码行数:32,代码来源:timer_management.py
示例18: run_virsh_domjobinfo
def run_virsh_domjobinfo(test, params, env):
"""
Test command: virsh domjobinfo.
The command returns information about jobs running on a domain.
1.Prepare test environment.
2.When the libvirtd == "off", stop the libvirtd service.
3.Perform virsh domjobinfo operation.
4.Recover test environment.
5.Confirm the test result.
"""
vm_name = params.get("main_vm")
vm = env.get_vm(vm_name)
domid = vm.get_id()
domuuid = vm.get_uuid()
pre_vm_state = params.get("domjobinfo_pre_vm_state", "null")
vm_ref = params.get("domjobinfo_vm_ref")
status_error = params.get("status_error", "no")
libvirtd = params.get("libvirtd", "on")
tmp_file = os.path.join(test.tmpdir, '%s.tmp' % vm_name )
#prepare the state of vm
if pre_vm_state == "dump":
virsh.dump(vm_name, tmp_file)
elif pre_vm_state == "save":
virsh.save(vm_name, tmp_file)
elif pre_vm_state == "restore":
virsh.save(vm_name, tmp_file)
virsh.restore(tmp_file)
elif pre_vm_state == "managedsave":
virsh.managedsave(vm_name)
#run test case
if vm_ref == "id":
vm_ref = domid
elif vm_ref == "hex_id":
vm_ref = hex(int(domid))
elif vm_ref == "name":
vm_ref = "%s %s" % (vm_name, params.get("domjobinfo_extra"))
elif vm_ref == "uuid":
vm_ref = domuuid
elif vm_ref.find("invalid") != -1:
vm_ref = params.get(vm_ref)
if libvirtd == "off":
utils_libvirtd.libvirtd_stop()
status = virsh.domjobinfo(vm_ref, ignore_status=True).exit_status
#recover libvirtd service start
if libvirtd == "off":
utils_libvirtd.libvirtd_start()
#check status_error
if status_error == "yes":
if status == 0:
raise error.TestFail("Run successfully with wrong command!")
elif status_error == "no":
if status != 0:
raise error.TestFail("Run failed with right command")
开发者ID:LeiCui,项目名称:virt-test,代码行数:62,代码来源:virsh_domjobinfo.py
示例19: run
def run(test, params, env):
"""
Test command: virsh domjobabort.
The command can abort the currently running domain job.
1.Prepare test environment,destroy or suspend a VM.
2.Do action to get a subprocess(dump, save, managedsave).
3.Perform virsh domjobabort operation to abort VM's job.
4.Recover the VM's status and wait for the subprocess over.
5.Confirm the test result.
"""
vm_name = params.get("main_vm", "vm1")
vm = env.get_vm(vm_name)
start_vm = params.get("start_vm")
pre_vm_state = params.get("pre_vm_state", "start")
if start_vm == "no" and vm.is_alive():
vm.destroy()
# Instead of "paused_after_start_vm", use "pre_vm_state".
# After start the VM, wait for some time to make sure the job
# can be created on this domain.
if start_vm == "yes":
vm.wait_for_login()
if params.get("pre_vm_state") == "suspend":
vm.pause()
domid = vm.get_id()
domuuid = vm.get_uuid()
original_speed = virsh.migrate_getspeed(vm_name).stdout.strip()
def get_subprocess(action, vm_name, file, remote_uri=None):
"""
Execute background virsh command, return subprocess w/o waiting for exit()
:param cmd : virsh command.
:param guest_name : VM's name
:param file_source : virsh command's file option.
"""
if action == "managedsave":
file = ""
elif action == "migrate":
# Slow down migration for domjobabort
virsh.migrate_setspeed(vm_name, "1")
file = remote_uri
command = "virsh %s %s %s --unsafe" % (action, vm_name, file)
logging.debug("Action: %s", command)
p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
return p
action = params.get("jobabort_action", "dump")
status_error = params.get("status_error", "no")
job = params.get("jobabort_job", "yes")
tmp_file = os.path.join(test.tmpdir, "domjobabort.tmp")
tmp_pipe = os.path.join(test.tmpdir, "domjobabort.fifo")
vm_ref = params.get("jobabort_vm_ref")
remote_uri = params.get("jobabort_remote_uri")
remote_host = params.get("migrate_dest_host")
remote_user = params.get("migrate_dest_user", "root")
remote_pwd = params.get("migrate_dest_pwd")
saved_data = None
if action == "managedsave":
tmp_pipe = '/var/lib/libvirt/qemu/save/%s.save' % vm.name
if action == "restore":
virsh.save(vm_name, tmp_file, ignore_status=True)
if action == "migrate":
if remote_host.count("EXAMPLE"):
raise error.TestNAError("Remote host should be configured "
"for migrate.")
else:
# Config ssh autologin for remote host
ssh_key.setup_ssh_key(remote_host, remote_user,
remote_pwd, port=22)
if vm_ref == "id":
vm_ref = domid
elif vm_ref == "hex_id":
vm_ref = hex(int(domid))
elif vm_ref == "uuid":
vm_ref = domuuid
elif vm_ref.find("invalid") != -1:
vm_ref = params.get(vm_ref)
elif vm_ref == "name":
vm_ref = vm_name
# Get the subprocess of VM.
# The command's effect is to abort the currently running domain job.
# So before do "domjobabort" action, we must create a job on the domain.
process = None
if job == "yes" and start_vm == "yes" and status_error == "no":
if os.path.exists(tmp_pipe):
os.unlink(tmp_pipe)
os.mkfifo(tmp_pipe)
process = get_subprocess(action, vm_name, tmp_pipe, remote_uri)
#.........这里部分代码省略.........
开发者ID:zcyes,项目名称:tp |
请发表评论