本文整理汇总了Python中virttest.utils_test.libvirt.check_exit_status函数的典型用法代码示例。如果您正苦于以下问题:Python check_exit_status函数的具体用法?Python check_exit_status怎么用?Python check_exit_status使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了check_exit_status函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_result
def check_result(result, status_error):
"""
Check virt-v2v command result
"""
libvirt.check_exit_status(result, status_error)
output = result.stdout + result.stderr
if not status_error:
if not utils_v2v.import_vm_to_ovirt(params, address_cache,
timeout=v2v_timeout):
raise exceptions.TestFail('Import VM failed')
# Check guest following the checkpoint document after convertion
logging.info('Checking common checkpoints for v2v')
vmchecker = VMChecker(test, params, env)
params['vmchecker'] = vmchecker
ret = vmchecker.run()
if len(ret) == 0:
logging.info("All common checkpoints passed")
# Check specific checkpoints
if checkpoint == 'cdrom':
virsh_session = utils_sasl.VirshSessionSASL(params)
virsh_session_id = virsh_session.get_id()
check_device_exist('cdrom', virsh_session_id)
# Merge 2 error lists
error_list.extend(vmchecker.errors)
if len(error_list):
raise exceptions.TestFail('%d checkpoints failed: %s' %
len(error_list), error_list)
示例2: 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))
示例3: test_pmsuspend
def test_pmsuspend(vm_name):
"""
Test pmsuspend command.
"""
if vm.is_dead():
vm.start()
vm.wait_for_login()
# Create swap partition if nessesary.
if not vm.has_swap():
swap_path = os.path.join(test.tmpdir, 'swap.img')
vm.create_swap_partition(swap_path)
ret = virsh.dompmsuspend(vm_name, "disk", **virsh_dargs)
libvirt.check_exit_status(ret)
# wait for vm to shutdown
if not utils_misc.wait_for(lambda: vm.state() == "shut off", 60):
test.fail("vm is still alive after S4 operation")
# Wait for vm and qemu-ga service to start
vm.start()
# Prepare guest agent and start guest
try:
vm.prepare_guest_agent()
except (remote.LoginError, virt_vm.VMError), detail:
test.fail("failed to prepare agent:\n%s" % detail)
示例4: check_event_value
def check_event_value(vm_name, perf_option, event):
"""
Check domstats output and if the event has a value as expect
1. if perf_option == --disable, there isn't a value/line
2. if perf_option == --enable, there is a value/line
:param vm_name: Domain name,id
:param perf_option: --enable or --disable
:param vent: perf event name
"""
logging.debug("check_event_value: vm_name= %s, perf_option=%s, event=%s",
vm_name, perf_option, event)
ret = False
result = virsh.domstats(vm_name, "--perf", ignore_status=True,
debug=True)
libvirt.check_exit_status(result)
output = result.stdout.strip()
logging.debug("domstats output is %s", output)
if perf_option == '--enable':
for line in output.split('\n'):
if '.' in line and event == (line.split('.')[1]).split('=')[0]:
ret = True
else:
ret = True
for line in output.split('\n'):
if '.' in line and event == (line.split('.')[1]).split('=')[0]:
ret = False
return ret
示例5: check_result
def check_result(result, status_error):
"""
Check virt-v2v command result
"""
libvirt.check_exit_status(result, status_error)
output = result.stdout + result.stderr
if skip_check:
logging.info('Skip checking vm after conversion')
elif not status_error:
if output_mode == 'rhev':
if not utils_v2v.import_vm_to_ovirt(params, address_cache,
timeout=v2v_timeout):
test.fail('Import VM failed')
if output_mode == 'libvirt':
try:
virsh.start(vm_name, debug=True, ignore_status=False)
except Exception, e:
test.fail('Start vm failed: %s' % str(e))
# Check guest following the checkpoint document after convertion
vmchecker = VMChecker(test, params, env)
params['vmchecker'] = vmchecker
if params.get('skip_vm_check') != 'yes':
if checkpoint != 'win2008r2_ostk':
ret = vmchecker.run()
if len(ret) == 0:
logging.info("All common checkpoints passed")
if checkpoint == 'win2008r2_ostk':
check_BSOD()
# Merge 2 error lists
error_list.extend(vmchecker.errors)
示例6: storagevol_validate
def storagevol_validate(pool_name, file=None, **virsh_dargs):
"""
Test for schema storagevol
"""
if pool_name is None:
raise error.TestNAError("None pool is specified.")
# Confirm the storagepool exists.
found = False
result = virsh.pool_list(ignore_status=True)
output = re.findall(r"(\S+)\ +(\S+)\ +(\S+)[\ +\n]", str(result.stdout))
for item in output[1:]:
if pool_name == item[0]:
found = True
break
if not found:
raise error.TestNAError("Make sure the storagepool %s exists!" % pool_name)
# Get volume name
cmd_result = virsh.vol_list(pool_name, **virsh_dargs)
libvirt.check_exit_status(cmd_result)
try:
vol_name = re.findall(r"(\S+)\ +(\S+)[\ +\n]", str(cmd_result.stdout))[1][0]
except IndexError:
raise error.TestError("Fail to get volume name")
if vol_name is not None:
cmd_result = virsh.vol_dumpxml(vol_name, pool_name, to_file=file)
libvirt.check_exit_status(cmd_result)
示例7: create_luks_secret
def create_luks_secret(vol_path, password, test):
"""
Create secret for luks encryption
:param vol_path: volume path.
:return: secret id if create successfully.
"""
sec_xml = secret_xml.SecretXML("no", "yes")
sec_xml.description = "volume secret"
sec_xml.usage = 'volume'
sec_xml.volume = vol_path
sec_xml.xmltreefile.write()
ret = virsh.secret_define(sec_xml.xml)
utlv.check_exit_status(ret)
try:
encryption_uuid = re.findall(r".+\S+(\ +\S+)\ +.+\S+",
ret.stdout.strip())[0].lstrip()
except IndexError:
test.error("Fail to get newly created secret uuid")
logging.debug("Secret uuid %s", encryption_uuid)
# Set secret value.
encoding = locale.getpreferredencoding()
secret_string = base64.b64encode(password.encode(encoding)).decode(encoding)
ret = virsh.secret_set_value(encryption_uuid, secret_string)
utlv.check_exit_status(ret)
return encryption_uuid
示例8: make_relative_path_backing_files
def make_relative_path_backing_files():
"""
Create backing chain files of relative path.
:return: absolute path of top active file
"""
first_disk_source = get_first_disk_source()
basename = os.path.basename(first_disk_source)
root_dir = os.path.dirname(first_disk_source)
cmd = "mkdir -p %s" % os.path.join(root_dir, '{b..d}')
ret = process.run(cmd, shell=True)
libvirt.check_exit_status(ret)
# Make three external relative path backing files.
backing_file_dict = collections.OrderedDict()
backing_file_dict["b"] = "../%s" % basename
backing_file_dict["c"] = "../b/b.img"
backing_file_dict["d"] = "../c/c.img"
for key, value in list(backing_file_dict.items()):
backing_file_path = os.path.join(root_dir, key)
cmd = ("cd %s && qemu-img create -f qcow2 -o backing_file=%s,backing_fmt=qcow2 %s.img"
% (backing_file_path, value, key))
ret = process.run(cmd, shell=True)
libvirt.check_exit_status(ret)
return os.path.join(backing_file_path, "d.img")
示例9: secret_validate
def secret_validate(file=None, **virsh_dargs):
"""
Test for schema secret
"""
tmp_dir = data_dir.get_tmp_dir()
volume_path = os.path.join(tmp_dir, "secret_volume")
ephemeral = "no"
private = "no"
secret_xml_obj = SecretXML(ephemeral, private)
status, uuid = commands.getstatusoutput("uuidgen")
if status:
raise error.TestNAError("Failed to generate valid uuid")
secret_xml_obj.uuid = uuid
secret_xml_obj.volume = volume_path
secret_xml_obj.usage = "volume"
secret_obj_xmlfile = os.path.join(SECRET_DIR, uuid + ".xml")
cmd_result = virsh.secret_define(secret_xml_obj.xml, debug=True)
cmd_result = virsh.secret_list(**virsh_dargs)
libvirt.check_exit_status(cmd_result)
try:
uuid = re.findall(r"(\S+)\ +(\S+)[\ +\n]", str(cmd_result.stdout))[1][0]
except IndexError:
raise error.TestError("Fail to get secret uuid")
if uuid:
try:
virsh.secret_dumpxml(uuid, to_file=file, **virsh_dargs)
except error.CmdError, e:
raise error.TestError(str(e))
示例10: check_pool_list
def check_pool_list(pool_name, option="--all", expect_error=False):
"""
Check pool by running pool-list command with given option.
:param pool_name: Name of the pool
:param option: option for pool-list command
:param expect_error: Boolean value, expect command success or fail
"""
found = False
# Get the list stored in a variable
if list_dumpxml_acl:
result = virsh.pool_list(option, **acl_dargs)
else:
result = virsh.pool_list(option, ignore_status=True)
libvirt.check_exit_status(result, False)
output = re.findall(r"(\S+)\ +(\S+)\ +(\S+)[\ +\n]",
str(result.stdout))
for item in output:
if pool_name in item[0]:
found = True
break
if found:
logging.debug("Find pool '%s' in pool list.", pool_name)
else:
logging.debug("Not find pool %s in pool list.", pool_name)
if expect_error and found:
raise error.TestFail("Unexpect pool '%s' exist." % pool_name)
if not expect_error and not found:
raise error.TestFail("Expect pool '%s' doesn't exist." % pool_name)
示例11: make_snapshot
def make_snapshot():
"""
make external snapshots.
:return external snapshot path list
"""
logging.info("Making snapshot...")
first_disk_source = vm.get_first_disk_devices()['source']
snapshot_path_list = []
snapshot2_file = os.path.join(data_dir.get_tmp_dir(), "mem.s2")
snapshot3_file = os.path.join(data_dir.get_tmp_dir(), "mem.s3")
snapshot4_file = os.path.join(data_dir.get_tmp_dir(), "mem.s4")
snapshot4_disk_file = os.path.join(data_dir.get_tmp_dir(), "disk.s4")
snapshot5_file = os.path.join(data_dir.get_tmp_dir(), "mem.s5")
snapshot5_disk_file = os.path.join(data_dir.get_tmp_dir(), "disk.s5")
# Attempt to take different types of snapshots.
snapshots_param_dict = {"s1": "s1 --disk-only --no-metadata",
"s2": "s2 --memspec %s --no-metadata" % snapshot2_file,
"s3": "s3 --memspec %s --no-metadata --live" % snapshot3_file,
"s4": "s4 --memspec %s --diskspec vda,file=%s --no-metadata" % (snapshot4_file, snapshot4_disk_file),
"s5": "s5 --memspec %s --diskspec vda,file=%s --live --no-metadata" % (snapshot5_file, snapshot5_disk_file)}
for snapshot_name in sorted(snapshots_param_dict.keys()):
ret = virsh.snapshot_create_as(vm_name, snapshots_param_dict[snapshot_name],
**virsh_dargs)
libvirt.check_exit_status(ret)
if snapshot_name != 's4' and snapshot_name != 's5':
snapshot_path_list.append(first_disk_source.replace('qcow2', snapshot_name))
return snapshot_path_list
示例12: trigger_hpt_resize
def trigger_hpt_resize(session):
"""
Check the HPT order file and dmesg
:param session: the session to guest
:raise: test.fail if required message is not found
"""
hpt_order_path = "/sys/kernel/debug/powerpc/hpt_order"
hpt_order = session.cmd_output('cat %s' % hpt_order_path).strip()
hpt_order = int(hpt_order)
logging.info('Current hpt_order is %d', hpt_order)
hpt_order += 1
cmd = 'echo %d > %s' % (hpt_order, hpt_order_path)
cmd_result = session.cmd_status_output(cmd)
result = process.CmdResult(stderr=cmd_result[1],
stdout=cmd_result[1],
exit_status=cmd_result[0])
libvirt.check_exit_status(result)
dmesg = session.cmd('dmesg')
dmesg_content = params.get('dmesg_content').split('|')
for content in dmesg_content:
if content % hpt_order not in dmesg:
test.fail("'%s' is missing in dmesg" % (content % hpt_order))
else:
logging.info("'%s' is found in dmesg", content % hpt_order)
示例13: check_state
def check_state(expected_state):
result = virsh.domstate(vm_name, uri=uri)
utlv.check_exit_status(result)
vm_state = result.stdout.strip()
if vm_state == expected_state:
logging.info("Get expected state: %s", vm_state)
else:
raise TestFail("Get unexpected state: %s", vm_state)
示例14: 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")
示例15: run
def run(test, params, env):
"""
Test svirt in virt-clone.
"""
VIRT_CLONE = None
try:
VIRT_CLONE = utils_path.find_command("virt-clone")
except utils_path.CmdNotFoundError:
raise error.TestNAError("No virt-clone command found.")
# Get general variables.
status_error = ('yes' == params.get("status_error", 'no'))
host_sestatus = params.get("svirt_virt_clone_host_selinux", "enforcing")
# Get variables about seclabel for VM.
sec_type = params.get("svirt_virt_clone_vm_sec_type", "dynamic")
sec_model = params.get("svirt_virt_clone_vm_sec_model", "selinux")
sec_label = params.get("svirt_virt_clone_vm_sec_label", None)
sec_relabel = params.get("svirt_virt_clone_vm_sec_relabel", "yes")
sec_dict = {'type': sec_type, 'model': sec_model, 'label': sec_label,
'relabel': sec_relabel}
# Get variables about VM and get a VM object and VMXML instance.
vm_name = params.get("main_vm")
vm = env.get_vm(vm_name)
vmxml = VMXML.new_from_inactive_dumpxml(vm_name)
backup_xml = vmxml.copy()
# Get varialbles about image.
img_label = params.get('svirt_virt_clone_disk_label')
# Label the disks of VM with img_label.
disks = vm.get_disk_devices()
backup_labels_of_disks = {}
for disk in disks.values():
disk_path = disk['source']
backup_labels_of_disks[disk_path] = utils_selinux.get_context_of_file(
filename=disk_path)
utils_selinux.set_context_of_file(filename=disk_path,
context=img_label)
# Set selinux of host.
backup_sestatus = utils_selinux.get_status()
utils_selinux.set_status(host_sestatus)
# Set the context of the VM.
vmxml.set_seclabel([sec_dict])
vmxml.sync()
clone_name = ("%s-clone" % vm.name)
try:
cmd = ("%s --original %s --name %s --auto-clone" %
(VIRT_CLONE, vm.name, clone_name))
cmd_result = utils.run(cmd, ignore_status=True)
utils_libvirt.check_exit_status(cmd_result, status_error)
finally:
# clean up
for path, label in backup_labels_of_disks.items():
utils_selinux.set_context_of_file(filename=path, context=label)
backup_xml.sync()
utils_selinux.set_status(backup_sestatus)
if not virsh.domstate(clone_name).exit_status:
libvirt_vm.VM(clone_name, params, None, None).remove_with_storage()