Skip to content

Commit ef3a7e9

Browse files
smitterllibvirt-qe
authored andcommitted
virtual_disks_multivms: fix disk discovery
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]>
1 parent 2f83bc8 commit ef3a7e9

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

libvirt/tests/src/virtual_disks/virtual_disks_multivms.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import logging as log
33
import aexpect
4+
import time
45

56
from avocado.utils import process
67

@@ -11,6 +12,7 @@
1112
from virttest import remote
1213
from virttest import utils_disk
1314
from virttest import utils_misc
15+
from virttest.utils_libvirt.libvirt_disk import get_non_root_disk_name
1416
from virttest.utils_test import libvirt
1517
from virttest.libvirt_xml import vm_xml
1618
from virttest.libvirt_xml.devices.disk import Disk
@@ -36,6 +38,19 @@ def run(test, params, env):
3638
6.Confirm the test result.
3739
"""
3840

41+
def _delete_scsi_disk():
42+
""" Helper function for wait_for in finally """
43+
libvirt.delete_scsi_disk()
44+
cmd = "lsscsi|grep scsi_debug"
45+
s1, _ = utils_misc.cmd_status_output(cmd,
46+
shell=True,
47+
ignore_status=False)
48+
cmd = "lsmod|grep scsi_debug"
49+
s2, _ = utils_misc.cmd_status_output(cmd,
50+
shell=True,
51+
ignore_status=False)
52+
return s1 + s2 == 2
53+
3954
def set_vm_controller_xml(vmxml):
4055
"""
4156
Set VM scsi controller xml.
@@ -239,7 +254,8 @@ def get_vm_disk_xml(dev_type, dev_name, **options):
239254
test.fail('Failed to hotplug disk device')
240255
elif 0 == result and not vms_list[i]['status']:
241256
test.fail('Hotplug disk device unexpectedly.')
242-
257+
time.sleep(5)
258+
added_disk, _ = get_non_root_disk_name(session)
243259
# Check disk error_policy option in VMs.
244260
if test_error_policy:
245261
error_policy = vms_list[i]['disk'].driver["error_policy"]
@@ -248,7 +264,7 @@ def get_vm_disk_xml(dev_type, dev_name, **options):
248264
if error_policy == "enospace":
249265
cmd = ("mount /dev/%s /mnt && dd if=/dev/zero of=/mnt/test"
250266
" bs=1M count=2000 2>&1 | grep 'No space left'"
251-
% disk_target)
267+
% added_disk)
252268
s, o = session.cmd_status_output(cmd)
253269
logging.debug("error_policy in vm0 exit %s; output: %s", s, o)
254270
if 0 != s:
@@ -258,15 +274,15 @@ def get_vm_disk_xml(dev_type, dev_name, **options):
258274
break
259275

260276
if session.cmd_status("fdisk -l /dev/%s && mount /dev/%s /mnt; ls /mnt"
261-
% (disk_target, disk_target)):
277+
% (added_disk, added_disk)):
262278
session.close()
263279
test.fail("Test error_policy: "
264280
"failed to mount disk")
265281
if i == 1:
266282
try:
267283
session0 = vms_list[0]['vm'].wait_for_login(timeout=10)
268284
cmd = ("fdisk -l /dev/%s && mkfs.ext3 -F /dev/%s "
269-
% (disk_target, disk_target))
285+
% (added_disk, added_disk))
270286
s, o = session.cmd_status_output(cmd)
271287
logging.debug("error_policy in vm1 exit %s; output: %s", s, o)
272288
session.close()
@@ -312,9 +328,10 @@ def _check_error():
312328
test_str = "teststring"
313329
# Try to write on vm0.
314330
session0 = vms_list[0]['vm'].wait_for_login(timeout=10)
331+
added_disk0, _ = get_non_root_disk_name(session0)
315332
cmd = ("fdisk -l /dev/%s && mount /dev/%s /mnt && echo '%s' "
316333
"> /mnt/test && umount /mnt"
317-
% (disk_target, disk_target, test_str))
334+
% (added_disk0, added_disk0, test_str))
318335
s, o = session0.cmd_status_output(cmd)
319336
logging.debug("session in vm0 exit %s; output: %s", s, o)
320337
if s:
@@ -323,7 +340,7 @@ def _check_error():
323340
# Try to read on vm1.
324341
cmd = ("fdisk -l /dev/%s && mount /dev/%s /mnt && grep %s"
325342
" /mnt/test && umount /mnt"
326-
% (disk_target, disk_target, test_str))
343+
% (added_disk, added_disk, test_str))
327344
s, o = session.cmd_status_output(cmd)
328345
logging.debug("session in vm1 exit %s; output: %s", s, o)
329346
if s:
@@ -377,7 +394,7 @@ def _check_error():
377394
for img in disks:
378395
if 'format' in img:
379396
if img["format"] == "scsi":
380-
utils_misc.wait_for(libvirt.delete_scsi_disk,
397+
utils_misc.wait_for(_delete_scsi_disk,
381398
120, ignore_errors=True)
382399
elif img["format"] == "iscsi":
383400
libvirt.setup_or_cleanup_iscsi(is_setup=False)

0 commit comments

Comments
 (0)