Skip to content

Commit

Permalink
storage: always accept to resize a partition that is being wiped
Browse files Browse the repository at this point in the history
If we are wiping a partition, don't bother checking if the filesystem that was
on it supports resizing. The filesystem is going to be erased anyway. The new
filesystem (if any) will be created using mkfs.* so there is no need for resize
support.

LP: #2096799

Signed-off-by: Olivier Gayot <[email protected]>
  • Loading branch information
ogayot committed Jan 27, 2025
1 parent ad2dd0a commit 394a697
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
8 changes: 6 additions & 2 deletions subiquity/common/filesystem/manipulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,13 @@ def reformat(self, disk, ptable=None, wipe=None):
self.delete_partition(p, True)
self.clear(disk, wipe)

def can_resize_partition(self, partition):
def can_resize_partition(self, partition, *, wipe=None):
# For a new partition.
if not partition.preserve:
return True
# For an existing partition that is being wiped.
if wipe is not None:
return True
if partition.format not in get_resize_fstypes():
return False
return True
Expand All @@ -297,7 +301,7 @@ def partition_disk_handler(
size_change = new_size - partition.size
if size_change > gap_size:
raise Exception("partition size too large")
if not self.can_resize_partition(partition):
if not self.can_resize_partition(partition, wipe=spec.get("wipe")):
raise Exception("partition cannot support resize")
partition.size = new_size
partition.resize = True
Expand Down
21 changes: 20 additions & 1 deletion subiquity/common/filesystem/tests/test_manipulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@

from subiquity.common.filesystem import boot, gaps, sizes
from subiquity.common.filesystem.actions import DeviceAction
from subiquity.common.filesystem.manipulator import FilesystemManipulator
from subiquity.common.filesystem.manipulator import (
FilesystemManipulator,
get_resize_fstypes,
)
from subiquity.models.filesystem import Bootloader, MiB, Partition
from subiquity.models.tests.test_filesystem import (
make_disk,
Expand Down Expand Up @@ -743,6 +746,22 @@ def test_resize_unpreserved(self):
part = make_partition(self.manipulator.model, disk, preserve=False)
self.assertTrue(self.manipulator.can_resize_partition(part))

def test_resize_non_resizable(self):
disk = make_disk(self.manipulator.model, ptable=None)
part = make_partition(self.manipulator.model, disk, preserve=True)
# If XFS becomes resizable, replace with something else.
self.assertNotIn("xfs", get_resize_fstypes())
make_filesystem(self.manipulator.model, partition=part, fstype="xfs")
self.assertFalse(self.manipulator.can_resize_partition(part))

def test_resize_non_resizable_but_wipe(self):
disk = make_disk(self.manipulator.model, ptable=None)
part = make_partition(self.manipulator.model, disk, preserve=True)
# If XFS becomes resizable, replace with something else.
self.assertNotIn("xfs", get_resize_fstypes())
make_filesystem(self.manipulator.model, partition=part, fstype="xfs")
self.assertTrue(self.manipulator.can_resize_partition(part, wipe="superblock"))

def test_resize_ext4(self):
disk = make_disk(self.manipulator.model, ptable=None)
part = make_partition(self.manipulator.model, disk, preserve=True)
Expand Down

0 comments on commit 394a697

Please sign in to comment.