提交 cc76473d 编写于 作者: A Aihua Liang

New case:block_hotplug_negative

drive release check after failed to add device with data plane enable
Signed-off-by: NAihua Liang <aliang@redhat.com>
上级 bb39a6d8
import logging
import time
from virttest import data_dir
from virttest import storage
from virttest import error_context
from virttest.qemu_devices import qdevices
@error_context.context_aware
def run(test, params, env):
"""
Test hotplug of block devices.
1) Boot up guest without block device.
2) Hotplug a drive
2) Hoplug block device with invalid blk params.
3) Unplug the drive
4) Hotplug the drive again
5) Check vm is alive after drive unplug/hotplug
:param test: QEMU test object.
:param params: Dictionary with the test parameters.
:param env: Dictionary with test environment.
"""
def find_image(image_name):
"""
Find the path of the iamge.
:param image_name: name of image.
:return mage_filename: filename of image.
"""
image_params = params.object_params(image_name)
image_filename = storage.get_image_filename(image_params, data_dir.get_data_dir())
return image_filename
def drive_unplug_plug(drive, vm):
"""
Unplug drive then replug it.
:param drive: instance of QRHDrive
:param vm: Vitual Machine object
"""
error_context.context("unplug the drive", logging.info)
drive.unplug(vm.monitor)
time.sleep(5)
error_context.context("Hotplug the drive", logging.info)
drive.hotplug(vm.monitor)
img_list = params.get("images").split()
img_format_type = params.get("img_format_type", "qcow2")
pci_type = params.get("pci_type", "virtio-blk-pci")
blk_num = int(params.get("blk_num", 1))
add_block_device = True
vm = env.get_vm(params["main_vm"])
vm.verify_alive()
error_context.context("Hotplug block device", logging.info)
for num in xrange(blk_num):
device = qdevices.QDevice(pci_type)
drive = qdevices.QRHDrive("block%d" % num)
drive.set_param("file", find_image(img_list[num + 1]))
drive.set_param("format", img_format_type)
drive_id = drive.get_param("id")
drive.hotplug(vm.monitor)
#add controller if needed
if params.get("need_controller", "no") == "yes":
controller_model = params.get("controller_model")
controller = qdevices.QDevice(controller_model)
bus_extra_param = params.get("bus_extra_params_%s" % img_list[num + 1])
if bus_extra_param:
key, value = bus_extra_param.split("=")
qdevice_params = {key: value}
controller.params.update(qdevice_params)
try:
controller.hotplug(vm.monitor)
except Exception, e:
if "QMP command 'device_add' failed" in str(e):
logging.info("Failed to add controller with invalid params")
drive_unplug_plug(drive, vm)
add_block_device = False
if add_block_device:
device.set_param("drive", drive_id)
device.set_param("id", "block%d" % num)
blk_extra_param = params.get("blk_extra_params_%s" % img_list[num + 1])
if blk_extra_param:
key, value = blk_extra_param.split("=")
device.set_param(key, value)
try:
device.hotplug(vm.monitor)
except Exception, e:
if "QMP command 'device_add' failed" in str(e):
logging.info("Failed to add block with invalid params")
drive_unplug_plug(drive, vm)
error_context.context("Check vm is alive after drive unplug/hotplug test", logging.info)
session = vm.wait_for_login()
if not session.is_responsive():
session.close()
test.fail("VM can't work normally after drive unplug->hotplug")
session.close()
# Below case works stablly on QMP monitor, but have no more test with Human
# monitor, so suggest to use QMP monitor as default qemu monitor run below test
#
- block_hotplug_negative:
no RHEL.3.9
no ide
virt_test_type = qemu
type = block_hotplug_negative
bootindex_image1 = 0
images += " stg0"
boot_drive_stg0 = no
image_name_stg0 = images/storage0
image_size_stg0 = 1G
remove_image_stg0 = yes
force_create_image_stg0 = yes
kill_vm_on_error = yes
blk_num = 1
blk_extra_params_stg0 = "invalid_param=on"
variants:
- @default:
- data_plane:
no Host_RHEL.m6
iothreads = iothread0
virtio_blk:
blk_extra_params_image1 = "iothread=${iothreads}"
virtio_scsi:
no Host_RHEL.m7.u0, Host_RHEL.m7.u1, Host_RHEL.m7.u2
bus_extra_params_image1 = "iothread=${iothreads}"
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册