Split and move logic for partition tables

Move and split the logic to create the partition tables when
applying raid configuration.

Change-Id: Ic76dd2067ace02dd02351caca0c7f9b05571e510
This commit is contained in:
Riccardo Pittau 2020-04-24 12:10:22 +02:00
parent bfa184e88d
commit 557d5603a2
4 changed files with 49 additions and 17 deletions

View File

@ -1652,21 +1652,8 @@ class GenericHardwareManager(HardwareManager):
partition_table_type = utils.get_partition_table_type_from_specs(node)
target_boot_mode = utils.get_node_boot_mode(node)
parted_start_dict = {}
# Create a partition table on each disk.
for dev_name in block_devices:
LOG.info("Creating partition table on {}".format(
dev_name))
try:
utils.execute('parted', dev_name, '-s', '--',
'mklabel', partition_table_type)
except processutils.ProcessExecutionError as e:
msg = "Failed to create partition table on {}: {}".format(
dev_name, e)
raise errors.SoftwareRAIDError(msg)
parted_start_dict[dev_name] = raid_utils.calculate_raid_start(
target_boot_mode, partition_table_type, dev_name)
parted_start_dict = raid_utils.create_raid_partition_tables(
block_devices, partition_table_type, target_boot_mode)
LOG.debug("First available sectors per devices %s", parted_start_dict)

View File

@ -13,11 +13,15 @@
import copy
from ironic_lib import utils as il_utils
from oslo_log import log as logging
from ironic_python_agent import errors
from ironic_python_agent import utils
LOG = logging.getLogger(__name__)
def get_block_devices_for_raid(block_devices, logical_disks):
"""Get block devices that are involved in the RAID configuration.
@ -132,3 +136,24 @@ def calc_raid_partition_sectors(psize, start):
end_str = '%dGiB' % end
return start_str, end_str, end
def create_raid_partition_tables(block_devices, partition_table_type,
target_boot_mode):
"""Creates partition tables in all disks in a RAID configuration and
reports the starting sector for each partition on each disk.
:param block_devices: disks where we want to create the partition tables.
:param partition_table_type: type of partition table to create, for example
gpt or msdos.
:param target_boot_mode: the node selected boot mode, for example uefi
or bios.
:return: a dictionary of devices and the start of the corresponding
partition.
"""
parted_start_dict = {}
for dev_name in block_devices:
utils.create_partition_table(dev_name, partition_table_type)
parted_start_dict[dev_name] = calculate_raid_start(
target_boot_mode, partition_table_type, dev_name)
return parted_start_dict

View File

@ -3543,7 +3543,7 @@ class TestGenericHardwareManager(base.IronicAgentTest):
error_regex = "Failed to create partition table on /dev/sda"
mocked_execute.side_effect = [
processutils.ProcessExecutionError]
self.assertRaisesRegex(errors.SoftwareRAIDError, error_regex,
self.assertRaisesRegex(errors.CommandExecutionError, error_regex,
self.hardware.create_configuration,
self.node, [])
# partition creation
@ -3755,7 +3755,7 @@ class TestGenericHardwareManager(base.IronicAgentTest):
error_regex = "Failed to create partition table on /dev/nvme0n1"
mocked_execute.side_effect = [
processutils.ProcessExecutionError]
self.assertRaisesRegex(errors.SoftwareRAIDError, error_regex,
self.assertRaisesRegex(errors.CommandExecutionError, error_regex,
self.hardware.create_configuration,
self.node, [])
# partition creation

View File

@ -730,3 +730,23 @@ def sync_clock(ignore_errors=False):
LOG.error(msg)
if CONF.fail_if_clock_not_set or not ignore_errors:
raise errors.CommandExecutionError(msg)
def create_partition_table(dev_name, partition_table_type):
"""Create a partition table on a disk using parted.
:param dev_name: the disk where we want to create the partition table.
:param partition_table_type: the type of partition table we want to
create, for example gpt or msdos.
:raises: CommandExecutionError if an error is encountered while
attempting to create the partition table.
"""
LOG.info("Creating partition table on {}".format(
dev_name))
try:
execute('parted', dev_name, '-s', '--',
'mklabel', partition_table_type)
except processutils.ProcessExecutionError as e:
msg = "Failed to create partition table on {}: {}".format(
dev_name, e)
raise errors.CommandExecutionError(msg)