Skip to content

Commit 2f35e2b

Browse files
PCI PT Hotplug/Hotunplug fixes for arch ppc64le (autotest#6072)
1) Added 2 new test cases : test 1 : hotplog/unplug operation is performed for multiple times test 2 : multiple hotplug/unplug operations with random reboot is done in between to check device avialability inside VM. 2) Changes made are : 1) two new parameters added into cfg file multiple_hotplug_hotunplug number_of_hotplug_unplug 2) params.itervalues() [supported in python2] was removed in python3. Python3 has params.values() instead. Hence made this change as it was failing to read the params with .itervalues() 3) The "librtas" package name varies across different distros (fedora, sles etc). Therefore, the test first checks the running distro and adds the corresponding package name to the package list. This approach ensures seamless testing across all supported distributions. 4) Zip() is the correct and Python 3-compatible way to iterate over two lists in parallel. 5) For PP64LE arch in latest libvirt it is necessary to detach the device from the host before attaching it to a VM. Hence added a arch 'if' flag to check if the arch is ppc64le and libvirt is latest newer from 3.10 then detach the device from host first then attach it to VM. 6) utils_net.ping is same, no changes made to the ping function, just added timeout=30 sec and passing session handler to the same ping function, so that ping command is executed inside VM , as my requirement is to run ping test inside VM for the interface added for a pci device. 7) rand_reboot function is added. The function is designed where it Set probability of reboot per iteration (e.g., 30%) and based on total number of iterations and probability a random reboot happens in between hotplug/unplug operations. On an average for 30 iterations 6-8 reboots are expected. 8) Both the tests are called inside try block Signed-off-by: Tasmiya Nalatwad <tasmiya@linux.vnet.ibm.com>
1 parent fa60ee0 commit 2f35e2b

2 files changed

Lines changed: 87 additions & 18 deletions

File tree

libvirt/tests/cfg/passthrough/pci/libvirt_pci_passthrough_hotplug.cfg

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,9 @@
4545
- virsh_dump:
4646
# dump the guest with memory only option
4747
virsh_dump = "yes"
48+
- multiple_hotplug_hotunplug:
49+
multiple_hotplug_hotunplug = "yes"
50+
number_of_hotplug_unplug = 25
51+
- multiple_hotplug_unplug_with_rand_reboot:
52+
random_reboot = "yes"
53+
number_of_hotplug_unplug = 30

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

Lines changed: 81 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,28 @@
1010
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1111
#
1212
# Author: Prudhvi Miryala<mprudhvi@linux.vnet.ibm.com>
13+
# Author: Tasmiya.Nalatwad<tasmiya@linux.vnet.ibm.com>
1314
# Host device hotplug test
1415

1516

1617
import os
1718
import logging as log
1819
import aexpect
1920
import time
21+
import platform
22+
import random
2023

2124
from avocado.utils import process
25+
from avocado.utils import distro
2226

2327
from virttest import virsh
2428
from virttest.libvirt_xml.vm_xml import VMXML
2529
from virttest.libvirt_xml.nodedev_xml import NodedevXML
2630
from virttest.test_setup import PciAssignable
27-
from virttest import utils_misc
31+
from virttest import utils_test, utils_misc
2832
from virttest import data_dir
2933
from virttest.libvirt_xml.devices.controller import Controller
3034
from virttest import utils_package
31-
from virttest import utils_net
3235
from virttest import libvirt_version
3336
from virttest.utils_test import libvirt
3437

@@ -56,6 +59,9 @@ def run(test, params, env):
5659
10. test virsh dumpxml
5760
11. hotunplug the device
5861
12. test stress
62+
13. Perform multiple hotplug/unplug operations
63+
14. Perfomr random reboots in between
64+
multiple hotplug/unplug
5965
to verify the new network device.
6066
"""
6167
# get the params from params
@@ -75,8 +81,16 @@ def run(test, params, env):
7581
virsh_dumpxml = params.get("virsh_dumpxml", "no")
7682
virsh_dump = params.get("virsh_dump", "no")
7783
flood_ping = params.get("flood_ping", "no")
84+
arch = platform.machine()
85+
multiple_hotplug_hotunplug = params.get("multiple_hotplug_hotunplug", "no")
86+
number_of_hotplug_unplug = int(params.get("number_of_hotplug_unplug", "1"))
87+
random_reboot = params.get("random_reboot", "no")
88+
cntlr_index = params.get("index", "1")
89+
cntlr_model = params.get("model", "pci-root")
90+
cntlr_type = "pci"
91+
7892
# Check the parameters from configuration file.
79-
for each_param in params.itervalues():
93+
for each_param in params.values():
8094
if "ENTER_YOUR" in each_param:
8195
test.cancel("Please enter the configuration details of %s."
8296
% each_param)
@@ -85,19 +99,37 @@ def run(test, params, env):
8599
devices = vmxml.get_devices()
86100
pci_devs = []
87101
dargs = {'debug': True, 'ignore_status': True}
102+
103+
controllers = vmxml.get_controllers(cntlr_type, cntlr_model)
104+
index_list = []
105+
for controller in controllers:
106+
index_value = controller.get("index")
107+
if index_value is not None:
108+
index_list.append(int(index_value))
109+
110+
if index_list:
111+
next_index = max(index_list) + 1
112+
else:
113+
next_index = int(cntlr_index)
88114
controller = Controller("controller")
89-
controller.type = "pci"
90-
controller.index = params.get("index", "1")
91-
controller.model = params.get("model", "pci-root")
115+
controller.type = cntlr_type
116+
controller.index = str(next_index)
117+
controller.model = cntlr_model
118+
92119
devices.append(controller)
93120
vmxml.set_devices(devices)
94121
vmxml.sync()
95122
if not vm.is_alive():
96123
vm.start()
97124
session = vm.wait_for_login()
98-
if not utils_package.package_install(["ppc64-diag",
99-
"librtas", "powerpc-utils"],
100-
session, 360):
125+
detected_distro = distro.detect()
126+
pkg = ["ppc64-diag", "powerpc-utils"]
127+
if detected_distro.name == "sles16":
128+
if int(detected_distro.version) == 16:
129+
pkg.extend(["librtas2"])
130+
if detected_distro.name in ("fedora", "rhel"):
131+
pkg.extend(["librtas"])
132+
if not utils_package.package_install(pkg, session, 360):
101133
test.cancel('Fail on dependencies installing')
102134
if virsh_dump == "yes":
103135
dump_file = os.path.join(data_dir.get_tmp_dir(), "virshdump.xml")
@@ -122,7 +154,7 @@ def run(test, params, env):
122154

123155
def detach_device(pci_devs, pci_ids):
124156
# detaching the device from host
125-
for pci_value, pci_node in map(None, pci_devs, pci_ids):
157+
for pci_value, pci_node in zip(pci_devs, pci_ids):
126158
pci_value = pci_value.replace(".", "_")
127159
cmd = "lspci -ks %s | grep 'Kernel driver in use' |\
128160
awk '{print $5}'" % pci_node
@@ -138,7 +170,7 @@ def detach_device(pci_devs, pci_ids):
138170

139171
def reattach_device(pci_devs, pci_ids):
140172
# reattach the device to host
141-
for pci_value, pci_node in map(None, pci_devs, pci_ids):
173+
for pci_value, pci_node in zip(pci_devs, pci_ids):
142174
pci_value = pci_value.replace(".", "_")
143175
cmd = "lspci -ks %s | grep 'Kernel driver in use' |\
144176
awk '{print $5}'" % pci_node
@@ -160,8 +192,12 @@ def check_attach_pci():
160192
return nic_list_after != nic_list_before
161193

162194
def device_hotplug():
163-
if not libvirt_version.version_compare(3, 10, 0):
164-
detach_device(pci_devs, pci_ids)
195+
if arch == "ppc64le":
196+
if libvirt_version.version_compare(3, 10, 0):
197+
detach_device(pci_devs, pci_ids)
198+
else:
199+
if not libvirt_version.version_compare(3, 10, 0):
200+
detach_device(pci_devs, pci_ids)
165201
# attach the device in hotplug mode
166202
result = virsh.attach_device(vm_name, dev.xml,
167203
flagstr="--live", debug=True)
@@ -190,16 +226,18 @@ def device_hotunplug():
190226

191227
def test_ping():
192228
try:
193-
output = session.cmd_output("lspci -nn | grep %s" % device_name)
229+
session = vm.wait_for_login()
230+
output = session.cmd_output('lspci -nn | grep "%s"' % device_name)
194231
nic_id = str(output).split(' ', 1)[0]
195232
nic_name = str(utils_misc.get_interface_from_pci_id(nic_id,
196233
session))
197234
session.cmd("ip addr flush dev %s" % nic_name)
198235
session.cmd("ip addr add %s/%s dev %s"
199236
% (net_ip, netmask, nic_name))
200237
session.cmd("ip link set %s up" % nic_name)
201-
s_ping, o_ping = utils_net.ping(dest=server_ip, count=5,
202-
interface=net_ip)
238+
s_ping, o_ping = utils_test.ping(dest=server_ip, count=5,
239+
interface=net_ip, timeout=30,
240+
session=session)
203241
logging.info(s_ping)
204242
logging.info(o_ping)
205243
if s_ping:
@@ -211,8 +249,9 @@ def test_ping():
211249

212250
def test_flood_ping():
213251
# Test Flood Ping
214-
s_ping, o_ping = utils_net.ping(dest=server_ip, count=5,
215-
interface=net_ip, flood=True)
252+
s_ping, o_ping = utils_test.ping(dest=server_ip, count=5,
253+
interface=net_ip, timeout=30,
254+
flood=True, session=session)
216255
logging.info(s_ping)
217256
logging.info(o_ping)
218257
if s_ping:
@@ -263,6 +302,15 @@ def test_dump():
263302
if cmd_result.exit_status:
264303
test.fail("Failed to virsh dump of domain %s" % vm_name)
265304

305+
def rand_reboot(iteration):
306+
# Set probability of reboot per iteration (e.g., 30%)
307+
reboot_chance = 0.3
308+
if random.random() < reboot_chance:
309+
logging.debug("Rebooting at iteration %s", iteration)
310+
test_reboot()
311+
time.sleep(5)
312+
logging.debug("Random reboot completed, and adapter found in the VM after reboot")
313+
266314
try:
267315
for stress_value in range(0, int(stress_val)):
268316
device_hotplug()
@@ -279,6 +327,21 @@ def test_dump():
279327
test_dump()
280328
device_hotunplug()
281329

330+
if multiple_hotplug_hotunplug == "yes":
331+
for iteration in range(number_of_hotplug_unplug):
332+
logging.info("Performing Hotplug/Hotunplug of pci device for %s time", iteration)
333+
device_hotplug()
334+
test_ping()
335+
device_hotunplug()
336+
337+
if random_reboot == "yes":
338+
for iteration in range(number_of_hotplug_unplug):
339+
logging.info("Performing Hotplug/Hotunplug of pci device for %s time", iteration)
340+
device_hotplug()
341+
test_ping()
342+
rand_reboot(iteration)
343+
device_hotunplug()
344+
282345
finally:
283346
# clean up
284347
data_dir.clean_tmp_files()

0 commit comments

Comments
 (0)