Skip to content

Commit

Permalink
vfio_net_boot: Basic test case to test host NIC passthrough
Browse files Browse the repository at this point in the history
This set of test cases is to test host NIC passthrough in to the guest.
Passthrough some NICs to vm, and then login via ssh, then ping external
IP address from guest.

Signed-off-by: Yihuang Yu <[email protected]>
  • Loading branch information
PaulYuuu committed Jul 2, 2024
1 parent 16aaecd commit 2ce3bba
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 0 deletions.
49 changes: 49 additions & 0 deletions qemu/tests/cfg/vfio_net_boot.cfg
Original file line number Diff line number Diff line change
@@ -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
73 changes: 73 additions & 0 deletions qemu/tests/vfio_net_boot.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 2ce3bba

Please sign in to comment.