Move logic for raid start sector to raid_utils

A starting tentative in reducing size of raid related functions.

Change-Id: I81f912d0dc0ad138d8cc776cdb4ee3b5251ec3ba
This commit is contained in:
Riccardo Pittau 2020-04-08 17:22:47 +02:00
parent bdc5e9448d
commit f32a4a2b29
2 changed files with 42 additions and 29 deletions

View File

@ -1566,35 +1566,8 @@ class GenericHardwareManager(HardwareManager):
dev_name, e)
raise errors.SoftwareRAIDError(msg)
# TODO(rg): TBD, several options regarding boot part slots here:
# 1. Create boot partitions in prevision
# 2. Just leave space
# 3. Do nothing: rely on the caller to specify target_raid_config
# correctly according to what they intend to do (e.g. not set MAX
# if they know they will need some space for bios boot or efi
# parts). Best option imo, if we accept that the target volume
# granularity is GiB, so you lose up to 1GiB just for a bios boot
# partition...
if target_boot_mode == 'uefi':
# Leave 129MiB - start_sector s for the esp (approx 128MiB)
# NOTE: any image efi partition is expected to be less
# than 128MiB
# TBD: 129MiB is a waste in most cases.
raid_start = '129MiB'
else:
if partition_table_type == 'gpt':
# Leave 8MiB - start_sector s (approx 7MiB)
# for the bios boot partition or the ppc prepboot part
# This should avoid grub errors saying that it cannot
# install boot stage 1.5/2 (since the mbr gap does not
# exist on disk holders with gpt tables)
raid_start = '8MiB'
else:
# sgdisk works fine for display data on mbr tables too
out, _u = utils.execute('sgdisk', '-F', dev_name)
raid_start = "{}s".format(out.splitlines()[-1])
parted_start_dict[dev_name] = raid_start
parted_start_dict[dev_name] = raid_utils.calculate_raid_start(
target_boot_mode, partition_table_type, dev_name)
LOG.debug("First available sectors per devices %s", parted_start_dict)

View File

@ -15,6 +15,7 @@ import copy
from ironic_lib import utils as il_utils
from ironic_python_agent import errors
from ironic_python_agent import utils
def get_block_devices_for_raid(block_devices, logical_disks):
@ -63,3 +64,42 @@ def get_block_devices_for_raid(block_devices, logical_disks):
logical_disk['block_devices'] = matching
return result, logical_disks
def calculate_raid_start(target_boot_mode, partition_table_type, dev_name):
"""Define the start sector for the raid partition.
:param target_boot_mode: the node boot mode.
:param partition_table_type: the node partition label, gpt or msdos.
:param dev_name: block device in the raid configuration.
:return: The start sector for the raid partition.
"""
# TODO(rg): TBD, several options regarding boot part slots here:
# 1. Create boot partitions in prevision
# 2. Just leave space
# 3. Do nothing: rely on the caller to specify target_raid_config
# correctly according to what they intend to do (e.g. not set MAX
# if they know they will need some space for bios boot or efi
# parts). Best option imo, if we accept that the target volume
# granularity is GiB, so you lose up to 1GiB just for a bios boot
# partition...
if target_boot_mode == 'uefi':
# Leave 129MiB - start_sector s for the esp (approx 128MiB)
# NOTE: any image efi partition is expected to be less
# than 128MiB
# TBD: 129MiB is a waste in most cases.
raid_start = '129MiB'
else:
if partition_table_type == 'gpt':
# Leave 8MiB - start_sector s (approx 7MiB)
# for the bios boot partition or the ppc prepboot part
# This should avoid grub errors saying that it cannot
# install boot stage 1.5/2 (since the mbr gap does not
# exist on disk holders with gpt tables)
raid_start = '8MiB'
else:
# sgdisk works fine for display data on mbr tables too
out, _u = utils.execute('sgdisk', '-F', dev_name)
raid_start = "{}s".format(out.splitlines()[-1])
return raid_start