Skip to content

Commit

Permalink
attach_detach_disk: fix disk discovery
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
smitterl committed Feb 8, 2024
1 parent 1a7880a commit 7b47a59
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions libvirt/tests/src/virsh_cmd/domain/virsh_attach_detach_disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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":
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7b47a59

Please sign in to comment.