Skip to content

Commit

Permalink
Merge pull request #459 from vojtechtrefny/main_fs-selection-size-fix
Browse files Browse the repository at this point in the history
Do not allow selecting formats with that won't fit (#2318274)
  • Loading branch information
vojtechtrefny authored Oct 15, 2024
2 parents d072da6 + b9dbbe2 commit f839b2f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
11 changes: 9 additions & 2 deletions blivetgui/dialogs/add_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,12 +790,19 @@ def add_fs_chooser(self):

return filesystems_store, filesystems_combo

def _allow_format_size(self, fs):
# FIXME: also check raid level -- resulting "free space" might be lower because of redundancy
if self.selected_free.size < fs._min_size:
return False
if self.size_area and fs._max_size and self.size_area.min_size > fs._max_size:
return False
return True

def update_fs_chooser(self):
self.filesystems_store.clear()

for fs in self.supported_filesystems:
# FIXME: also check raid level -- resulting "free space" might be lower because of redundancy
if self.selected_free.size > fs._min_size:
if self._allow_format_size(fs):
self.filesystems_store.append((fs, fs.type, fs.name))
self.filesystems_store.append((None, "unformatted", _("unformatted")))

Expand Down
33 changes: 25 additions & 8 deletions tests/blivetgui_tests/add_dialog_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ def _get_free_device(self, size=Size("8 GiB"), logical=False, parent=None, **kwa
uninitialized_disk = kwargs.get("is_uninitialized_disk", False)

return MagicMock(type="free_space", size=size, is_logical=logical, parents=[parent], disk=parent,
is_free_region=free_region, is_empty_disk=empty_disk, is_uninitialized_disk=uninitialized_disk)
is_free_region=free_region, is_empty_disk=empty_disk, is_uninitialized_disk=uninitialized_disk,
min_size=kwargs.get("min_size", Size("1 MiB")))

def _get_parent_device(self, name=None, dtype="disk", size=Size("8 GiB"), ftype="disklabel"):
if not name:
Expand All @@ -261,17 +262,19 @@ def _get_parent_device(self, name=None, dtype="disk", size=Size("8 GiB"), ftype=
name = "fedora"

dev = MagicMock()
dev.configure_mock(name=name, type=dtype, size=size,
format=MagicMock(type=ftype,
sector_size=512,
parted_disk=MagicMock(maxPartitionLength=4294967295)))
if dtype != "disk":
dev.configure_mock(name=name, type=dtype, size=size)

if dtype == "disk":
dev.configure_mock(format=MagicMock(type=ftype,
sector_size=512,
parted_disk=MagicMock(maxPartitionLength=4294967295)))
else:
disk = self._get_parent_device()
dev.configure_mock(disk=disk, parents=[disk])
dev.configure_mock(disk=disk, parents=[disk], format=MagicMock(type=ftype))
if dtype == "lvmvg":
pv = MagicMock()
disk = self._get_parent_device()
pv.configure_mock(name="vda1", size=size, format=MagicMock(free=size), disk=disk, parents=[disk])
pv.configure_mock(name="vda1", size=size, format=MagicMock(type="lvmpv", free=size), disk=disk, parents=[disk])
dev.configure_mock(pe_size=Size("4 MiB"), free_space=size, pvs=[pv], parents=[pv],
pmspare_size=Size("4 MiB"))

Expand Down Expand Up @@ -559,6 +562,20 @@ def test_fs_chooser_biosboot(self):
add_dialog.filesystems_combo.set_active_id("ext4")
self.assertEqual(add_dialog.filesystems_combo.get_active_id(), "ext4")

# check that biosboot is not available when creating lv (rhbz#2318274)
parent_device = self._get_parent_device(dtype="lvmvg", ftype=None)
free_device = self._get_free_device(parent=parent_device, min_size=Size("4 MiB"))
_filesystems = self.supported_filesystems[:]
_filesystems.append(formats.biosboot.BIOSBoot())

add_dialog = AddDialog(self.parent_window, parent_device, free_device,
[("free", free_device)], _filesystems,
[])
add_dialog.devices_combo.set_active_id("lvmlv")

ret = add_dialog.filesystems_combo.set_active_id("biosboot")
self.assertFalse(ret)

def test_md_type(self):
parent_device = self._get_parent_device()
free_device = self._get_free_device(parent=parent_device)
Expand Down

0 comments on commit f839b2f

Please sign in to comment.