From 7b47a599750436ec3b05139fd4d193c8ea9e9376 Mon Sep 17 00:00:00 2001 From: Sebastian Mitterle Date: Thu, 8 Feb 2024 12:18:02 -0500 Subject: [PATCH] attach_detach_disk: fix disk discovery The code compared old and new listing of impersistent disk names, e.g. 'vdX'. Those names can change between reboots. Instead, use function to identify new disks that don't mount the root file system. The function raises an error if there is no such disk, so handle that to confirm that disks are detached correctly. Signed-off-by: Sebastian Mitterle --- .../domain/virsh_attach_detach_disk.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/libvirt/tests/src/virsh_cmd/domain/virsh_attach_detach_disk.py b/libvirt/tests/src/virsh_cmd/domain/virsh_attach_detach_disk.py index 82b16fc11f..52df542f75 100644 --- a/libvirt/tests/src/virsh_cmd/domain/virsh_attach_detach_disk.py +++ b/libvirt/tests/src/virsh_cmd/domain/virsh_attach_detach_disk.py @@ -5,6 +5,7 @@ import aexpect from avocado.utils import process +from avocado.core import exceptions from virttest import virt_vm from virttest import virsh @@ -15,7 +16,7 @@ from virttest.staging.service import Factory from virttest.staging import lv_utils from virttest.utils_libvirt import libvirt_pcicontr -from virttest import utils_disk +from virttest.utils_libvirt import libvirt_disk from virttest import utils_misc from virttest import data_dir from virttest import libvirt_version @@ -49,7 +50,7 @@ def check_info_in_audit_log_file(test_cmd, device_source): % device_source) return process.run(cmd, ignore_status=True, shell=True).exit_status == 0 - def check_vm_partition(vm, device, os_type, target_name, old_parts): + def check_vm_partition(vm, device, os_type, target_name): """ Check VM disk's partition. @@ -65,8 +66,12 @@ def check_vm_partition(vm, device, os_type, target_name, old_parts): attached = False if os_type == "linux": session = vm.wait_for_login() - new_parts = utils_disk.get_parts_list(session) - added_parts = list(set(new_parts).difference(set(old_parts))) + added_parts = [] + try: + added_disks = libvirt_disk.get_non_root_disk_names(session) + added_parts = [x[0] for x in added_disks] + except exceptions.TestError as e: + logging.debug(e) logging.debug("Added parts: %s" % added_parts) for i in range(len(added_parts)): if device == "disk": @@ -225,9 +230,6 @@ def _check_disk(target): # Start vm and get all partitions in vm. if vm.is_dead(): vm.start() - session = vm.wait_for_login() - old_parts = utils_disk.get_parts_list(session) - session.close() vm.destroy(gracefully=False) # Back up xml file. @@ -464,7 +466,7 @@ def _check_disk(target): # Check in VM after command. check_vm_after_cmd = True check_vm_after_cmd = check_vm_partition(vm, device, os_type, - device_target, old_parts) + device_target) # Check disk type after attach. check_disk_type = True