Skip to content

Commit

Permalink
Add one scsi device case
Browse files Browse the repository at this point in the history
xx-186123: [Host device assignment][SCSI] Hot-plug the same scsi device to two guests with shareable element

Signed-off-by: chunfuwen <[email protected]>
  • Loading branch information
chunfuwen committed Aug 4, 2023
1 parent e585ee5 commit a5eb249
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 9 deletions.
3 changes: 3 additions & 0 deletions libvirt/tests/cfg/scsi/scsi_device.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
type = scsi_device
status_error = "no"
start_vm = "no"
vms = avocado-vt-vm1 vm1
variants scsi_type:
- scsi_hostdev:
variants:
Expand All @@ -28,6 +29,8 @@
controller_type = "scsi"
controller_model = "virtio-scsi"
controller_index = "0"
- shared_by_two_guests:
only hotplug
- negative:
variants test_scenario:
- max_sectors_controller:
Expand Down
66 changes: 57 additions & 9 deletions libvirt/tests/src/scsi/scsi_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,42 @@ def check_scsi_controller(test, params, env):
test.fail("Get index=0 scsi controller although detached")


def test_hotplug_scsi_hostdev_shared_by_two_guests(test, params, env):
"""
Test hotplug scsi device into two guests
:param test: one test object instance
:param params: dict wrapped with params
:param env: environment instance
"""
block_device1 = setup_iscsi_block_device()
hostdev_xml = create_host_dev(params, block_device1)
hostdev_xml.shareable = True
vm_names = params.get("vms").split()
for vm_name in vm_names:
vm = env.get_vm(vm_name)
if vm.is_dead():
vm.start()
vm.wait_for_login().close()
virsh.attach_device(vm_name, hostdev_xml.xml, flagstr="--live",
ignore_status=False)


def check_hostdev_shareable_attr(test, params, env):
"""
check scsi shareable attribute
:param test: one test object instance
:param params: dict wrapped with params
:param env: environment instance
"""
vm_names = params.get("vms").split()
for vm_name in vm_names:
vm_output = virsh.dumpxml(vm_name).stdout_text
if 'shareable' not in vm_output:
test.fail("VM: % failed to find shareable attribute in output: %s" % (vm_name, vm_output))


def run(test, params, env):
"""
Test manipulate scsi device.
Expand All @@ -443,13 +479,21 @@ def run(test, params, env):
vm_name = params.get("main_vm")
vm = env.get_vm(vm_name)

# Back up xml file
if vm.is_alive():
vm.destroy(gracefully=False)
vm_names = params.get("vms").split()
if len(vm_names) < 2:
test.cancel("No multi vms provided.")

# Backup vm xml files.
vms_backup = []
# it need use 2 VMs for testing.
for i in list(range(2)):
if virsh.is_alive(vm_name[i]):
virsh.destroy(vm_name[i], gracefully=False)
vmxml_backup = vm_xml.VMXML.new_from_inactive_dumpxml(vm_names[i])
vms_backup.append(vmxml_backup)

coldplug = "yes" == params.get("coldplug")
define_error = "yes" == params.get("define_error", "no")
xml_backup = vm_xml.VMXML.new_from_inactive_dumpxml(vm_name)

plug_mode = params.get("plug_mode")
scsi_type = params.get("scsi_type")
Expand Down Expand Up @@ -486,12 +530,16 @@ def run(test, params, env):
check_vdisk_hostdev_address_unit(test, params, env)
elif test_scenario == "unplug_scsi_controller":
check_scsi_controller(test, params, env)
elif test_scenario == "shared_by_two_guests":
check_hostdev_shareable_attr(test, params, env)
finally:
# Recover VM.
if vm.is_alive():
vm.destroy(gracefully=False)
LOG.info("Restoring vm...")
xml_backup.sync()
# Recover VMs.
for i in list(range(2)):
if virsh.is_alive(vm_name[i]):
virsh.destroy(vm_name[i], gracefully=False)
LOG.info("Restoring vms...")
for vmxml_backup in vms_backup:
vmxml_backup.sync()
# Delete the tmp files.
libvirt.setup_or_cleanup_iscsi(is_setup=False)
if test_scenario == "boot_order":
Expand Down

0 comments on commit a5eb249

Please sign in to comment.