Merge pull request #1205 from dbungert/partition-sizing
sizing: scaling funcs usage & constants
This commit is contained in:
commit
05310f2ffd
|
@ -39,10 +39,6 @@ from subiquity.ui.views.filesystem.probing import (
|
|||
|
||||
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):
|
||||
|
||||
|
|
|
@ -75,6 +75,16 @@ def scale_partitions(all_factors, disk_size):
|
|||
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:
|
||||
|
||||
def create_mount(self, fs, spec):
|
||||
|
@ -138,14 +148,6 @@ class FilesystemManipulator:
|
|||
self.clear(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):
|
||||
part_size = spec['size']
|
||||
if part_size > gaps.largest_gap_size(disk):
|
||||
|
@ -156,7 +158,7 @@ class FilesystemManipulator:
|
|||
def _create_boot_partition(self, disk):
|
||||
bootloader = self.model.bootloader
|
||||
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')
|
||||
spec = dict(size=part_size, fstype='fat32')
|
||||
if self.model._mount_for_path("/boot/efi") is None:
|
||||
|
|
|
@ -22,6 +22,8 @@ from subiquity.common.filesystem import gaps
|
|||
from subiquity.common.filesystem.manipulator import (
|
||||
bootfs_scale,
|
||||
FilesystemManipulator,
|
||||
get_efi_size,
|
||||
get_bootfs_size,
|
||||
PartitionScaleFactors,
|
||||
scale_partitions,
|
||||
uefi_scale,
|
||||
|
@ -271,15 +273,15 @@ class TestPartitionSizeScaling(unittest.TestCase):
|
|||
]
|
||||
for disk_size, uefi, bootfs in tests:
|
||||
disk = make_disk(manipulator.model, preserve=True, size=disk_size)
|
||||
self.assertEqual(uefi, manipulator._get_efi_size(disk))
|
||||
self.assertEqual(bootfs, manipulator._get_bootfs_size(disk))
|
||||
self.assertEqual(uefi, get_efi_size(disk))
|
||||
self.assertEqual(bootfs, get_bootfs_size(disk))
|
||||
|
||||
# something in between for scaling
|
||||
disk_size = 15 << 30
|
||||
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(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_size > bootfs_scale.minimum)
|
||||
|
|
|
@ -41,7 +41,10 @@ from subiquity.common.filesystem.actions import (
|
|||
DeviceAction,
|
||||
)
|
||||
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 (
|
||||
Bootloader,
|
||||
Disk,
|
||||
|
@ -140,7 +143,7 @@ class FilesystemController(SubiquityController, FilesystemManipulator):
|
|||
self.add_boot_disk(disk)
|
||||
self.create_partition(
|
||||
device=disk, spec=dict(
|
||||
size=self._get_bootfs_size(disk),
|
||||
size=get_bootfs_size(disk),
|
||||
fstype="ext4",
|
||||
mount='/boot'
|
||||
))
|
||||
|
|
Loading…
Reference in New Issue