Skip to content

Commit

Permalink
Merge pull request #655 from KKoukiou/udevadm_settle_tests
Browse files Browse the repository at this point in the history
tests: some stabilization changes
  • Loading branch information
KKoukiou authored Mar 3, 2025
2 parents 215a400 + 497700b commit 9906e26
Show file tree
Hide file tree
Showing 16 changed files with 394 additions and 264 deletions.
20 changes: 20 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,24 @@ ignore_names = [
"setUpClass",
"machine_class",
"wait_poweroff",
"_testBasic_partition_disk",
"_testBtrfsSubvolumes_partition_disk",
"_testDiskSelectionLVM_partition_disk",
"_testDuplicateDeviceNames_partition_disk",
"_testEncryptedUnlockBTRFSonLUKS_partition_disk",
"_testEncryptedUnlockLUKSonRAID_partition_disk",
"_testEncryptedUnlockRAIDonLUKS_partition_disk",
"_testEncryptedUnlock_partition_disk",
"_testExtendedPartitionEFI_partition_disk",
"_testHomeReuseFedoraEncrypted_partition_disk",
"_testLVMOnRAID_partition_disk",
"_testLVM_partition_disk",
"_testMultipleDisks_partition_disk",
"_testMultipleRoots_partition_disk",
"_testNoRootMountPoint_partition_disk",
"_testReclaimExt4onLUKS_partition_disk",
"_testReclaimSpaceDeleteBtrfsSubvolumes_partition_disk",
"_testReclaimSpaceOptional_partition_disk",
"_testReclaimSpaceShrinkBtrfsSubvolumes_partition_disk",
"_testUnusableFormats_partition_disk",
]
81 changes: 63 additions & 18 deletions test/anacondalib.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from machine_install import VirtInstallMachine
from progress import Progress
from storage import Storage
from testlib import MachineCase # pylint: disable=import-error
from testlib import MachineCase, wait # pylint: disable=import-error
from users import Users
from utils import add_public_key

Expand All @@ -42,13 +42,15 @@
class VirtInstallMachineCase(MachineCase):
# The boot modes in which the test should run
boot_modes = ["bios"]
disk_image = ""
disk_size = 15
is_efi = os.environ.get("TEST_FIRMWARE", "bios") == "efi"
report_to_wiki = os.path.exists(os.path.join(TEST_DIR, "report.json"))
MachineCase.machine_class = VirtInstallMachine
report_file = os.path.join(TEST_DIR, "report.json")

def partition_disk(self):
""" Override this method to partition the disk """
pass

@property
def temp_dir(self):
"""Get temp directory for libvirt resources
Expand All @@ -73,6 +75,10 @@ def setUp(self):
openqa_test = getattr(method, "openqa_test", "")
wikictms_section = getattr(method, "wikictms_section", "")
boot_modes = getattr(method, "boot_modes", ["bios"])
self.disk_images = getattr(method, "disk_images", [("", 15)])

partition_disk_method_name = "_" + self._testMethodName + "_partition_disk"
self.partition_disk = getattr(self, partition_disk_method_name, self.partition_disk)

if self.is_efi and "efi" not in boot_modes:
self.skipTest("Skipping for EFI boot mode")
Expand All @@ -91,20 +97,23 @@ def setUp(self):

super().setUp()

# Add installation target disk
backing_file = None if not self.disk_image else os.path.join(BOTS_DIR, f"./images/{self.disk_image}")
self.add_disk(self.disk_size, backing_file)
# Select the disk as boot device
subprocess.check_call([
"virt-xml", "-c", "qemu:///session",
self.machine.label, "--edit", "--boot", "hd"
])

m = self.machine
b = self.browser
s = Storage(b, m)

self.addAllDisks()
s.udevadm_settle()

# Wait for minimum /dev/vda to be detected before proceeding
wait(lambda: "vda" in m.execute("ls /dev"), tries=5, delay=5)

self.partition_disk()

s.dbus_scan_devices()

# Set the first disk as the installation target
s.dbus_set_selected_disk("vda")

self.resetLanguage()

self.allow_journal_messages('.*cockpit.bridge-WARNING: Could not start ssh-agent.*')
Expand All @@ -115,16 +124,13 @@ def setUp(self):
self.allow_browser_errors(".*client closed.*")
self.allow_browser_errors(".*Server has closed the connection.*")

def add_disk(self, size, backing_file=None):
def add_disk(self, size, backing_file=None, target="vda"):
image = self._create_disk_image(size, backing_file=backing_file)
subprocess.check_call([
"virt-xml", "-c", "qemu:///session", self.machine.label,
"--update", "--add-device", "--disk", f"{image},format=qcow2"
"--update", "--add-device", "--disk", f"{image},format=qcow2,target={target}"
])

if self.is_nondestructive():
self.addCleanup(self.rem_disk, image)

return image

def rem_disk(self, disk):
Expand Down Expand Up @@ -162,13 +168,40 @@ def resetUsers(self):
users = Users(b, m)
users.dbus_clear_users()

def addAllDisks(self):
# Add installation target disks
for index, (disk, size) in enumerate(self.disk_images):
target = "vd" + chr(97 + index) # vd[a-z]
backing_file = None if not disk else os.path.join(BOTS_DIR, f"./images/{disk}")
self.add_disk(size, backing_file, target)

# Select the disk as boot device
subprocess.check_call([
"virt-xml", "-c", "qemu:///session",
self.machine.label, "--edit", "--boot", "hd"
])

def removeAllDisks(self):
# Remove all disks
domblklist = subprocess.getoutput(
f"virsh domblklist {self.machine.label}",
)
for line in domblklist.splitlines():
name = line.split()[0]
if "vd" in name:
file = line.split()[1]
self.rem_disk(file)

def resetStorage(self):
# Ensures that anaconda has the latest storage configuration data
m = self.machine
b = self.browser
s = Storage(b, m)

self.removeAllDisks()
s.dbus_reset_partitioning()
# Create an AUTOMATIC partitioning because MANUAL partitioning tests might take the last created
s.dbus_create_partitioning("AUTOMATIC")
s.dbus_reset_selected_disks()
# CLEAR_PARTITIONS_DEFAULT = -1
s.dbus_set_initialization_mode(-1)
Expand Down Expand Up @@ -242,7 +275,7 @@ def install(self, needs_confirmation, button_text="Install"):
# This should be removed from the test
if self.is_efi:
# Add efibootmgr entry for the second OS
distro_name = self.disk_image.split("-")[0]
distro_name = self.disk_images[0][0].split("-")[0]
m.execute(f"efibootmgr -c -d /dev/vda -p 15 -L {distro_name} -l '/EFI/{distro_name}/shimx64.efi'")
# Select the Fedora grub entry for first boot
m.execute("efibootmgr -n 0001")
Expand Down Expand Up @@ -304,3 +337,15 @@ def decorator(func):
func.boot_modes = list(modes)
return func
return decorator

def disk_images(disks):
"""
Decorator to add installation target disks to the test.
:param disks: List of tuples with disk image OS to be used as backing file and size in GB.
If the disk image OS is not provided an empty disk will be created.
"""
def decorator(func):
func.disk_images = list(disks)
return func
return decorator
28 changes: 13 additions & 15 deletions test/check-storage-basic
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import os

from anacondalib import VirtInstallMachineCase, pixel_tests_ignore
from anacondalib import VirtInstallMachineCase, disk_images, pixel_tests_ignore
from installer import Installer
from storage import Storage
from testlib import nondestructive, test_main # pylint: disable=import-error
Expand Down Expand Up @@ -52,8 +52,8 @@ class TestStorage(VirtInstallMachineCase):
# However, since the storage module initialization is long completed
# the newly added disk, will not be visible in the UI,
# until the test clicks on the re-scan button
self.add_disk(2)
dev = "vdb"
self.add_disk(2, target=dev)
s.rescan_disks(["vda", dev])

# Check that the disk selection persists when moving next and back
Expand Down Expand Up @@ -183,21 +183,11 @@ class TestStorage(VirtInstallMachineCase):
b.wait_in_text("#critical-error-bz-report-modal-details", "Unexpected storage JS error")
b.wait_in_text("#critical-error-bz-report-modal header", "The installer cannot continue due to a critical error: Storage plugin failed")

@nondestructive
class TestStorageMultipleDisks(VirtInstallMachineCase):

def testDiskSelectionLVM(self):
"""
Test that the user can't select one PV when VG group spans across multiple disks
"""

def _testDiskSelectionLVM_partition_disk(self):
b = self.browser
m = self.machine
i = Installer(b, m)
s = Storage(b, m)

self.add_disk(15)

s.partition_disk("/dev/vda", [("10GB", "lvmpv")])
s.partition_disk("/dev/vdb", [("10GB", "lvmpv")])

Expand All @@ -209,9 +199,17 @@ class TestStorageMultipleDisks(VirtInstallMachineCase):
vgchange -a n vg
""")

@disk_images([("", 15), ("", 15)])
def testDiskSelectionLVM(self):
"""
Test that the user can't select one PV when VG group spans across multiple disks
"""

b = self.browser
m = self.machine
i = Installer(b, m)

i.open()
i.reach(i.steps.INSTALLATION_METHOD)
s.rescan_disks()
i.reach(i.steps.STORAGE_CONFIGURATION)
i.next(should_fail=True)
b.wait_in_text(
Expand Down
6 changes: 3 additions & 3 deletions test/check-storage-erase-all
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program; If not, see <http://www.gnu.org/licenses/>.

from anacondalib import VirtInstallMachineCase
from anacondalib import VirtInstallMachineCase, disk_images
from installer import Installer
from operating_systems import WindowsOS
from review import Review
Expand All @@ -24,8 +24,8 @@ from testlib import nondestructive, test_main # pylint: disable=import-error

@nondestructive
class TestStorageEraseAll_Fedora(VirtInstallMachineCase):
disk_image = "fedora-rawhide"

@disk_images([("fedora-rawhide", 15)])
def testBasic(self):
b = self.browser
m = self.machine
Expand All @@ -44,12 +44,12 @@ class TestStorageEraseAll_Fedora(VirtInstallMachineCase):

@nondestructive
class TestStorageEraseAll_Windows(VirtInstallMachineCase):
disk_size = 20

def setUp(self):
super().setUp()
WindowsOS(machine=self.machine, browser=self.browser).partition_disk()

@disk_images([("", 20)])
def testBasic(self):
b = self.browser
m = self.machine
Expand Down
10 changes: 3 additions & 7 deletions test/check-storage-erase-all-e2e
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import os

from anacondalib import VirtInstallMachineCase
from anacondalib import VirtInstallMachineCase, disk_images
from installer import Installer
from password import Password
from progress import Progress
Expand Down Expand Up @@ -71,6 +71,7 @@ class TestStorageEraseAll_E2E(VirtInstallMachineCase):
vda3_root = next(part for part in vda3_luks["children"] if "/" in part["mountpoints"])
self.assertEqual(vda3_root["size"], "14G")

@disk_images([("", 15), ("debian-stable", 15)])
def testGuidedMultiSelect(self):
b = self.browser
m = self.machine
Expand All @@ -79,11 +80,8 @@ class TestStorageEraseAll_E2E(VirtInstallMachineCase):
r = Review(b, m)
p = Progress(b)

self.add_disk(15, os.path.join(BOTS_DIR, "./images/debian-stable"))

i.open()
i.reach(i.steps.INSTALLATION_METHOD)
s.rescan_disks()

s.check_disk_selected("vda", True)
s.check_disk_selected("vdb", False)
Expand Down Expand Up @@ -117,6 +115,7 @@ class TestStorageEraseAll_E2E(VirtInstallMachineCase):
# pretty_name = get_pretty_name(m)
# self.assertIn("Debian GNU/Linux", pretty_name)

@disk_images([("", 15), ("", 15)])
def testGuidedMultiEmptyAll(self):
b = self.browser
m = self.machine
Expand All @@ -125,11 +124,8 @@ class TestStorageEraseAll_E2E(VirtInstallMachineCase):
s = Storage(b, self.machine)
p = Progress(b)

self.add_disk(15)

i.open()
i.reach(i.steps.INSTALLATION_METHOD)
s.rescan_disks(["vda", "vdb"])

s.check_disk_selected("vda", True)
s.select_disks([("vdb", True), ("vda", True)])
Expand Down
Loading

0 comments on commit 9906e26

Please sign in to comment.