summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2020-06-11 22:53:07 +0000
committerGerrit Code Review <review@openstack.org>2020-06-11 22:53:07 +0000
commit751dac7b9065ded97dc28bc443e9428f09a88f09 (patch)
treef4e39f441d3a053e3263ce079a4180a5d8c5d3a3
parent54c1c32ae68c44fc8ab2d40ae5b7055a02ccaa91 (diff)
parent557d5603a29d0074402ec4d6f35927f6e79f2cf3 (diff)
downloadironic-python-agent-751dac7b9065ded97dc28bc443e9428f09a88f09.tar.gz
Merge "Split and move logic for partition tables"
-rw-r--r--ironic_python_agent/hardware.py17
-rw-r--r--ironic_python_agent/raid_utils.py25
-rw-r--r--ironic_python_agent/tests/unit/test_hardware.py4
-rw-r--r--ironic_python_agent/utils.py20
4 files changed, 49 insertions, 17 deletions
diff --git a/ironic_python_agent/hardware.py b/ironic_python_agent/hardware.py
index ea54300a..a5b31c73 100644
--- a/ironic_python_agent/hardware.py
+++ b/ironic_python_agent/hardware.py
@@ -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)
diff --git a/ironic_python_agent/raid_utils.py b/ironic_python_agent/raid_utils.py
index 1e629888..2ad49e0a 100644
--- a/ironic_python_agent/raid_utils.py
+++ b/ironic_python_agent/raid_utils.py
@@ -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
diff --git a/ironic_python_agent/tests/unit/test_hardware.py b/ironic_python_agent/tests/unit/test_hardware.py
index ebbb9b8e..0be427e5 100644
--- a/ironic_python_agent/tests/unit/test_hardware.py
+++ b/ironic_python_agent/tests/unit/test_hardware.py
@@ -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
diff --git a/ironic_python_agent/utils.py b/ironic_python_agent/utils.py
index dca48d11..211070ac 100644
--- a/ironic_python_agent/utils.py
+++ b/ironic_python_agent/utils.py
@@ -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)