本文整理汇总了Python中virttest.virsh.snapshot_list函数的典型用法代码示例。如果您正苦于以下问题:Python snapshot_list函数的具体用法?Python snapshot_list怎么用?Python snapshot_list使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了snapshot_list函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: check_snapshot
def check_snapshot(bgjob=None):
"""
Do snapshot operation and check the results
"""
snapshot_name1 = "snap.s1"
snapshot_name2 = "snap.s2"
if not snapshot_vm_running:
vm.destroy(gracefully=False)
ret = virsh.snapshot_create_as(vm_name, snapshot_name1)
libvirt.check_exit_status(ret)
snap_lists = virsh.snapshot_list(vm_name)
if snapshot_name not in snap_lists:
test.fail("Snapshot %s doesn't exist"
% snapshot_name)
if snapshot_vm_running:
options = "--force"
else:
options = ""
ret = virsh.snapshot_revert(
vm_name, ("%s %s" % (snapshot_name, options)))
libvirt.check_exit_status(ret)
ret = virsh.dumpxml(vm_name)
if ret.stdout.count("<rng model="):
test.fail("Found rng device in xml")
if snapshot_with_rng:
if vm.is_alive():
vm.destroy(gracefully=False)
if bgjob:
bgjob.kill_func()
modify_rng_xml(params, False)
# Start the domain before disk-only snapshot
if vm.is_dead():
# Add random server
if params.get("backend_type") == "tcp":
cmd = "cat /dev/random | nc -4 -l localhost 1024"
bgjob = utils.AsyncJob(cmd)
vm.start()
vm.wait_for_login().close()
err_msgs = ("live disk snapshot not supported"
" with this QEMU binary")
ret = virsh.snapshot_create_as(vm_name,
"%s --disk-only"
% snapshot_name2)
if ret.exit_status:
if ret.stderr.count(err_msgs):
test.skip(err_msgs)
else:
test.fail("Failed to create external snapshot")
snap_lists = virsh.snapshot_list(vm_name)
if snapshot_name2 not in snap_lists:
test.fail("Failed to check snapshot list")
ret = virsh.domblklist(vm_name)
if not ret.stdout.count(snapshot_name2):
test.fail("Failed to find snapshot disk")
开发者ID:lento-sun,项目名称:tp-libvirt,代码行数:58,代码来源:libvirt_rng.py
示例2: clean_up_snapshots
def clean_up_snapshots(vm_name, snapshot_list=[]):
"""
Do recovery after snapshot
:param vm_name: Name of domain
:param snapshot_list: The list of snapshot name you want to remove
"""
if not snapshot_list:
# Get all snapshot names from virsh snapshot-list
snapshot_list = virsh.snapshot_list(vm_name)
# Get snapshot disk path
for snap_name in snapshot_list:
# Delete useless disk snapshot file if exists
snap_xml = virsh.snapshot_dumpxml(vm_name,
snap_name).stdout.strip()
xtf_xml = xml_utils.XMLTreeFile(snap_xml)
disks_path = xtf_xml.findall('disks/disk/source')
for disk in disks_path:
os.system('rm -f %s' % disk.get('file'))
# Delete snapshots of vm
virsh.snapshot_delete(vm_name, snap_name)
else:
# Get snapshot disk path from domain xml because
# there is no snapshot info with the name
dom_xml = vm_xml.VMXML.new_from_dumpxml(vm_name).xmltreefile
disk_path = dom_xml.find('devices/disk/source').get('file')
for name in snapshot_list:
snap_disk_path = disk_path.split(".")[0] + "." + name
os.system('rm -f %s' % snap_disk_path)
开发者ID:hinesmr,项目名称:virt-test,代码行数:30,代码来源:libvirt.py
示例3: remove_snapshots
def remove_snapshots(vm):
remove_failed = 0
snaps = virsh.snapshot_list(vm)
for snap in snaps:
try:
virsh.snapshot_delete(vm,snap)
except error.CmdError:
remove_failed = remove_failed + 1
return remove_failed
开发者ID:HeidCloud,项目名称:virt-test,代码行数:10,代码来源:virsh_snapshot.py
示例4: remove_snapshots
def remove_snapshots(vm):
remove_failed = 0
snaps = virsh.snapshot_list(vm)
for snap in snaps:
try:
virsh.snapshot_delete(vm, snap)
except error.CmdError:
logging.debug("Can not remove snapshot %s.", snaps)
remove_failed = remove_failed + 1
return remove_failed
开发者ID:Acidburn0zzz,项目名称:tp-libvirt,代码行数:11,代码来源:virsh_snapshot.py
示例5: 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
示例6: result_confirm
def result_confirm(self, params):
"""
Confirm if snapshot has been created.
"""
if 'cpu_pid' in params:
cpu_id = params.get('cpu_pid')
self.cgroup.cgclassify_cgroup(int(cpu_id), self.cgroup_name)
if self.kill_first:
# Stop this threading
try:
first_pid = self.cgroup.get_pids(self.cgroup_index)[1]
utils_misc.safe_kill(int(first_pid), signal.SIGKILL)
except IndexError:
logging.info("Snapshot create process in cgroup"
" has been over")
else:
if self.td1:
self.td1.join(self.time_out)
self.td0.join(self.time_out)
self.current_snp_list = virsh.snapshot_list(self.vm_name)
if len(self.snp_list) >= len(self.current_snp_list):
self.test.fail("Create snapshot failed for low memory!")
开发者ID:balamuruhans,项目名称:tp-libvirt,代码行数:22,代码来源:resource_abnormal.py
示例7: __init__
def __init__(self, test, params):
self.cpu_num = int(params.get("cpu_num", "1"))
self.cgroup_name = params.get("cgroup_name")
self.cgroup_dir = params.get("cgroup_dir")
self.time_out = int(params.get("time_out", "600"))
self.vm_name = params.get("main_vm")
self.time_out = int(params.get("time_out", "600"))
self.twice_execute = "yes" == params.get("twice_execute", "no")
self.kill_first = "yes" == params.get("kill_first", "no")
xml_file = vm_xml.VMXML.new_from_inactive_dumpxml(self.vm_name)
disk_node = xml_file.get_disk_all()['vda']
source_file = disk_node.find('source').get('file')
image_type = utils_misc.get_image_info(source_file)['format']
if image_type != "qcow2":
raise error.TestNAError("Disk image format is not qcow2, "
"ignore snapshot test!")
self.cpu_status = utils_misc.get_cpu_status(self.cpu_num)
self.current_snp_list = []
self.snp_list = virsh.snapshot_list(self.vm_name)
env = params.get("env")
vm = env.get_vm(self.vm_name)
# This can add snapshot create time
vm.wait_for_login()
开发者ID:noxdafox,项目名称:tp-libvirt,代码行数:23,代码来源:resource_abnormal.py
示例8: run
def run(test, params, env):
"""
Test command: virsh blockcommit <domain> <path>
1) Prepare test environment.
2) Commit changes from a snapshot down to its backing image.
3) Recover test environment.
4) Check result.
"""
def make_disk_snapshot():
# Add all disks into commandline.
disks = vm.get_disk_devices()
# Make three external snapshots for disks only
for count in range(1, 4):
options = "snapshot%s snap%s-desc " \
"--disk-only --atomic --no-metadata" % (count, count)
for disk in disks:
disk_detail = disks[disk]
basename = os.path.basename(disk_detail['source'])
# Remove the original suffix if any, appending ".snap[0-9]"
diskname = basename.split(".")[0]
disk_external = os.path.join(tmp_dir,
"%s.snap%s" % (diskname, count))
snapshot_external_disks.append(disk_external)
options += " %s,snapshot=external,file=%s" % (disk,
disk_external)
cmd_result = virsh.snapshot_create_as(vm_name, options,
ignore_status=True,
debug=True)
status = cmd_result.exit_status
if status != 0:
raise error.TestFail("Failed to make snapshots for disks!")
# Create a file flag in VM after each snapshot
flag_file = tempfile.NamedTemporaryFile(prefix=("snapshot_test_"),
dir="/tmp")
file_path = flag_file.name
flag_file.close()
status, output = session.cmd_status_output("touch %s" % file_path)
if status:
raise error.TestFail("Touch file in vm failed. %s" % output)
snapshot_flag_files.append(file_path)
# MAIN TEST CODE ###
# Process cartesian parameters
vm_name = params.get("main_vm")
vm = env.get_vm(vm_name)
session = vm.wait_for_login()
top_inactive = ("yes" == params.get("top_inactive"))
with_timeout = ("yes" == params.get("with_timeout_option", "no"))
status_error = ("yes" == params.get("status_error", "no"))
base_option = params.get("base_option", "none")
middle_base = "yes" == params.get("middle_base", "no")
virsh_dargs = {'debug': True}
# A backup of original vm
vmxml_backup = vm_xml.VMXML.new_from_inactive_dumpxml(vm_name)
logging.debug("original xml is %s", vmxml_backup)
# Abort the test if there are snapshots already
exsiting_snaps = virsh.snapshot_list(vm_name)
if len(exsiting_snaps) != 0:
raise error.TestFail("There are snapshots created for %s already" %
vm_name)
try:
# Get a tmp_dir.
tmp_dir = data_dir.get_tmp_dir()
# The first disk is supposed to include OS
# We will perform blockcommit operation for it.
first_disk = vm.get_first_disk_devices()
snapshot_external_disks = []
snapshot_flag_files = []
make_disk_snapshot()
top_image = None
base_image = None
blockcommit_options = "--wait --verbose"
basename = os.path.basename(first_disk['source'])
diskname = basename.split(".")[0]
if with_timeout:
blockcommit_options += " --timeout 1"
if base_option == "shallow":
blockcommit_options += " --shallow"
elif base_option == "base":
if middle_base:
base_image = os.path.join(tmp_dir, "%s.snap1" %
diskname)
#.........这里部分代码省略.........
开发者ID:Acidburn0zzz,项目名称:tp-libvirt,代码行数:101,代码来源:virsh_blockcommit.py
示例9: run
#.........这里部分代码省略.........
disk_params.update(disk_params_auth)
disk_xml = libvirt.create_disk_xml(disk_params)
attach_option = params.get("attach_option", "")
cmd_result = virsh.attach_device(domainarg=vm_name, filearg=disk_xml,
flagstr=attach_option,
dargs=virsh_dargs)
libvirt.check_exit_status(cmd_result, status_error)
if vm.is_dead():
cmd_result = virsh.start(vm_name, **virsh_dargs)
libvirt.check_exit_status(cmd_result)
# Wait for domain is stable
vm.wait_for_login().close()
domain_operation = params.get("domain_operation", "")
if domain_operation == "save":
save_file = os.path.join(data_dir.get_tmp_dir(), "vm.save")
cmd_result = virsh.save(vm_name, save_file, **virsh_dargs)
libvirt.check_exit_status(cmd_result)
cmd_result = virsh.restore(save_file)
libvirt.check_exit_status(cmd_result)
if os.path.exists(save_file):
os.remove(save_file)
elif domain_operation == "snapshot":
# Run snapshot related commands: snapshot-create-as, snapshot-list
# snapshot-info, snapshot-dumpxml, snapshot-create
snapshot_name1 = "snap1"
snapshot_name2 = "snap2"
cmd_result = virsh.snapshot_create_as(vm_name, snapshot_name1,
**virsh_dargs)
libvirt.check_exit_status(cmd_result)
try:
virsh.snapshot_list(vm_name, **virsh_dargs)
except process.CmdError:
test.fail("Failed getting snapshots list for %s" % vm_name)
try:
virsh.snapshot_info(vm_name, snapshot_name1, **virsh_dargs)
except process.CmdError:
test.fail("Failed getting snapshots info for %s" % vm_name)
cmd_result = virsh.snapshot_dumpxml(vm_name, snapshot_name1,
**virsh_dargs)
libvirt.check_exit_status(cmd_result)
cmd_result = virsh.snapshot_create(vm_name, **virsh_dargs)
libvirt.check_exit_status(cmd_result)
cmd_result = virsh.snapshot_current(vm_name, **virsh_dargs)
libvirt.check_exit_status(cmd_result)
snapshot_file = os.path.join(data_dir.get_tmp_dir(), snapshot_name2)
sn_create_op = ("%s --disk-only --diskspec %s,file=%s"
% (snapshot_name2, disk_target, snapshot_file))
cmd_result = virsh.snapshot_create_as(vm_name, sn_create_op,
**virsh_dargs)
libvirt.check_exit_status(cmd_result)
cmd_result = virsh.snapshot_revert(vm_name, snapshot_name1,
**virsh_dargs)
cmd_result = virsh.snapshot_list(vm_name, **virsh_dargs)
if snapshot_name2 not in cmd_result:
test.error("Snapshot %s not found" % snapshot_name2)
elif domain_operation == "":
开发者ID:nasastry,项目名称:tp-libvirt,代码行数:67,代码来源:at_dt_iscsi_disk.py
示例10: run
#.........这里部分代码省略.........
logging.info("Succeed to check the xml for description and name")
else:
# Print just the differences rather than printing both
# files and forcing the eyeball comparison between lines
elems = list(map(None, pre_xml.splitlines(), after_xml.splitlines()))
for pre_line, aft_line in elems:
if pre_line.lstrip().strip() != aft_line.lstrip().strip():
if pre_line is not None:
logging.debug("diff before='%s'",
pre_line.lstrip().strip())
if aft_line is not None:
logging.debug("diff after='%s'",
aft_line.lstrip().strip())
test.fail("Failed xml before/after comparison")
snapshot_oldlist = None
try:
# Create disk snapshot before all to make the origin image clean
logging.debug("Create snap-temp --disk-only")
ret = virsh.snapshot_create_as(vm_name, "snap-temp --disk-only")
if ret.exit_status != 0:
test.fail("Fail to create temp snap, Error: %s"
% ret.stderr.strip())
# Create snapshots
for opt in [snap_create_opt1, snap_create_opt2]:
logging.debug("...use option %s", opt)
result = virsh.snapshot_create_as(vm_name, opt)
if result.exit_status:
test.fail("Failed to create snapshot. Error:%s."
% result.stderr.strip())
time.sleep(1)
snapshot_oldlist = virsh.snapshot_list(vm_name)
# Get the snapshot xml before edit
if len(snap_name) > 0:
pre_name = check_name = snap_name
else:
cmd_result = virsh.snapshot_current(vm_name)
pre_name = check_name = cmd_result.stdout.strip()
ret = virsh.snapshot_dumpxml(vm_name, pre_name)
if ret.exit_status == 0:
pre_xml = ret.stdout.strip()
else:
test.fail("Fail to dumpxml of snapshot %s:%s" %
(pre_name, ret.stderr.strip()))
edit_cmd = []
replace_cmd = '%s<\/name>/%s<\/name>' % (pre_name, pre_name)
replace_cmd += '\\r<description>%s<\/description>' % snap_desc
replace_cmd = ":%s/" + replace_cmd + "/"
edit_cmd.append(replace_cmd)
# if have --clone or --rename, need to change snapshot name in xml
if len(snap_opt) > 0:
edit_cmd.append(":2")
edit_cmd.append(":s/<name>.*</<name>" + snap_newname + "<")
check_name = snap_newname
edit_opts = " " + snap_name + " " + snap_cur + " " + snap_opt
# Do snapshot edit
if status_error == "yes":
output = virsh.snapshot_edit(vm_name, edit_opts)
if output.exit_status == 0:
test.fail("Succeed to do the snapshot-edit but"
开发者ID:nasastry,项目名称:tp-libvirt,代码行数:67,代码来源:virsh_snapshot_edit.py
示例11: run
#.........这里部分代码省略.........
vm.destroy(gracefully=False)
new_disk = disk.Disk()
new_disk.xml = open(utlv.create_disk_xml(disk_params)).read()
# start vm with the virtual disk
vmxml.devices = vmxml.devices.append(new_disk)
vmxml.sync()
vm.start()
session = vm.wait_for_login()
cur_disks = virt_vm.get_disks()
mount_disk = "".join(list(set(old_disks) ^ set(cur_disks)))
# mkfs and mount disk in vm, create a file on that disk.
if not mount_disk:
logging.debug("old_disk: %s, new_disk: %s", old_disks, cur_disks)
raise exceptions.TestFail("No new disk found in vm.")
mkfs_and_mount(session, mount_disk)
create_file_in_vm(session, "/mnt/before_snapshot.txt", "before")
# virsh snapshot-create-as vm s --disk-only --diskspec vda,file=path
if snapshot_disk_only:
vm_blks = list(vm.get_disk_devices().keys())
options = "%s --disk-only" % snapshot_name
for vm_blk in vm_blks:
snapshot_file = snapshot_dir + "/" + vm_blk + "." + snapshot_name
if os.path.exists(snapshot_file):
os.remove(snapshot_file)
options = options + " --diskspec %s,file=%s" % (vm_blk,
snapshot_file)
else:
options = snapshot_name
utlv.check_exit_status(virsh.snapshot_create_as(vm_name, options))
# check virsh snapshot-list
logging.debug("Running: snapshot-list %s", vm_name)
snapshot_list = virsh.snapshot_list(vm_name)
logging.debug("snapshot list is: %s", snapshot_list)
if not snapshot_list:
raise exceptions.TestFail("snapshots not found after creation.")
# snapshot-revert doesn't support external snapshot for now. so
# only check this with internal snapshot.
if not snapshot_disk_only:
create_file_in_vm(session, "/mnt/after_snapshot.txt", "after")
logging.debug("Running: snapshot-revert %s %s",
vm_name, snapshot_name)
utlv.check_exit_status(virsh.snapshot_revert(vm_name, snapshot_name))
session = vm.wait_for_login()
file_existence, file_content = get_file_in_vm(session,
"/mnt/after_snapshot.txt")
logging.debug("file exist = %s, file content = %s",
file_existence, file_content)
if file_existence:
raise exceptions.TestFail("The file created "
"after snapshot still exists.")
file_existence, file_content = get_file_in_vm(session,
"/mnt/before_snapshot.txt")
logging.debug("file eixst = %s, file content = %s",
file_existence, file_content)
if ((not file_existence) or (file_content.strip() != "before")):
raise exceptions.TestFail("The file created "
"before snapshot is lost.")
# delete snapshots
# if diskonly, delete --metadata and remove files
# if not diskonly, delete snapshot
if snapshot_disk_only:
options = "--metadata"
else:
options = ""
for snap in snapshot_list:
logging.debug("deleting snapshot %s with options %s",
snap, options)
result = virsh.snapshot_delete(vm_name, snap, options)
logging.debug("result of snapshot-delete: %s",
result.stdout.strip())
if snapshot_disk_only:
vm_blks = list(vm.get_disk_devices().keys())
for vm_blk in vm_blks:
snapshot_file = snapshot_dir + "/" + vm_blk + "." + snap
if os.path.exists(snapshot_file):
os.remove(snapshot_file)
snapshot_list = virsh.snapshot_list(vm_name)
if snapshot_list:
raise exceptions.TestFail("Snapshot not deleted: %s", snapshot_list)
except Exception as detail:
raise exceptions.TestFail("exception happens: %s", detail)
finally:
logging.debug("Start to clean up env...")
vmxml_backup.sync()
if pool_ins and pool_ins.pool_exists(pool_name):
virsh.pool_destroy(pool_name)
for new_vhba in new_vhbas:
virsh.nodedev_destroy(new_vhba)
utils_npiv.restart_multipathd()
if old_mpath_conf:
utils_npiv.prepare_multipath_conf(conf_path=mpath_conf_path,
conf_content=old_mpath_conf,
replace_existing=True)
if not original_mpath_conf_exist and os.path.exists(mpath_conf_path):
os.remove(mpath_conf_path)
开发者ID:balamuruhans,项目名称:tp-libvirt,代码行数:101,代码来源:npiv_snapshot.py
示例12: run
def run(test, params, env):
"""
Test for virt-xml-validate
"""
# Get the full path of virt-xml-validate command.
try:
VIRT_XML_VALIDATE = os_dep.command("virt-xml-validate")
except ValueError:
raise error.TestNAError("Not find virt-xml-validate command on host.")
vm_name = params.get("main_vm", "virt-tests-vm1")
net_name = params.get("net_dumpxml_name", "default")
pool_name = params.get("pool_dumpxml_name", "default")
schema = params.get("schema", "domain")
output = params.get("output_file", "output")
output_path = os.path.join(data_dir.get_tmp_dir(), output)
valid_schemas = [
"domain",
"domainsnapshot",
"network",
"storagepool",
"storagevol",
"nodedev",
"capability",
"nwfilter",
"secret",
"interface",
]
if schema not in valid_schemas:
raise error.TestFail("invalid %s specified" % schema)
virsh_dargs = {"ignore_status": True, "debug": True}
if schema == "domainsnapshot":
domainsnapshot_validate(vm_name, file=output_path, **virsh_dargs)
elif schema == "network":
network_validate(net_name, file=output_path, **virsh_dargs)
elif schema == "storagepool":
storagepool_validate(pool_name, file=output_path, **virsh_dargs)
elif schema == "storagevol":
storagevol_validate(pool_name, file=output_path, **virsh_dargs)
elif schema == "nodedev":
nodedev_validate(file=output_path, **virsh_dargs)
elif schema == "capability":
capability_validate(file=output_path, **virsh_dargs)
elif schema == "nwfilter":
nwfilter_validate(file=output_path, **virsh_dargs)
elif schema == "secret":
secret_validate(file=output_path, **virsh_dargs)
elif schema == "interface":
interface_validate(file=output_path, **virsh_dargs)
else:
# domain
virsh.dumpxml(vm_name, to_file=output_path)
cmd = "%s %s %s" % (VIRT_XML_VALIDATE, output_path, schema)
cmd_result = utils.run(cmd, ignore_status=True)
# Delete snapshots.
snapshot_lists = virsh.snapshot_list(vm_name)
if len(snapshot_lists) > 0:
libvirt.clean_up_snapshots(vm_name, snapshot_lists)
for snapshot in snapshot_lists:
virsh.snapshot_delete(vm_name, snapshot, "--metadata")
if cmd_result.exit_status:
raise error.TestFail("virt-xml-validate command failed.\n" "Detail: %s." % cmd_result)
if cmd_result.stdout.count("fail"):
raise error.TestFail("xml fails to validate\n" "Detail: %s." % cmd_result)
开发者ID:uni-peter-zheng,项目名称:tp-libvirt,代码行数:69,代码来源:virt_xml_validate.py
示例13: check_vm_partitions
if device_attach_error[i] == "yes":
continue
ret = virsh.detach_device(vm_name, disks_xml[i].xml,
flagstr=attach_option)
os.remove(disks_xml[i].xml)
libvirt.check_exit_status(ret)
# Check disks in VM after hotunplug.
if check_patitions_hotunplug:
if not check_vm_partitions(devices,
device_targets, False):
raise error.TestFail("See device in VM after hotunplug")
finally:
# Delete snapshots.
snapshot_lists = virsh.snapshot_list(vm_name)
if len(snapshot_lists) > 0:
libvirt.clean_up_snapshots(vm_name, snapshot_lists)
for snapshot in snapshot_lists:
virsh.snapshot_delete(vm_name, snapshot, "--metadata")
# Recover VM.
if vm.is_alive():
vm.destroy(gracefully=False)
logging.info("Restoring vm...")
virsh.undefine(vm_name)
virsh.define(vm_xml_file)
os.remove(vm_xml_file)
# Restore qemu_config file.
qemu_config.restore()
开发者ID:nertpinx,项目名称:tp-libvirt,代码行数:31,代码来源:virtual_disks_multidisks.py
示例14: run
#.........这里部分代码省略.........
with_timeout = ("yes" == params.get("with_timeout_option", "no"))
status_error = ("yes" == params.get("status_error", "no"))
base_option = params.get("base_option", "none")
middle_base = "yes" == params.get("middle_base", "no")
pivot_opt = "yes" == params.get("pivot_opt", "no")
snap_in_mirror = "yes" == params.get("snap_in_mirror", "no")
snap_in_mirror_err = "yes" == params.get("snap_in_mirror_err", "no")
with_active_commit = "yes" == params.get("with_active_commit", "no")
multiple_chain = "yes" == params.get("multiple_chain", "no")
virsh_dargs = {'debug': True}
# Check whether qemu-img need add -U suboption since locking feature was added afterwards qemu-2.10
qemu_img_locking_feature_support = libvirt_storage.check_qemu_image_lock_support()
backing_file_relative_path = "yes" == params.get("backing_file_relative_path", "no")
# Process domain disk device parameters
disk_type = params.get("disk_type")
disk_src_protocol = params.get("disk_source_protocol")
restart_tgtd = params.get("restart_tgtd", 'no')
vol_name = params.get("vol_name")
tmp_dir = data_dir.get_tmp_dir()
pool_name = params.get("pool_name", "gluster-pool")
brick_path = os.path.join(tmp_dir, pool_name)
if not top_inactive:
if not libvirt_version.version_compare(1, 2, 4):
test.cancel("live active block commit is not supported"
" in current libvirt version.")
# A backup of original vm
vmxml_backup = vm_xml.VMXML.new_from_inactive_dumpxml(vm_name)
# Abort the test if there are snapshots already
exsiting_snaps = virsh.snapshot_list(vm_name)
if len(exsiting_snaps) != 0:
test.fail("There are snapshots created for %s already" %
vm_name)
snapshot_external_disks = []
cmd_session = None
try:
if disk_src_protocol == 'iscsi' and disk_type == 'network':
if not libvirt_version.version_compare(1, 0, 4):
test.cancel("'iscsi' disk doesn't support in"
" current libvirt version.")
# Set vm xml and guest agent
if replace_vm_disk:
if disk_src_protocol == "rbd" and disk_type == "network":
src_host = params.get("disk_source_host", "EXAMPLE_HOSTS")
mon_host = params.get("mon_host", "EXAMPLE_MON_HOST")
if src_host.count("EXAMPLE") or mon_host.count("EXAMPLE"):
test.cancel("Please provide rbd host first.")
if backing_file_relative_path:
if vm.is_alive():
vm.destroy(gracefully=False)
first_src_file = get_first_disk_source()
blk_source_image = os.path.basename(first_src_file)
blk_source_folder = os.path.dirname(first_src_file)
replace_disk_image = make_relative_path_backing_files()
params.update({'disk_source_name': replace_disk_image,
'disk_type': 'file',
'disk_src_protocol': 'file'})
vm.start()
libvirt.set_vm_disk(vm, params, tmp_dir)
开发者ID:balamuruhans,项目名称:tp-libvirt,代码行数:66,代码来源:virsh_blockcommit.py
示例15: run
#.........这里部分代码省略.........
if pre_vm_state == "transient":
logging.info("Creating %s...", vm_name)
vmxml_for_test = vm_xml.VMXML.new_from_inactive_dumpxml(vm_name)
if vm.is_alive():
vm.destroy(gracefully=False)
vm.undefine()
if virsh.create(vmxml_for_test.xml,
**virsh_dargs).exit_status:
vmxml_backup.define()
raise error.TestFail("Cann't create the domain")
elif vm.is_dead():
try:
vm.start()
vm.wait_for_login().close()
except virt_vm.VMStartError:
if start_error:
pass
else:
raise error.TestFail("VM Failed to start"
" for some reason!")
# Set memory operation
if set_max_mem:
max_mem_option = params.get("max_mem_option", "")
ret = virsh.setmaxmem(vm_name, set_max_mem,
flagstr=max_mem_option)
libvirt.check_exit_status(ret, maxmem_error)
# Check domain xml after start the domain.
if test_dom_xml:
check_dom_xml(at_mem=attach_device)
# Check qemu command line
if test_qemu_cmd:
check_qemu_cmd()
# Check guest meminfo after attachment
if (attach_device and not attach_option.count("config") and
not any([attach_error, start_error])):
check_guest_meminfo(old_mem_total)
# Consuming memory on guest,
# to verify memory changes by numastat
if test_mem_binding:
pid = vm.get_pid()
old_numastat = read_from_numastat(pid, "Total")
logging.debug("Numastat: %s", old_numastat)
consume_vm_mem()
new_numastat = read_from_numastat(pid, "Total")
logging.debug("Numastat: %s", new_numastat)
# Only check total memory which is the last element
if float(new_numastat[-1]) - float(old_numastat[-1]) < 0:
raise error.TestFail("Numa memory can't be consumed"
" on guest")
# Run managedsave command to check domain xml.
if test_managedsave:
ret = virsh.managedsave(vm_name, **virsh_dargs)
libvirt.check_exit_status(ret)
vm.start()
vm.wait_for_login().close()
if test_dom_xml:
check_dom_xml(at_mem=attach_device)
# Run save and restore command to check domain xml
if test_save_restore:
check_save_restore()
if test_dom_xml:
check_dom_xml(at_mem=attach_device)
# Check domain xml after restarting libvirtd
if restart_libvirtd:
libvirtd = utils_libvirtd.Libvirtd()
libvirtd.restart()
if test_dom_xml:
check_dom_xml(at_mem=attach_device)
# Detach the memory device
if detach_device:
if not dev_xml:
dev_xml = create_mem_xml()
ret = virsh.detach_device(vm_name, dev_xml.xml,
flagstr=attach_option)
libvirt.check_exit_status(ret, detach_error)
if test_dom_xml:
check_dom_xml(dt_mem=detach_device)
finally:
# Delete snapshots.
snapshot_lists = virsh.snapshot_list(vm_name)
if len(snapshot_lists) > 0:
libvirt.clean_up_snapshots(vm_name, snapshot_lists)
for snap in snapshot_lists:
virsh.snapshot_delete(vm_name, snap, "--metadata")
# Recover VM.
if vm.is_alive():
vm.destroy(gracefully=False)
logging.info("Restoring vm...")
vmxml_backup.sync()
开发者ID:CongLi,项目名称:tp-libvirt,代码行数:101,代码来源:libvirt_mem.py
示例16: run
def run(test, params, env):
"""
Test command: virsh blockcommit <domain> <path>
1) Prepare test environment.
2) Commit changes from a snapshot down to its backing image.
3) Recover test environment.
4) Check result.
"""
def make_disk_snapshot():
# Add all disks into commandline.
disks = vm.get_disk_devices()
# Make three external snapshots for disks only
for count in range(1, 4):
options = "snapshot%s snap%s-desc " \
"--disk-only --atomic --no-metadata" % (count, count)
if needs_agent:
options += " --quiesce"
for disk in disks:
disk_detail = disks[disk]
basename = os.path.basename(disk_detail['source'])
# Remove the original suffix if any, appending ".snap[0-9]"
diskname = basename.split(".")[0]
disk_external = os.path.join(tmp_dir,
"%s.snap%s" % (diskname, count))
snapshot_external_disks.append(disk_external)
options += " %s,snapshot=external,file=%s" % (disk,
disk_external)
cmd_result = virsh.snapshot_create_as(vm_name, options,
ignore_status=True,
debug=True)
status = cmd_result.exit_status
if status != 0:
raise error.TestFail("Failed to make snapshots for disks!")
# Create a file flag in VM after each snapshot
flag_file = tempfile.NamedTemporaryFile(prefix=("snapshot_test_"),
dir="/tmp")
file_path = flag_file.name
flag_file.close()
status, output = session.cmd_status_output("touch %s" % file_path)
if status:
raise error.TestFail("Touch file in vm failed. %s" % output)
snapshot_flag_files.append(file_path)
# 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")
needs_agent = "yes" == params.get("needs_agent", "yes")
replace_vm_disk = "yes" == params.get("replace_vm_disk", "no")
top_inactive = ("yes" == params.get("top_inactive"))
with_timeout = ("yes" == params.get("with_timeout_option", "no"))
status_error = ("yes" == params.get("status_error", "no"))
base_option = params.get("base_option", "none")
middle_base = "yes" == params.get("middle_base", "no")
pivot_opt = "yes" == params.get("pivot_opt", "no")
snap_in_mirror = "yes" == params.get("snap_in_mirror", "no")
snap_in_mirror_err = "yes" == params.get("snap_in_mirror_err", "no")
virsh_dargs = {'debug': True}
# Process domain disk device parameters
disk_type = params.get("disk_type")
disk_src_protocol = params.get("disk_source_protocol")
vol_name = params.get("vol_name")
tmp_dir = data_dir.get_tmp_dir()
pool_name = params.get("pool_name", "gluster-pool")
brick_path = os.path.join(tmp_dir, pool_name)
if not top_inactive:
if not libvirt_version.version_compare(1, 2, 4):
raise error.TestNAError("live active block commit is not supported"
+ " in current libvirt version.")
# A backup of original vm
vmxml_backup = vm_xml.VMXML.new_from_inactive_dumpxml(vm_name)
# Abort the test if there are snapshots already
exsiting_snaps = virsh.snapshot_list(vm_name)
if len(exsiting_snaps) != 0:
raise error.TestFail("There are snapshots created for %s already" %
vm_name)
snapshot_external_disks = []
try:
if disk_src_protocol == 'iscsi' and disk_type == 'network':
if not libvirt_version.version_compare(1, 0, 4):
raise error.TestNAError("'iscsi' disk doesn't support in"
|
请发表评论