未验证 提交 3351ebd7 编写于 作者: Y YongxueHong 提交者: GitHub

Merge pull request #2243 from YongxueHong/bug-1542350_1566866

multi_disk_random_hotplug: Refactoring the codes
......@@ -29,6 +29,7 @@ from virttest.qemu_capabilities import Flags
from virttest.qemu_devices import qdevices
from virttest.qemu_devices.utils import (DeviceError, DeviceHotplugError,
DeviceUnplugError)
from virttest.qemu_monitor import MonitorLockError
HOTPLUG, UNPLUG = ('hotplug', 'unplug')
HOTPLUGGED_HBAS = {}
......@@ -37,6 +38,7 @@ DISK = {'name': 'images', 'media': 'disk'}
CDROM = {'name': 'cdroms', 'media': 'cdrom'}
_LOCK = threading.Lock()
_QMP_OUTPUT = {}
def _verify_plugged_num(action):
......@@ -157,6 +159,9 @@ class BlockDevicesPlug(object):
The Block Devices Plug.
"""
ACQUIRE_LOCK_TIMEOUT = 20
VERIFY_UNPLUG_TIMEOUT = 60
def __init__(self, vm):
self.vm = vm
self._imgs = vm.params.get("images").split()[1:]
......@@ -167,7 +172,6 @@ class BlockDevicesPlug(object):
self._plugged_disks = []
self._orig_disks = set()
self._all_disks = set()
self._qmp_outputs = {}
self._event_devs = []
self._dev_type = DISK
self._qdev_type = qdevices.QBlockdevNode if vm.check_capability(
......@@ -200,10 +204,15 @@ class BlockDevicesPlug(object):
def _check_qmp_outputs(self, action):
""" Check the output of qmp commands. """
for dev_id in list(self._qmp_outputs.keys()):
output = self._qmp_outputs.pop(dev_id)
for dev_id in list(_QMP_OUTPUT.keys()):
output = _QMP_OUTPUT.pop(dev_id)
if output[1] is False:
raise TestError("Failed to %s device %s." % (action, dev_id))
err = "Failed to %s device %s. " % (action, dev_id)
if not output[0] and action == 'unplug':
err += 'No deleted event generated and %s still in qtree' % dev_id
else:
err += output[0]
raise TestError(err)
def _get_events_deleted(self):
""" Get the device deleted events. """
......@@ -251,6 +260,16 @@ class BlockDevicesPlug(object):
self._hotplugged_devs[img].insert(-1, dev)
HOTPLUGGED_HBAS[img] = dev
def _plug(self, plug_func, monitor):
end = time.time() + self.ACQUIRE_LOCK_TIMEOUT
while time.time() < end:
try:
return plug_func(monitor)
except MonitorLockError:
pass
else:
return plug_func(monitor)
def _hotplug_atomic(self, device, monitor, bus=None):
""" Function hot plug device to devices representation. """
with _LOCK:
......@@ -281,7 +300,7 @@ class BlockDevicesPlug(object):
bus.prepare_hotplug(device)
qdev_out = self.vm.devices.insert(device)
out = device.hotplug(monitor)
out = self._plug(device.hotplug, monitor)
ver_out = device.verify_hotplug(out, monitor)
if ver_out is False:
with _LOCK:
......@@ -310,9 +329,10 @@ class BlockDevicesPlug(object):
with _LOCK:
self.vm.devices.set_dirty()
out = device.unplug(monitor)
if not utils_misc.wait_for(lambda: device.verify_unplug(
out, monitor) is True, first=1, step=5, timeout=60):
out = self._plug(device.unplug, monitor)
if not utils_misc.wait_for(
lambda: device.verify_unplug(out, monitor) is True,
first=1, step=5, timeout=self.VERIFY_UNPLUG_TIMEOUT):
with _LOCK:
self.vm.devices.set_clean()
return out, device.verify_unplug(out, monitor)
......@@ -327,7 +347,8 @@ class BlockDevicesPlug(object):
nodes = [format_node]
nodes.extend((n for n in format_node.get_child_nodes()))
for node in nodes:
if not node.verify_unplug(node.unplug(monitor), monitor):
if not node.verify_unplug(
self._plug(node.unplug, monitor), monitor):
raise DeviceUnplugError(
node, "Failed to unplug blockdev node.", self)
with _LOCK:
......@@ -358,7 +379,7 @@ class BlockDevicesPlug(object):
for img, devices in devices_dict.items():
for device in devices:
args = (device, monitor) if bus is None else (device, monitor, bus)
self._qmp_outputs[device.get_qid()] = getattr(
_QMP_OUTPUT[device.get_qid()] = getattr(
self, '_%s_atomic' % action)(*args)
time.sleep(self._interval)
......@@ -368,7 +389,7 @@ class BlockDevicesPlug(object):
"""
logging.info("Start to hotplug devices \"%s\" by monitor %s." % (
' '.join(images), monitor.name))
args = images if bus is None else (images, {'aobject': bus.aobject})
args = (images, {'aobject': 'pci.0' if bus is None else bus.aobject})
self._create_devices(*args)
self._plug_devs(HOTPLUG, self._hotplugged_devs, monitor, bus)
......@@ -392,7 +413,7 @@ class BlockDevicesPlug(object):
# Search the corresponding HBA device to be unplugged.
for img in list(self._unplugged_devs.keys()):
_dev = self._unplugged_devs[img][0]
_dev = next((_ for _ in self._unplugged_devs[img] if _.get_qid() == img))
_dev_bus = _dev.get_param('bus')
if _dev_bus:
bus_name = _dev_bus.rsplit('.')[0]
......
- multi_disk_random_hotplug: install setup image_copy unattended_install.cdrom
type = multi_disk_random_hotplug
start_vm = no
not_preprocess = yes
force_create_image = yes
force_create_image_image1 = no
remove_image = yes
remove_image_image1 = no
stg_image_name = "images/stg%s"
stg_image_num = 20
stg_image_size = 128M
repeat_times = 3
wait_between_hotplugs = 2
wait_after_hotplug = 10
wait_between_unplugs = 2
vt_ulimit_nofile = 8192
ppc64le,ppc64:
wait_between_unplugs = 20
wait_between_unplugs = 20
q35:
pcie_extra_root_port = ${stg_image_num}
# since image check is executed after unplug wait can be 0
wait_after_unplug = 10
Windows:
virtio_blk:
driver_name = viostor
virtio_scsi:
driver_name = vioscsi
# explicitly disable iothread
iothread_scheme ?=
image_iothread ?=
iothreads ?=
iozone_cmd_option = '-azR -r 64k -n 100M -g 100M -M -i 0 -i 1 -I -b iozone_{0}.xls -f {0}:\testfile'
iozone_timeout = 1800
luks:
connect_timeout = 1800
Linux:
# We have multiple disks so just ignor first one of each type
no_stress_cmds = 100
......@@ -26,6 +45,8 @@
stress_stop_cmd = kill -19 `cat /tmp/disk_stress`
stress_cont_cmd = kill -18 `cat /tmp/disk_stress`
stress_kill_cmd = "rm -f /tmp/disk_stress"
dd_cmd = 'dd if={0} of=/dev/null bs=1M count=100 iflag=direct '
dd_cmd += '&& dd if=/dev/zero of={0} bs=1M count=100 oflag=direct'
variants:
- all_types:
stg_params = "fmt:virtio,virtio_scsi,lsi_scsi,usb2"
......@@ -36,8 +57,26 @@
Host_RHEL.m6:
usbs= "ehci"
usb_type_ehci = ich9-usb-ehci1
Linux:
dd_timeout = 1800
- single_type:
no ide, ahci, scsi
virtio_scsi:
vt_ulimit_nofile = 8192
stg_params = "fmt:virtio_scsi"
set_drive_bus = no
Linux:
stg_image_num = 254
plug_timeout = 1800
Windows:
# The CD-ROM has occupied a driver letter.
stg_image_num = 23
q35:
Linux:
stg_image_num = 200
plug_timeout = 1800
set_drive_bus = yes
pcie_extra_root_port = ${stg_image_num}
variants:
- @serial:
- parallel:
......@@ -47,3 +86,30 @@
monitor_type_TestQMP2 = qmp
monitor_type_TestQMP3 = qmp
monitor_type_TestQMP4 = qmp
luks:
acquire_lock_timeout = 1800
ppc64le, ppc64:
acquire_lock_timeout = 7200
verify_unplug_timeout = 300
parallel.single_type:
virtio_scsi:
no Windows
monitors += " TestQMP5 TestQMP6 TestQMP7 TestQMP8 TestQMP9 TestQMP10"
monitors += " TestQMP11 TestQMP12 TestQMP13 TestQMP15 TestQMP15 TestQMP16"
monitors += " TestQMP17 TestQMP18 TestQMP19 TestQMP20"
monitor_type_TestQMP5 = qmp
monitor_type_TestQMP6 = qmp
monitor_type_TestQMP7 = qmp
monitor_type_TestQMP8 = qmp
monitor_type_TestQMP9 = qmp
monitor_type_TestQMP10 = qmp
monitor_type_TestQMP11 = qmp
monitor_type_TestQMP12 = qmp
monitor_type_TestQMP13 = qmp
monitor_type_TestQMP14 = qmp
monitor_type_TestQMP15 = qmp
monitor_type_TestQMP16 = qmp
monitor_type_TestQMP17 = qmp
monitor_type_TestQMP18 = qmp
monitor_type_TestQMP19 = qmp
monitor_type_TestQMP20 = qmp
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册