本文整理汇总了Python中virttest.virsh.save函数的典型用法代码示例。如果您正苦于以下问题:Python save函数的具体用法?Python save怎么用?Python save使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了save函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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)
示例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()
示例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))
示例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)
示例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)
示例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)
示例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()
示例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")
示例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()
示例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.")
示例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]
示例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)
#.........这里部分代码省略.........
示例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
示例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: