Skip to content

Commit dcd7d6a

Browse files
Tests perform PCI_PT of NIC devices and checks ping And Tests pci device persistent across Multiple Reboot of VM
1. Changes made to support ppc64 arch and perform pci PT of network devices 2. Perform ping to other server ip and check the device network connectivity 3. Added test to check the device availability after multiple reboots of guest is done Signed-off-by: Tasmiya Nalatwad <tasmiya@linux.vnet.ibm.com>
1 parent 4c4c67c commit dcd7d6a

File tree

2 files changed

+72
-46
lines changed

2 files changed

+72
-46
lines changed

libvirt/tests/cfg/passthrough/pci/libvirt_pci_passthrough.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,7 @@
4545
operation = "suspend"
4646
- passthrough_shutdown_start:
4747
operation = "shutdown"
48+
- passthrough_multiple_reboots:
49+
number_of_reboots = 15
50+
operation = "reboot"
51+
supported_err = "not supported by the connection driver: virDomainReboot"

libvirt/tests/src/passthrough/pci/libvirt_pci_passthrough.py

Lines changed: 68 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging as log
22
import ipaddress
3+
import platform
34
import time
45

56
from virttest import virsh, virt_vm
@@ -39,6 +40,8 @@ def run(test, params, env):
3940
i) Reboot.
4041
ii) Suspend/Resume.
4142
iii) Start/Shutdown.
43+
d). Multiple Reboots:
44+
1. Checking PCI Device remains persistent across multiple reboots
4245
"""
4346

4447
def guest_lifecycle():
@@ -93,6 +96,8 @@ def guest_lifecycle():
9396
sriov = ('yes' == params.get("libvirt_pci_SRIOV", 'no'))
9497
device_type = params.get("libvirt_pci_device_type", "NIC")
9598
vm_vfs = int(params.get("number_vfs", 2))
99+
number_of_reboots = int(params.get("number_of_reboots", "1"))
100+
arch = platform.machine()
96101
pci_dev = None
97102
pci_address = None
98103
bus_info = []
@@ -174,59 +179,76 @@ def guest_lifecycle():
174179
pci_address = pci_xml.cap.get_address_dict()
175180
vmxml.add_hostdev(pci_address)
176181

177-
try:
178-
for itr in range(iteration):
179-
logging.info("Currently executing iteration number: '%s'", itr)
180-
vmxml.sync()
181-
vm.start()
182-
session = vm.wait_for_login()
183-
# The Network configuration is generic irrespective of PF or SRIOV VF
184-
if device_type == "NIC":
185-
if sorted(vm.get_pci_devices()) != sorted(nic_list_before):
186-
logging.debug("Adapter passthroughed to guest successfully")
187-
else:
188-
test.fail("Passthrough adapter not found in guest.")
189-
net_ip = ipaddress.ip_address(net_ip)
190-
nic_list_after = vm.get_pci_devices()
191-
nic_list = list(set(nic_list_after).difference(set(nic_list_before)))
192-
for val in range(len(nic_list)):
193-
bus_info.append(str(nic_list[val]).split(' ', 1)[0])
194-
nic_list[val] = str(nic_list[val]).split(' ', 1)[0][:-2]
195-
bus_info.sort()
196-
if not sriov:
197-
# check all functions get same iommu group
182+
def check_device_status(net_ip, server_ip, netmask):
183+
logging.info("Currently executing iteration number: '%s'", itr)
184+
vmxml.sync()
185+
vm.start()
186+
session = vm.wait_for_login()
187+
# The Network configuration is generic irrespective of PF or SRIOV VF
188+
if device_type == "NIC":
189+
if sorted(vm.get_pci_devices()) != sorted(nic_list_before):
190+
logging.debug("Adapter passthroughed to guest successfully")
191+
else:
192+
test.fail("Passthrough adapter not found in guest.")
193+
net_ip = ipaddress.ip_address(net_ip)
194+
nic_list_after = vm.get_pci_devices()
195+
nic_list = list(set(nic_list_after).difference(set(nic_list_before)))
196+
for val in range(len(nic_list)):
197+
bus_info.append(str(nic_list[val]).split(' ', 1)[0])
198+
nic_list[val] = str(nic_list[val]).split(' ', 1)[0][:-2]
199+
bus_info.sort()
200+
if not sriov:
201+
# check all functions get same iommu group
202+
# arch ppc64 gets different iommu group when attached to VM
203+
if arch != "ppc64le":
198204
if len(set(nic_list)) != 1:
199205
test.fail("Multifunction Device passthroughed but "
200206
"functions are in different iommu group")
201-
# ping to server from each function
202-
for val in bus_info:
203-
nic_name = str(utils_misc.get_interface_from_pci_id(val, session))
204-
session.cmd("ip addr flush dev %s" % nic_name)
205-
session.cmd("ip addr add %s/%s dev %s"
206-
% (net_ip, netmask, nic_name))
207-
session.cmd("ip link set %s up" % nic_name)
208-
# Pinging using nic_name is having issue,
209-
# hence replaced with IPAddress
210-
s_ping, o_ping = utils_test.ping(server_ip, count=5,
211-
interface=net_ip, timeout=30,
212-
session=session)
213-
logging.info(o_ping)
214-
if s_ping != 0:
215-
err_msg = "Ping test fails, error info: '%s'"
216-
test.fail(err_msg % o_ping)
217-
# Each interface should have unique IP
207+
# ping to server from each function
208+
for val in bus_info:
209+
nic_name = str(utils_misc.get_interface_from_pci_id(val, session))
210+
session.cmd("ip addr flush dev %s" % nic_name)
211+
session.cmd("ip addr add %s/%s dev %s"
212+
% (net_ip, netmask, nic_name))
213+
session.cmd("ip link set %s up" % nic_name)
214+
# Pinging using nic_name is having issue,
215+
# hence replaced with IPAddress
216+
s_ping, o_ping = utils_test.ping(server_ip, count=5,
217+
interface=net_ip, timeout=30,
218+
session=session)
219+
logging.info(o_ping)
220+
if s_ping != 0:
221+
err_msg = "Ping test fails, error info: '%s'"
222+
test.fail(err_msg % o_ping)
223+
# Each interface should have unique IP
224+
# For ppc64 arch let's test using one ip only
225+
if arch != "ppc64le":
218226
net_ip = net_ip + 1
219227

220-
elif device_type == "STORAGE":
221-
# Get the result of "fdisk -l" in guest, and
222-
# compare the result with fdisk_list_before.
223-
output = session.cmd_output("fdisk -l|grep \"Disk identifier:\"")
224-
fdisk_list_after = output.splitlines()
225-
if fdisk_list_after == fdisk_list_before:
226-
test.fail("Didn't find the disk attached to guest.")
228+
elif device_type == "STORAGE":
229+
# Get the result of "fdisk -l" in guest, and
230+
# compare the result with fdisk_list_before.
231+
output = session.cmd_output("fdisk -l|grep \"Disk identifier:\"")
232+
fdisk_list_after = output.splitlines()
233+
if fdisk_list_after == fdisk_list_before:
234+
test.fail("Didn't find the disk attached to guest.")
227235

228-
# Execute VM Life-cycle Operation with device pass-through
236+
def multiple_reboot(number_of_reboots):
237+
for reboot_count in range(number_of_reboots):
238+
logging.info("Performing VM Reboot with device pass-through for reboot count : %s", reboot_count)
229239
guest_lifecycle()
240+
logging.info("Check device avialablity after VM Reboot for reboot count : %s", reboot_count)
241+
check_device_status(net_ip, server_ip, netmask)
242+
243+
try:
244+
for itr in range(iteration):
245+
check_device_status(net_ip, server_ip, netmask)
246+
247+
# Execute VM Life-cycle Operation with device pass-through
248+
guest_lifecycle()
249+
250+
# Execute Multiple reboots on VM and check the device persistency
251+
multiple_reboot(number_of_reboots)
230252

231253
finally:
232254
backup_xml.sync()

0 commit comments

Comments
 (0)