Merge pull request #1205 from dbungert/partition-sizing

sizing: scaling funcs usage & constants
This commit is contained in:
Dan Bungert 2022-03-09 16:23:01 -07:00 committed by GitHub
commit 05310f2ffd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 19 deletions

View File

@ -39,10 +39,6 @@ from subiquity.ui.views.filesystem.probing import (
log = logging.getLogger("subiquity.client.controllers.filesystem") log = logging.getLogger("subiquity.client.controllers.filesystem")
BIOS_GRUB_SIZE_BYTES = 1 * 1024 * 1024 # 1MiB
PREP_GRUB_SIZE_BYTES = 8 * 1024 * 1024 # 8MiB
UEFI_GRUB_SIZE_BYTES = 512 * 1024 * 1024 # 512MiB EFI partition
class FilesystemController(SubiquityTuiController, FilesystemManipulator): class FilesystemController(SubiquityTuiController, FilesystemManipulator):

View File

@ -75,6 +75,16 @@ def scale_partitions(all_factors, disk_size):
return ret return ret
def get_efi_size(disk):
all_factors = (uefi_scale, bootfs_scale, rootfs_scale)
return scale_partitions(all_factors, disk.size)[0]
def get_bootfs_size(disk):
all_factors = (uefi_scale, bootfs_scale, rootfs_scale)
return scale_partitions(all_factors, disk.size)[1]
class FilesystemManipulator: class FilesystemManipulator:
def create_mount(self, fs, spec): def create_mount(self, fs, spec):
@ -138,14 +148,6 @@ class FilesystemManipulator:
self.clear(part) self.clear(part)
self.model.remove_partition(part) self.model.remove_partition(part)
def _get_efi_size(self, disk):
all_factors = (uefi_scale, bootfs_scale, rootfs_scale)
return scale_partitions(all_factors, disk.size)[0]
def _get_bootfs_size(self, disk):
all_factors = (uefi_scale, bootfs_scale, rootfs_scale)
return scale_partitions(all_factors, disk.size)[1]
def _create_boot_with_resize(self, disk, spec, **kwargs): def _create_boot_with_resize(self, disk, spec, **kwargs):
part_size = spec['size'] part_size = spec['size']
if part_size > gaps.largest_gap_size(disk): if part_size > gaps.largest_gap_size(disk):
@ -156,7 +158,7 @@ class FilesystemManipulator:
def _create_boot_partition(self, disk): def _create_boot_partition(self, disk):
bootloader = self.model.bootloader bootloader = self.model.bootloader
if bootloader == Bootloader.UEFI: if bootloader == Bootloader.UEFI:
part_size = self._get_efi_size(disk) part_size = get_efi_size(disk)
log.debug('_create_boot_partition - adding EFI partition') log.debug('_create_boot_partition - adding EFI partition')
spec = dict(size=part_size, fstype='fat32') spec = dict(size=part_size, fstype='fat32')
if self.model._mount_for_path("/boot/efi") is None: if self.model._mount_for_path("/boot/efi") is None:

View File

@ -22,6 +22,8 @@ from subiquity.common.filesystem import gaps
from subiquity.common.filesystem.manipulator import ( from subiquity.common.filesystem.manipulator import (
bootfs_scale, bootfs_scale,
FilesystemManipulator, FilesystemManipulator,
get_efi_size,
get_bootfs_size,
PartitionScaleFactors, PartitionScaleFactors,
scale_partitions, scale_partitions,
uefi_scale, uefi_scale,
@ -271,15 +273,15 @@ class TestPartitionSizeScaling(unittest.TestCase):
] ]
for disk_size, uefi, bootfs in tests: for disk_size, uefi, bootfs in tests:
disk = make_disk(manipulator.model, preserve=True, size=disk_size) disk = make_disk(manipulator.model, preserve=True, size=disk_size)
self.assertEqual(uefi, manipulator._get_efi_size(disk)) self.assertEqual(uefi, get_efi_size(disk))
self.assertEqual(bootfs, manipulator._get_bootfs_size(disk)) self.assertEqual(bootfs, get_bootfs_size(disk))
# something in between for scaling # something in between for scaling
disk_size = 15 << 30 disk_size = 15 << 30
disk = make_disk(manipulator.model, preserve=True, size=disk_size) disk = make_disk(manipulator.model, preserve=True, size=disk_size)
efi_size = manipulator._get_efi_size(disk) efi_size = get_efi_size(disk)
self.assertTrue(uefi_scale.maximum > efi_size) self.assertTrue(uefi_scale.maximum > efi_size)
self.assertTrue(efi_size > uefi_scale.minimum) self.assertTrue(efi_size > uefi_scale.minimum)
bootfs_size = manipulator._get_bootfs_size(disk) bootfs_size = get_bootfs_size(disk)
self.assertTrue(bootfs_scale.maximum > bootfs_size) self.assertTrue(bootfs_scale.maximum > bootfs_size)
self.assertTrue(bootfs_size > bootfs_scale.minimum) self.assertTrue(bootfs_size > bootfs_scale.minimum)

View File

@ -41,7 +41,10 @@ from subiquity.common.filesystem.actions import (
DeviceAction, DeviceAction,
) )
from subiquity.common.filesystem import boot, gaps, labels from subiquity.common.filesystem import boot, gaps, labels
from subiquity.common.filesystem.manipulator import FilesystemManipulator from subiquity.common.filesystem.manipulator import (
FilesystemManipulator,
get_bootfs_size,
)
from subiquity.common.types import ( from subiquity.common.types import (
Bootloader, Bootloader,
Disk, Disk,
@ -140,7 +143,7 @@ class FilesystemController(SubiquityController, FilesystemManipulator):
self.add_boot_disk(disk) self.add_boot_disk(disk)
self.create_partition( self.create_partition(
device=disk, spec=dict( device=disk, spec=dict(
size=self._get_bootfs_size(disk), size=get_bootfs_size(disk),
fstype="ext4", fstype="ext4",
mount='/boot' mount='/boot'
)) ))