Skip to content

Commit

Permalink
virtual_disks: stabilize tests that check a new disk was added
Browse files Browse the repository at this point in the history
Partition names under /cat/partitions might change
between boots, causing tests to fail in those cases.

Use instead information under /dev/disk/by-path.

Furthermore,

virtual_disk_ndb: remove unused parameter

startupPolicy: disable floppy, sata - not available on s390x

Signed-off-by: Sebastian Mitterle <[email protected]>
  • Loading branch information
smitterl committed Jul 28, 2023
1 parent 02aae6c commit b695554
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 23 deletions.
2 changes: 2 additions & 0 deletions libvirt/tests/cfg/virtual_disks/startup_policy.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
aarch64:
disk_target_bus = "scsi"
- floppy:
no s390-virtio
device_type = "floppy"
target_dev = "fda"
disk_target_bus = "fdc"
Expand All @@ -78,6 +79,7 @@
target_dev = "vdb"
disk_target_bus = "virtio"
- sata_bus:
no s390-virtio
target_dev = "sdb"
disk_target_bus = "sata"
variants:
Expand Down
18 changes: 10 additions & 8 deletions libvirt/tests/src/virtual_disks/startup_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,17 @@ def create_disk_xml():
shutil.copyfile(disk_xml, disk_xml_file)
return disk_xml

def check_in_vm(old_parts):
def check_in_vm(old_parts, device_type):
"""
Check mount/read/write disk in VM.
:param old_parts: pre-operated partitions in VM.
:param device_type: test parameter, e.g. 'cdrom', 'floppy'
:return: True if check successfully.
"""
try:
session = vm.wait_for_login()
new_parts = utils_disk.get_parts_list(session)
new_parts = utils_disk.get_parts_list_by_path(session)
logging.debug("new parted:%s", new_parts)
added_parts = list(set(new_parts).difference(set(old_parts)))
logging.info("Added parts:%s", added_parts)
Expand All @@ -185,11 +186,12 @@ def check_in_vm(old_parts):
if not added_part:
logging.error("Can't see added partition in VM")
return False
if 'sr' not in added_part and 'fd' not in added_part:
cmd = ("fdisk -l /dev/{0} && mkfs.ext4 -F /dev/{0} && "
"mkdir -p test && mount /dev/{0} test && echo"
if device_type not in ["cdrom", "floppy"]:

cmd = ("fdisk -l {0} && mkfs.ext4 -F {0} && "
"mkdir -p test && mount {0} test && echo"
" teststring > test/testfile && umount test"
.format(added_part))
.format("/dev/disk/by-path/%s" % added_part))
status, output = session.cmd_status_output(cmd)
logging.info("Check disk operation in VM:\n%s", output)
if status != 0:
Expand Down Expand Up @@ -342,7 +344,7 @@ def rename_file(source_file, target_file, revert=False):
if vm.is_dead():
vm.start()
session = vm.wait_for_login()
old_parts = utils_disk.get_parts_list(session)
old_parts = utils_disk.get_parts_list_by_path(session)
session.close()
vm.destroy(gracefully=False)

Expand Down Expand Up @@ -459,7 +461,7 @@ def rename_file(source_file, target_file, revert=False):
# Step 1. Start domain and destroy it normally.
vm.start()
# Step 1 Start VM successfully.
if not check_in_vm(old_parts):
if not check_in_vm(old_parts, device_type):
test.fail("Check disk partitions in VM failed")

# Step 2 Destroy VM, move the volume to other place, refresh the pool, then start the guest.
Expand Down
11 changes: 6 additions & 5 deletions libvirt/tests/src/virtual_disks/virtual_disks_filedescriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
from virttest.utils_test import libvirt

LOG = logging.getLogger('avocado.' + __name__)

cleanup_files = []


Expand All @@ -50,7 +49,8 @@ def get_added_disks(old_partitions, test, params, env):
session = vm.wait_for_login()
if platform.platform().count('ppc64'):
time.sleep(10)
added_partitions = utils_disk.get_added_parts(session, old_partitions)
added_partitions = utils_disk.get_added_parts_by_path(session,
old_partitions)
LOG.debug("Newly added partition(s) is: %s", added_partitions)
return added_partitions
except Exception as err:
Expand Down Expand Up @@ -235,6 +235,7 @@ def run(test, params, env):
hotplug = "yes" == params.get("virt_device_hotplug")
pkgs_host = params.get("pkgs_host", "")
disk_readonly = params.get("disk_readonly", "no") == "yes"
part_path = "/dev/disk/by-path/%s"

# Skip test if version not match expected one
libvirt_version.is_libvirt_feature_supported(params)
Expand All @@ -243,7 +244,7 @@ def run(test, params, env):
if vm.is_dead():
vm.start()
session = vm.wait_for_login()
old_partitions = utils_disk.get_parts_list(session)
old_partitions = utils_disk.get_parts_list_by_path(session)
session.close()
if not hotplug:
vm.destroy(gracefully=False)
Expand Down Expand Up @@ -289,10 +290,10 @@ def run(test, params, env):
if platform.platform().count('ppc64'):
time.sleep(10)
if disk_readonly:
if libvirt_disk.check_virtual_disk_io(vm, new_disk):
if libvirt_disk.check_virtual_disk_io(vm, new_disk, path=part_path):
test.fail("Expect the newly added disk is not writable, but actually it is")
else:
if not libvirt_disk.check_virtual_disk_io(vm, new_disk):
if not libvirt_disk.check_virtual_disk_io(vm, new_disk, path=part_path):
test.fail("Cannot operate the newly added disk in vm.")
virsh.detach_device(vm_name, device_obj.xml, flagstr="--live",
debug=True, ignore_status=False)
Expand Down
17 changes: 7 additions & 10 deletions libvirt/tests/src/virtual_disks/virtual_disks_nbd.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
from virttest.libvirt_xml.devices.disk import Disk


# Using as lower capital is not the best way to do, but this is just a
# workaround to avoid changing the entire file.
logging = log.getLogger('avocado.' + __name__)


Expand Down Expand Up @@ -112,30 +110,29 @@ def _check_file_create(filename):
% snapshot_name2)
_check_file_create("mem.txt")

def check_in_vm(target, old_parts):
def check_in_vm(old_parts):
"""
Check mount/read/write disk in VM.
:param target: Disk dev in VM.
:param old_parts: Original disk partitions in VM.
:return: True if check successfully.
"""
try:
session = vm.wait_for_login()
if platform.platform().count('ppc64'):
time.sleep(10)
new_parts = utils_disk.get_parts_list(session)
new_parts = utils_disk.get_parts_list_by_path(session)
added_parts = list(set(new_parts).difference(set(old_parts)))
logging.info("Added parts:%s", added_parts)
if len(added_parts) != 1:
logging.error("The number of new partitions is invalid in VM")
return False
else:
added_part = added_parts[0]
cmd = ("fdisk -l /dev/{0} && mkfs.ext4 -F /dev/{0} && "
"mkdir -p test && mount /dev/{0} test && echo"
cmd = ("fdisk -l {0} && mkfs.ext4 -F {0} && "
"mkdir -p test && mount {0} test && echo"
" teststring > test/testfile && umount test"
.format(added_part))
.format("/dev/disk/by-path/%s" % added_part))
status, output = session.cmd_status_output(cmd)
logging.debug("Disk operation in VM:\nexit code:\n%s\noutput:\n%s",
status, output)
Expand Down Expand Up @@ -176,7 +173,7 @@ def check_in_vm(target, old_parts):
if vm.is_dead():
vm.start()
session = vm.wait_for_login()
old_parts = utils_disk.get_parts_list(session)
old_parts = utils_disk.get_parts_list_by_path(session)
session.close()
vm.destroy(gracefully=False)

Expand Down Expand Up @@ -278,7 +275,7 @@ def check_in_vm(target, old_parts):
if check_partitions and not status_error:
logging.debug("wait seconds for starting in checking vm part")
time.sleep(2)
if not check_in_vm(device_target, old_parts):
if not check_in_vm(old_parts):
test.fail("Check disk partitions in VM failed")
# Check snapshot operation and its result
if domain_operation == 'snap_shot':
Expand Down

0 comments on commit b695554

Please sign in to comment.