本文整理汇总了Python中virttest.libvirt_xml.vm_xml.VMXML.set_cpu_mode方法的典型用法代码示例。如果您正苦于以下问题:Python VMXML.set_cpu_mode方法的具体用法?Python VMXML.set_cpu_mode怎么用?Python VMXML.set_cpu_mode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类virttest.libvirt_xml.vm_xml.VMXML
的用法示例。
在下文中一共展示了VMXML.set_cpu_mode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from virttest.libvirt_xml.vm_xml import VMXML [as 别名]
# 或者: from virttest.libvirt_xml.vm_xml.VMXML import set_cpu_mode [as 别名]
def run(test, params, env):
"""
Test command: virsh dumpxml.
1) Prepare parameters.
2) Set options of virsh dumpxml.
3) Prepare environment: vm_state, etc.
4) Run dumpxml command.
5) Recover environment.
6) Check result.
"""
def is_dumpxml_of_running_vm(dumpxml, domid):
"""
To check whether the dumpxml is got during vm is running.
(Verify the domid in dumpxml)
:param dumpxml: the output of virsh dumpxml.
:param domid: the id of vm
"""
match_string = "<domain.*id='%s'/>" % domid
if re.search(dumpxml, match_string):
return True
return False
# Prepare parameters
vm_name = params.get("main_vm")
vm = env.get_vm(vm_name)
vm_ref = params.get("dumpxml_vm_ref", "domname")
options_ref = params.get("dumpxml_options_ref", "")
options_suffix = params.get("dumpxml_options_suffix", "")
vm_state = params.get("dumpxml_vm_state", "running")
security_pwd = params.get("dumpxml_security_pwd", "123456")
status_error = params.get("status_error", "no")
backup_xml = VMXML.new_from_inactive_dumpxml(vm_name)
if options_ref.count("update-cpu"):
VMXML.set_cpu_mode(vm_name)
elif options_ref.count("security-info"):
new_xml = backup_xml.copy()
VMXML.add_security_info(new_xml, security_pwd)
domuuid = vm.get_uuid()
domid = vm.get_id()
# Prepare vm state for test
if vm_state == "shutoff" and vm.is_alive():
vm.destroy() # Confirm vm is shutoff
if vm_ref == "domname":
vm_ref = vm_name
elif vm_ref == "domid":
vm_ref = domid
elif vm_ref == "domuuid":
vm_ref = domuuid
elif vm_ref == "hex_id":
if domid == "-":
vm_ref = domid
else:
vm_ref = hex(int(domid))
if options_suffix:
options_ref = "%s %s" % (options_ref, options_suffix)
# Run command
logging.info("Command:virsh dumpxml %s", vm_ref)
try:
try:
cmd_result = virsh.dumpxml(vm_ref, extra=options_ref)
output = cmd_result.stdout.strip()
if cmd_result.exit_status:
raise error.TestFail("dumpxml %s failed.\n"
"Detail: %s.\n" % (vm_ref, cmd_result))
status = 0
except error.TestFail, detail:
status = 1
output = detail
logging.debug("virsh dumpxml result:\n%s", output)
# Recover vm state
if vm_state == "paused":
vm.resume()
# Check result
if status_error == "yes":
if status == 0:
raise error.TestFail("Run successfully with wrong command.")
elif status_error == "no":
if status:
raise error.TestFail("Run failed with right command.")
else:
# validate dumpxml file
# Since validate LibvirtXML functions are been working by
# cevich, reserving it here. :)
if options_ref.count("inactive"):
if is_dumpxml_of_running_vm(output, domid):
raise error.TestFail("Got dumpxml for active vm "
"with --inactive option!")
elif options_ref.count("update-cpu"):
if not output.count("vendor"):
raise error.TestFail("No more cpu info outputed!")
elif options_ref.count("security-info"):
#.........这里部分代码省略.........