Skip to content

Commit

Permalink
virtual_disks: stabilize tests on s390x
Browse files Browse the repository at this point in the history
On s390x, partition order under /cat/partitions might change
between boots, causing tests to fail in those cases.

Use instead information under /dev/disk/by-path which is unique.

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 27, 2023
1 parent 02aae6c commit 1e812a8
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 25 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
28 changes: 20 additions & 8 deletions libvirt/tests/src/virtual_disks/startup_policy.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import re
import logging as log
import platform
import shutil

import aexpect
Expand All @@ -23,6 +24,8 @@
# 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__)
get_parts_list_func = utils_disk.get_parts_list
parts_path = "/dev/%"


def run(test, params, env):
Expand All @@ -42,6 +45,11 @@ def run(test, params, env):
vm = env.get_vm(vm_name)
startup_policy = params.get("policy")

if "s390x" == platform.machine():
global parts_path, get_parts_list_func
parts_path = "/dev/disk/by-path/%s"
get_parts_list_func = utils_disk.get_parts_list_by_path

def create_iscsi_pool():
"""
Setup iSCSI target,and create one iSCSI pool.
Expand Down Expand Up @@ -165,16 +173,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 = get_parts_list_func(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 +194,14 @@ 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 ('sr' not in added_part
and 'fd' not in added_part
and device_type != "cdrom"):

cmd = ("fdisk -l {0} && mkfs.ext4 -F {0} && "
"mkdir -p test && mount {0} test && echo"
" teststring > test/testfile && umount test"
.format(added_part))
.format(parts_path % 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 +354,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 = get_parts_list_func(session)
session.close()
vm.destroy(gracefully=False)

Expand Down Expand Up @@ -459,7 +471,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
21 changes: 14 additions & 7 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,9 @@
from virttest.utils_test import libvirt

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

get_parts_func = utils_disk.get_parts_list
get_added_parts_func = utils_disk.get_added_parts
part_path = "/dev/%"
cleanup_files = []


Expand All @@ -50,7 +52,7 @@ 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 = get_added_parts_func(session,old_partitions)
LOG.debug("Newly added partition(s) is: %s", added_partitions)
return added_partitions
except Exception as err:
Expand Down Expand Up @@ -113,8 +115,7 @@ def coldplug_disk(test, params, env):
def coldplug_save_restore(test, params, env):
"""
cold plug disk, save and restore VM in one session
:param test: test object
:param test: test object
:param params: one dictionary wrapping parameters
:param env: environment representing running context
"""
Expand Down Expand Up @@ -239,11 +240,17 @@ def run(test, params, env):
# Skip test if version not match expected one
libvirt_version.is_libvirt_feature_supported(params)

if 's390x' == platform.machine():
global get_parts_func, get_added_parts_func, part_path
get_parts_func = utils_disk.get_parts_list_by_path
get_added_parts_func = utils_disk.get_added_parts_by_path
part_path = "/dev/disk/by-path/%s"

# Get disk partitions info before hot/cold plug virtual disk
if vm.is_dead():
vm.start()
session = vm.wait_for_login()
old_partitions = utils_disk.get_parts_list(session)
old_partitions = get_parts_func(session)
session.close()
if not hotplug:
vm.destroy(gracefully=False)
Expand Down Expand Up @@ -289,10 +296,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
23 changes: 13 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,9 +20,9 @@
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__)
parts_path = "/dev/%s"
get_parts_func = utils_disk.get_parts_list


def run(test, params, env):
Expand Down Expand Up @@ -112,30 +112,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 = get_parts_func(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(parts_path % 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 @@ -172,11 +171,15 @@ def check_in_vm(target, old_parts):
# Initialize one NbdExport object
nbd = None

if 's390x' == platform.machine():
parts_path = "/dev/disk/by-path/%s"
get_parts_func = utils_disk.get_parts_list_by_path

# 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)
old_parts = get_parts_func(session)
session.close()
vm.destroy(gracefully=False)

Expand Down Expand Up @@ -278,7 +281,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 1e812a8

Please sign in to comment.