diff --git a/qemu/tests/cfg/vfio_net_boot.cfg b/qemu/tests/cfg/vfio_net_boot.cfg new file mode 100644 index 0000000000..1e981ad586 --- /dev/null +++ b/qemu/tests/cfg/vfio_net_boot.cfg @@ -0,0 +1,49 @@ +- vfio_net_boot: + virt_test_type = qemu + type = vfio_net_boot + start_vm = no + nics = "" + # Special host pci slots to be configured + # setup_hostdev_slots = 0000:00:00.1 + hostdev_bind_driver = vfio-pci + vm_hostdev_driver = vfio-pci + ext_host = www.redhat.com + variants: + - single_vm: + vms = "vm1" + - multi_vms: + vms = "vm1 vm2" + image_snapshot = yes + variants: + - one_nic: + vm_hostdevs = hostdev1 + - multi_nics: + vm_hostdevs = hostdev1 hostdev2 + variants: + - pf: + hostdev_assignment_type = pf + - vf: + hostdev_assignment_type = vf + hostdev_vf_counts = 4 + variants ip_version: + - ipv4: + - ipv6: + variants: + - @default: + - virtio_iommu: + required_qemu= [7.0.0,) + only x86_64, aarch64 + x86_64: + only q35 + enable_guest_iommu = yes + virtio_iommu = yes + - intel_iommu: + only q35 + only HostCpuVendor.intel + machine_type_extra_params = "kernel-irqchip=split" + intel_iommu = yes + enable_guest_iommu = yes + variants: + - @default: + - hugepage: + hugepage = yes diff --git a/qemu/tests/vfio_net_boot.py b/qemu/tests/vfio_net_boot.py new file mode 100644 index 0000000000..641c8f8cc3 --- /dev/null +++ b/qemu/tests/vfio_net_boot.py @@ -0,0 +1,73 @@ +from virttest import error_context, utils_net + +from provider import hostdev +from provider.hostdev import utils as hostdev_utils +from provider.hostdev.dev_setup import hostdev_setup + + +@error_context.context_aware +def run(test, params, env): + """ + Assign host devices to VM and do ping test. + + :param test: QEMU test object. + :type test: avocado_vt.test.VirtTest + :param params: Dictionary with the test parameters. + :type params: virttest.utils_params.Params + :param env: Dictionary with test environment. + :type env: virttest.utils_env.Env + """ + ip_version = params["ip_version"] + with hostdev_setup(params) as params: + hostdev_driver = params.get("vm_hostdev_driver", "vfio-pci") + assignment_type = params.get("hostdev_assignment_type") + ext_host = params.get( + "ext_host", utils_net.get_host_ip_address(ip_ver=ip_version) + ) + available_pci_slots = hostdev_utils.get_pci_by_dev_type( + assignment_type, "network", hostdev_driver + ) + # Create all VMs first + for vm in env.get_all_vms(): + vm_hostdevs = vm.params.objects("vm_hostdevs") + pci_slots = [] + error_context.base_context(f"Setting hostdevs for {vm.name}", test.log.info) + for dev in vm_hostdevs: + pci_slot = available_pci_slots.pop(0) + vm.params[f"vm_hostdev_host_{dev}"] = pci_slot + pci_slots.append(pci_slot) + vm.create(params=vm.params) + vm.verify_alive() + vm.params["vm_hostdev_slots"] = pci_slots + + # Login and ping + for vm in env.get_all_vms(): + try: + error_context.context("Log into guest via MAC address", test.log.info) + for slot in vm.params["vm_hostdev_slots"]: + parent_slot = hostdev_utils.get_parent_slot(slot) + slot_manager = params[f"hostdev_manager_{parent_slot}"] + if type(slot_manager) is hostdev.PFDevice: + mac_addr = slot_manager.mac_addresses[0] + else: + slot_index = slot_manager.vfs.index(slot) + mac_addr = slot_manager.mac_addresses[slot_index] + session = hostdev_utils.ssh_login_from_mac( + vm, mac_addr, int(ip_version[-1]) + ) + if session: + error_context.context( + f"Ping {ext_host} from {vm.name}", test.log.info + ) + s_ping, _ = utils_net.ping( + ext_host, + 10, + session=session, + timeout=30, + force_ipv4=(ip_version == "ipv4"), + ) + session.close() + if s_ping: + test.fail(f"Fail to ping {ext_host} from {vm.name}") + finally: + vm.destroy()