From f32a4a2b29df01cb100b6fdda59dac5d964a1107 Mon Sep 17 00:00:00 2001 From: Riccardo Pittau Date: Wed, 8 Apr 2020 17:22:47 +0200 Subject: [PATCH] Move logic for raid start sector to raid_utils A starting tentative in reducing size of raid related functions. Change-Id: I81f912d0dc0ad138d8cc776cdb4ee3b5251ec3ba --- ironic_python_agent/hardware.py | 31 ++---------------------- ironic_python_agent/raid_utils.py | 40 +++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 29 deletions(-) diff --git a/ironic_python_agent/hardware.py b/ironic_python_agent/hardware.py index 86de2cf9e..b88f135b3 100644 --- a/ironic_python_agent/hardware.py +++ b/ironic_python_agent/hardware.py @@ -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) diff --git a/ironic_python_agent/raid_utils.py b/ironic_python_agent/raid_utils.py index 7f718ac4e..b50164e87 100644 --- a/ironic_python_agent/raid_utils.py +++ b/ironic_python_agent/raid_utils.py @@ -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