Skip to content

Commit

Permalink
multi_disk.virtio_scsi.passthrough: Dynamically update blacklist
Browse files Browse the repository at this point in the history
Because the names of disks in different host environments are
different, we need to dynamically modify 'indirect_image_blacklist'.
Check disks before and after scsi_debug is created, and dynamically
modify the 'indirect_image_blacklist' based on newly added disks.

Signed-off-by: Sibo Wang <siwang@redhat.com>
  • Loading branch information
SiboWang1997 committed Nov 27, 2023
1 parent 80f62ea commit 1ac468b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
5 changes: 2 additions & 3 deletions qemu/tests/cfg/multi_disk.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,9 @@
stg_params = "drive_format:scsi-block "
kill_vm = yes
force_create_image = no
pre_command = "modprobe -r scsi_debug; modprobe sg; modprobe scsi_debug add_host=9 dev_size_mb=50"
post_command = "rmmod scsi_debug"
disk_check_cmd = "ls -1d /dev/nvme* || ls -1d /dev/sda*"
image_stg_blacklist = "/dev/sda[\d]* /dev/sg0"
disk_create_cmd = "modprobe -r scsi_debug; modprobe sg; modprobe scsi_debug add_host=9 dev_size_mb=50"
disk_check_cmd = "ls /dev/s[dg]* -1A"
stg_params += "image_raw_device:yes "
stg_params += "image_format:raw "
stg_params += "indirect_image_select:range(-9,0) "
Expand Down
31 changes: 24 additions & 7 deletions qemu/tests/multi_disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,17 @@ def _get_windows_disks_index(image_size):
disk_indexs.append(o[0])
return disk_indexs

def _find_create_images(ori_images, curr_images):
if len(curr_images) < len(ori_images):
curr_images, ori_images = ori_images, curr_images

curr_images = curr_images.split('\n')
ori_images = ori_images.split('\n')
create_images = [image + ' ' for image in curr_images if
image not in ori_images]
new_images = ''.join(create_images)
return new_images

def _get_data_disks():
if ostype == "windows":
error_context.context("Get windows disk index that to "
Expand Down Expand Up @@ -250,16 +261,22 @@ def _get_data_disks():
astring.tabular_output(param_table, param_table_header))
return

disk_check_cmd = params.get('disk_check_cmd')
indirect_image_blacklist = params.get('indirect_image_blacklist').split()
disk_check_cmd = params.get('disk_check_cmd', "")
disk_create_cmd = params.get("disk_create_cmd", "")

if disk_check_cmd:
image_stg_blacklist = params.get('image_stg_blacklist').split()
matching_images = process.run(disk_check_cmd, ignore_status=True,
shell=True).stdout_text
for disk in image_stg_blacklist:
if not re.search(disk, matching_images):
indirect_image_blacklist.remove(disk)
ori_images = process.run(disk_check_cmd, ignore_status=True,
shell=True).stdout_text
process.run(disk_create_cmd, ignore_status=True,
shell=True).stdout_text
curr_images = process.run(disk_check_cmd, ignore_status=True,
shell=True).stdout_text
new_images = _find_create_images(curr_images, ori_images)
import copy
for black_disk in copy.copy(indirect_image_blacklist):
if re.search(black_disk, new_images):
indirect_image_blacklist.remove(black_disk)
params["indirect_image_blacklist"] = " ".join(indirect_image_blacklist)

# Always recreate VMs and disks
Expand Down

0 comments on commit 1ac468b

Please sign in to comment.