sizing: scaling funcs usage & constants

Move these around so that we don't need a manipulator instance to use.
This commit is contained in:
Dan Bungert 2022-03-01 09:57:01 -07:00
parent ffc0502e48
commit 00d239f2c2
3 changed files with 22 additions and 15 deletions

View File

@ -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:

View File

@ -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)

View File

@ -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'
))