Skip to content

Commit

Permalink
block_hotplug_with_cpu_hotplug: Add new case
Browse files Browse the repository at this point in the history
Add new case about scenario: hotplug storage device after
hotplug a cpu device.

Signed-off-by: menli <[email protected]>
  • Loading branch information
menli820 committed Nov 20, 2023
1 parent 99286ab commit cc7ba24
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 0 deletions.
92 changes: 92 additions & 0 deletions qemu/tests/block_hotplug_with_cpu_hotplug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
from provider import cpu_utils
from provider import win_wora

from virttest import error_context
from provider.block_devices_plug import BlockDevicesPlug
from virttest import utils_disk, utils_misc
from virttest.utils_misc import get_linux_drive_path
from virttest.utils_windows.drive import get_disk_props_by_serial_number


@error_context.context_aware
def run(test, params, env):
"""
Test hotplug of block devices after
hotplug a cpu device.
1) Boot up guest
2) Hotplug device and verify in qtree
3) Check hotplug devices in guest
4) Hotpulg a cpu device
5) Hotplug device again and verify in qtree.
6) Check hotplug devices in guest
:param test: QEMU test object.
:param params: Dictionary with the test parameters.
:param env: Dictionary with test environment.
"""

def _get_window_disk_index_by_serial(serial):
idx_info = get_disk_props_by_serial_number(session, serial, ["Index"])
if idx_info:
return idx_info["Index"]
test.fail("Not find expected disk %s" % serial)

def _check_disk_in_guest(img):
os_type = params["os_type"]
test.log.debug("Check disk %s in guest" % img)
if os_type == 'windows':
img_size = params.get("image_size_%s" % img)
cmd = utils_misc.set_winutils_letter(session, guest_cmd)
disk = _get_window_disk_index_by_serial(img)
utils_disk.update_windows_disk_attributes(session, disk)
test.log.info("Clean disk:%s", disk)
utils_disk.clean_partition_windows(session, disk)
test.log.info("Formatting disk:%s", disk)
driver = \
utils_disk.configure_empty_disk(session, disk, img_size,
os_type)[0]
output_path = driver + ":\\test.dat"
cmd = cmd.format(output_path)
else:
output_path = get_linux_drive_path(session, img)
cmd = guest_cmd.format(output_path)

test.log.debug(cmd)
session.cmd(cmd)

vcpu_devices = params.objects("vcpu_devices")
img_name_list = params.get("images").split()
guest_cmd = params.get("guest_cmd")

vm = env.get_vm(params["main_vm"])
session = vm.wait_for_login()

if params.get_boolean("workaround_need"):
win_wora.modify_driver(params, session)

error_context.context("Plug device", test.log.info)
plug = BlockDevicesPlug(vm)
plug.hotplug_devs_serial(img_name_list[1])
_check_disk_in_guest(img_name_list[1])

for vcpu_dev in vcpu_devices:
error_context.context("Hotplug vcpu device: %s" % vcpu_dev,
test.log.info)
vm.hotplug_vcpu_device(vcpu_dev)
if not utils_misc.wait_for(
lambda: cpu_utils.check_if_vm_vcpus_match_qemu(vm),
60):
test.fail("Actual number of guest CPUs is not equal to expected")

# FIXME: win2016 guest will reboot once hotplug a cpu
# so we need to reacquire the session.
if params.get_boolean("workaround_need"):
session = vm.wait_for_login()

error_context.context("Plug another device",
test.log.info)
plug.hotplug_devs_serial(img_name_list[2])
_check_disk_in_guest(img_name_list[2])

session.close()
49 changes: 49 additions & 0 deletions qemu/tests/cfg/block_hotplug_with_cpu_hotplug.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
- block_hotplug_with_cpu_hotplug:
type = block_hotplug_with_cpu_hotplug
virt_test_type = qemu
only x86_64 i386
no Win10 Win11
bootindex_image1 = 0
images += " stg0 stg1"
boot_drive_stg0 = no
image_name_stg0 = images/storage0
image_size_stg0 = 1G
blk_extra_params_stg0 = "serial=stg0"
remove_image_stg0 = yes
force_create_image_stg0 = yes
boot_drive_stg1 = no
image_name_stg1 = images/storage1
image_size_stg1 = 1G
blk_extra_params_stg1 = "serial=stg1"
remove_image_stg1 = yes
force_create_image_stg1 = yes
vcpu_devices = vcpu1
q35:
pcie_extra_root_port = 2
Win2016:
# Set a workaround for win2016 guest
workaround_need = yes
devcon_dir = "win7_amd64"
devcon_path = "WIN_UTILS:\devcon\${devcon_dir}\devcon.exe"
driver_inf_file = "C:\Windows\INF\machine.inf"
dev_hwid = '"ACPI\VEN_ACPI&DEV_0010"'
virtio_blk:
drive_format_stg0 = virtio
drive_format_stg1 = virtio
virtio_scsi:
drive_format_stg0 = scsi-hd
drive_format_stg1 = scsi-hd
q35:
drive_bus_stg0 = 1
drive_bus_stg1 = 2
Linux:
tmp_dir = /var/tmp/test
guest_cmd = "mkdir -p ${tmp_dir} && mkfs.xfs -f {0} &&"
guest_cmd += " mount -t xfs {0} ${tmp_dir} && dd if=/dev/zero "
guest_cmd += " of=${tmp_dir}/test.img bs=1M count=100 oflag=direct && "
guest_cmd += " umount ${tmp_dir}"
Windows:
image_size_data = 120M
guest_cmd = "WIN_UTILS:\coreutils\DummyCMD.exe {} 102400000 1"
ovmf:
no i440fx

0 comments on commit cc7ba24

Please sign in to comment.