Skip to content

Commit

Permalink
size_chooser: Add support for overprovisioned devices
Browse files Browse the repository at this point in the history
Currently the max size is limited by the sum of parent devices
sizes. Stratis filesystems are first devices where we support
overprovisioning (Stratis filesystem is always 1 TiB) so we need
a special exception for them.
  • Loading branch information
vojtechtrefny committed Apr 8, 2021
1 parent 107623c commit 5920fa1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
22 changes: 17 additions & 5 deletions blivetgui/dialogs/size_chooser.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class SizeArea(GUIWidget):
name = "size area"
glade_file = "size_area.ui"

def __init__(self, device_type, parents, min_limit, max_limit, raid_type):
def __init__(self, device_type, parents, min_limit, max_limit, raid_type, overprovisioning=False):
"""
:param device_type: type of device we are creating
:param parents: list of available/selected parents
Expand All @@ -89,6 +89,7 @@ def __init__(self, device_type, parents, min_limit, max_limit, raid_type):

self._min_size_limit = min_limit
self._max_size_limit = max_limit
self._overprovisioning = overprovisioning

# "main" size chooser
self.main_chooser = SizeChooser(max_size=self.max_size, min_size=self.min_size)
Expand Down Expand Up @@ -157,7 +158,10 @@ def max_size(self):
parents, raid level and limits for the newly created device
"""
if self._parent_area is None:
return min(sum(parent.max_size for parent in self.parents), self.max_size_limit)
if self._overprovisioning:
return self.max_size_limit
else:
return min(sum(parent.max_size for parent in self.parents), self.max_size_limit)
else:
return self._parent_area.total_max

Expand Down Expand Up @@ -223,10 +227,18 @@ def get_selection(self):
them (either specified by user or just fraction of total size)
"""
if self._parent_area is None:
# no advanced selection -> we will use all available parents and set
# same size for each of them and return total selected size
total_size = self.main_chooser.selected_size
parents = self._get_parents_allocation()

if self._overprovisioning:
# with overprovisioning parent allocation doesn't really make sense
parents = [ParentSelection(parent_device=p.device,
free_space=size.Size(0),
selected_size=total_size) for p in self.parents]
else:
# no advanced selection -> we will use all available parents and set
# same size for each of them and return total selected size
parents = self._get_parents_allocation()

return SizeSelection(total_size=total_size, parents=parents)
else:
# selection is handled by the parent area
Expand Down
22 changes: 22 additions & 0 deletions tests/blivetgui_tests/size_widgets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,28 @@ def test_70_parent_allocation(self):
selected_sizes = [r.selected_size for r in ret]
self.assertListEqual(selected_sizes, [Size(1), Size(2)])

def test_75_parent_allocation_overprovisioning(self):
""" Test allocating size on parents without ParentArea with overprovisioning """

# -- same size parents
parents = [MagicMock(device=self._mock_device(), min_size=Size("1 MiB"), max_size=Size("1 GiB"),
reserved_size=Size(0)),
MagicMock(device=self._mock_device(), min_size=Size("1 MiB"), max_size=Size("1 GiB"),
reserved_size=Size(0))]

size_area = SizeArea(device_type="lvm", parents=parents,
min_limit=Size(1), max_limit=Size("200 GiB"),
raid_type=None, overprovisioning=True)

# select maximum (bigger than parents) --> both parents should have max_limit selected
size_area.main_chooser.selected_size = Size("200 GiB")
ret = size_area.get_selection()
self.assertEqual(len(ret.parents), 2)
self.assertEqual(ret.parents[0].parent_device, parents[0].device)
self.assertEqual(ret.parents[0].selected_size, Size("200 GiB"))
self.assertEqual(ret.parents[1].parent_device, parents[1].device)
self.assertEqual(ret.parents[1].selected_size, Size("200 GiB"))


@unittest.skipUnless("DISPLAY" in os.environ.keys(), "requires X server")
class ParentAreaTest(unittest.TestCase):
Expand Down

0 comments on commit 5920fa1

Please sign in to comment.