Skip to content

Commit

Permalink
virtual_disks_multivms: fix disk discovery
Browse files Browse the repository at this point in the history
The tests used the disk target as identifier for the
disk inside of the VM. However, the target is not guaranteed
to show up in the guest as-is, especially given that the
/dev/XdY paths are not persistent and can change between boots.

Use instead a function that identifies a new disk inside of a VM
as the one disk that has no root mount on itself, its partitions
or volumes.

Finally, the `delete_scsi_disk` doesn't return any value so it
was always looping for the full timeout. Wrap it into a function
that confirms if both the module and device have been removed.

Signed-off-by: Sebastian Mitterle <[email protected]>
  • Loading branch information
smitterl authored and libvirt-qe committed Dec 12, 2023
1 parent 2f83bc8 commit ef3a7e9
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions libvirt/tests/src/virtual_disks/virtual_disks_multivms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import logging as log
import aexpect
import time

from avocado.utils import process

Expand All @@ -11,6 +12,7 @@
from virttest import remote
from virttest import utils_disk
from virttest import utils_misc
from virttest.utils_libvirt.libvirt_disk import get_non_root_disk_name
from virttest.utils_test import libvirt
from virttest.libvirt_xml import vm_xml
from virttest.libvirt_xml.devices.disk import Disk
Expand All @@ -36,6 +38,19 @@ def run(test, params, env):
6.Confirm the test result.
"""

def _delete_scsi_disk():
""" Helper function for wait_for in finally """
libvirt.delete_scsi_disk()
cmd = "lsscsi|grep scsi_debug"
s1, _ = utils_misc.cmd_status_output(cmd,
shell=True,
ignore_status=False)
cmd = "lsmod|grep scsi_debug"
s2, _ = utils_misc.cmd_status_output(cmd,
shell=True,
ignore_status=False)
return s1 + s2 == 2

def set_vm_controller_xml(vmxml):
"""
Set VM scsi controller xml.
Expand Down Expand Up @@ -239,7 +254,8 @@ def get_vm_disk_xml(dev_type, dev_name, **options):
test.fail('Failed to hotplug disk device')
elif 0 == result and not vms_list[i]['status']:
test.fail('Hotplug disk device unexpectedly.')

time.sleep(5)
added_disk, _ = get_non_root_disk_name(session)
# Check disk error_policy option in VMs.
if test_error_policy:
error_policy = vms_list[i]['disk'].driver["error_policy"]
Expand All @@ -248,7 +264,7 @@ def get_vm_disk_xml(dev_type, dev_name, **options):
if error_policy == "enospace":
cmd = ("mount /dev/%s /mnt && dd if=/dev/zero of=/mnt/test"
" bs=1M count=2000 2>&1 | grep 'No space left'"
% disk_target)
% added_disk)
s, o = session.cmd_status_output(cmd)
logging.debug("error_policy in vm0 exit %s; output: %s", s, o)
if 0 != s:
Expand All @@ -258,15 +274,15 @@ def get_vm_disk_xml(dev_type, dev_name, **options):
break

if session.cmd_status("fdisk -l /dev/%s && mount /dev/%s /mnt; ls /mnt"
% (disk_target, disk_target)):
% (added_disk, added_disk)):
session.close()
test.fail("Test error_policy: "
"failed to mount disk")
if i == 1:
try:
session0 = vms_list[0]['vm'].wait_for_login(timeout=10)
cmd = ("fdisk -l /dev/%s && mkfs.ext3 -F /dev/%s "
% (disk_target, disk_target))
% (added_disk, added_disk))
s, o = session.cmd_status_output(cmd)
logging.debug("error_policy in vm1 exit %s; output: %s", s, o)
session.close()
Expand Down Expand Up @@ -312,9 +328,10 @@ def _check_error():
test_str = "teststring"
# Try to write on vm0.
session0 = vms_list[0]['vm'].wait_for_login(timeout=10)
added_disk0, _ = get_non_root_disk_name(session0)
cmd = ("fdisk -l /dev/%s && mount /dev/%s /mnt && echo '%s' "
"> /mnt/test && umount /mnt"
% (disk_target, disk_target, test_str))
% (added_disk0, added_disk0, test_str))
s, o = session0.cmd_status_output(cmd)
logging.debug("session in vm0 exit %s; output: %s", s, o)
if s:
Expand All @@ -323,7 +340,7 @@ def _check_error():
# Try to read on vm1.
cmd = ("fdisk -l /dev/%s && mount /dev/%s /mnt && grep %s"
" /mnt/test && umount /mnt"
% (disk_target, disk_target, test_str))
% (added_disk, added_disk, test_str))
s, o = session.cmd_status_output(cmd)
logging.debug("session in vm1 exit %s; output: %s", s, o)
if s:
Expand Down Expand Up @@ -377,7 +394,7 @@ def _check_error():
for img in disks:
if 'format' in img:
if img["format"] == "scsi":
utils_misc.wait_for(libvirt.delete_scsi_disk,
utils_misc.wait_for(_delete_scsi_disk,
120, ignore_errors=True)
elif img["format"] == "iscsi":
libvirt.setup_or_cleanup_iscsi(is_setup=False)
Expand Down

0 comments on commit ef3a7e9

Please sign in to comment.