本文整理汇总了Python中virttest.libvirt_xml.vm_xml.VMXML.get_device_class方法的典型用法代码示例。如果您正苦于以下问题:Python VMXML.get_device_class方法的具体用法?Python VMXML.get_device_class怎么用?Python VMXML.get_device_class使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类virttest.libvirt_xml.vm_xml.VMXML
的用法示例。
在下文中一共展示了VMXML.get_device_class方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from virttest.libvirt_xml.vm_xml import VMXML [as 别名]
# 或者: from virttest.libvirt_xml.vm_xml.VMXML import get_device_class [as 别名]
def run(test, params, env):
"""
Test for PCI single function device(NIC or Infiniband)
passthrough to libvirt guest in hotplug mode.
a). NIC Or Infiniband:
1. Get params.
2. Get the pci device function.
3. Start guest
4. prepare device xml to be attached
5. hotplug the device
6. check device hotplugged or not
7. Ping to server_ip from guest
8. test flood ping
9. test guest life cycle
10. test virsh dumpxml
11. hotunplug the device
12. test stress
to verify the new network device.
"""
# get the params from params
vm_name = params.get("main_vm")
vm = env.get_vm(vm_name)
device_name = params.get("libvirt_pci_net_dev_name", "ENTER_YOUR.DEV.NAME")
pci_id = params.get("libvirt_pci_net_dev_label", "ENTER_YOUR.DEV.LABEL")
net_ip = params.get("libvirt_pci_net_ip", "ENTER_YOUR.IP")
server_ip = params.get("libvirt_pci_server_ip",
"ENTER_YOUR.SERVER.IP")
netmask = params.get("libvirt_pci_net_mask", "ENTER_YOUR.MASK")
stress_val = params.get("stress_val", "1")
stress = params.get("stress", "no")
timeout = int(params.get("timeout", "ENTER_YOUR.TIMEOUT.VALUE"))
suspend_operation = params.get("suspend_operation", "no")
reboot_operation = params.get("reboot_operation", "no")
virsh_dumpxml = params.get("virsh_dumpxml", "no")
virsh_dump = params.get("virsh_dump", "no")
flood_ping = params.get("flood_ping", "no")
# Check the parameters from configuration file.
for each_param in params.itervalues():
if "ENTER_YOUR" in each_param:
test.cancel("Please enter the configuration details of %s."
% each_param)
vmxml = VMXML.new_from_inactive_dumpxml(vm_name)
backup_xml = vmxml.copy()
devices = vmxml.get_devices()
pci_devs = []
dargs = {'debug': True, 'ignore_status': True}
controller = Controller("controller")
controller.type = "pci"
controller.index = params.get("index", "1")
controller.model = params.get("model", "pci-root")
devices.append(controller)
vmxml.set_devices(devices)
vmxml.sync()
if not vm.is_alive():
vm.start()
session = vm.wait_for_login()
if not utils_package.package_install(["ppc64-diag",
"librtas", "powerpc-utils"],
session, 360):
test.cancel('Fail on dependencies installing')
if virsh_dump == "yes":
dump_file = os.path.join(data_dir.get_tmp_dir(), "virshdump.xml")
output = session.cmd_output("ip link")
logging.debug("checking for output - %s", output)
nic_list_before = str(output.splitlines())
logging.debug("nic_list before hotplug %s", nic_list_before)
obj = PciAssignable()
# get all functions id's
pci_ids = obj.get_same_group_devs(pci_id)
for val in pci_ids:
temp = val.replace(":", "_")
pci_devs.extend(["pci_"+temp])
pci_val = pci_devs[0].replace(".", "_")
pci_xml = NodedevXML.new_from_dumpxml(pci_val)
pci_address = pci_xml.cap.get_address_dict()
dev = VMXML.get_device_class('hostdev')()
dev.mode = 'subsystem'
dev.hostdev_type = 'pci'
dev.managed = 'no'
dev.source = dev.new_source(**pci_address)
def detach_device(pci_devs, pci_ids):
# detaching the device from host
for pci_value, pci_node in map(None, pci_devs, pci_ids):
pci_value = pci_value.replace(".", "_")
cmd = "lspci -ks %s | grep 'Kernel driver in use' |\
awk '{print $5}'" % pci_node
driver_name = to_text(process.system_output(cmd, shell=True).strip())
if driver_name == "vfio-pci":
logging.debug("device alreay detached")
else:
if virsh.nodedev_detach(pci_value).exit_status:
test.error("Hostdev node detach failed")
driver_name = to_text(process.system_output(cmd, shell=True).strip())
if driver_name != "vfio-pci":
test.error("driver bind failed after detach")
def reattach_device(pci_devs, pci_ids):
# reattach the device to host
#.........这里部分代码省略.........