|
| 1 | +from virttest import libvirt_version |
| 2 | +from virttest import virsh |
| 3 | + |
| 4 | +from virttest.libvirt_xml import vm_xml |
| 5 | +from virttest.utils_libvirt import libvirt_vmxml |
| 6 | +from virttest.utils_test import libvirt |
| 7 | + |
| 8 | + |
| 9 | +def run(test, params, env): |
| 10 | + """ |
| 11 | + Hotplug or coldplug iommu device to guest |
| 12 | + """ |
| 13 | + libvirt_version.is_libvirt_feature_supported(params) |
| 14 | + iommu_dict = eval(params.get('iommu_dict', '{}')) |
| 15 | + attach_option = params.get("attach_option", "") |
| 16 | + err_msg = params.get("err_msg") |
| 17 | + |
| 18 | + vm_name = params.get("main_vm", "avocado-vt-vm1") |
| 19 | + vm = env.get_vm(vm_name) |
| 20 | + vmxml = vm_xml.VMXML.new_from_dumpxml(vm_name) |
| 21 | + backup_vmxml = vmxml.copy() |
| 22 | + try: |
| 23 | + if attach_option and vm.is_alive(): |
| 24 | + vm.destroy() |
| 25 | + elif not attach_option and not vm.is_alive(): |
| 26 | + vm.start() |
| 27 | + vm.wait_for_login().close() |
| 28 | + |
| 29 | + iommu_dev = libvirt_vmxml.create_vm_device_by_type('iommu', iommu_dict) |
| 30 | + test.log.debug(f"iommu device: {iommu_dev}") |
| 31 | + res = virsh.attach_device(vm.name, iommu_dev.xml, debug=True, |
| 32 | + flagstr=attach_option) |
| 33 | + libvirt.check_result(res, err_msg) |
| 34 | + finally: |
| 35 | + backup_vmxml.sync() |
0 commit comments