summaryrefslogtreecommitdiff
path: root/ironic_python_agent/raid_utils.py
diff options
context:
space:
mode:
authorJakub Jelinek <jakub.jelinek@cern.ch>2022-08-24 09:25:16 +0000
committerJakub Jelinek <jakub.jelinek@cern.ch>2022-09-05 20:43:51 +0000
commita99bf274e4baec8e585bc9979e492bb8d85d17b5 (patch)
treee0ad11b0f27f46ba681968d8125f55a0850a47a9 /ironic_python_agent/raid_utils.py
parented6a8d28b7e8f1a6f091023863db26bb2a993a40 (diff)
downloadironic-python-agent-a99bf274e4baec8e585bc9979e492bb8d85d17b5.tar.gz
SoftwareRAID: Enable skipping RAIDS
Extend the ability to skip disks to RAID devices This allows users to specify the volume name of a logical device in the skip list which is then not cleaned or created again during the create/apply configuration phase The volume name can be specified in target raid config provided the change https://review.opendev.org/c/openstack/ironic-python-agent/+/853182/ passes Story: 2010233 Change-Id: Ib9290a97519bc48e585e1bafb0b60cc14e621e0f
Diffstat (limited to 'ironic_python_agent/raid_utils.py')
-rw-r--r--ironic_python_agent/raid_utils.py36
1 files changed, 35 insertions, 1 deletions
diff --git a/ironic_python_agent/raid_utils.py b/ironic_python_agent/raid_utils.py
index 3d5f260f..84c6941f 100644
--- a/ironic_python_agent/raid_utils.py
+++ b/ironic_python_agent/raid_utils.py
@@ -267,10 +267,44 @@ def get_next_free_raid_device():
name = f'/dev/md{idx}'
if name not in names:
return name
-
raise errors.SoftwareRAIDError("No free md (RAID) devices are left")
+def get_volume_name_of_raid_device(raid_device):
+ """Get the volume name of a RAID device
+
+ :param raid_device: A Software RAID block device name.
+ :returns: volume name of the device, or None
+ """
+ if not raid_device:
+ return None
+ try:
+ out, _ = utils.execute('mdadm', '--detail', raid_device,
+ use_standard_locale=True)
+ except processutils.ProcessExecutionError as e:
+ LOG.warning('Could not retrieve the volume name of %(dev)s: %(err)s',
+ {'dev': raid_device, 'err': e})
+ return None
+ lines = out.splitlines()
+ for line in lines:
+ if re.search(r'Name', line) is not None:
+ split_array = line.split(':')
+ # expecting format:
+ # Name : <host>:name (optional comment)
+ if len(split_array) == 3:
+ candidate = split_array[2]
+ else:
+ return None
+ # if name is followed by some other text
+ # such as (local to host <domain>) remove
+ # everything after " "
+ if " " in candidate:
+ candidate = candidate.split(" ")[0]
+ volume_name = candidate
+ return volume_name
+ return None
+
+
# TODO(rg): handle PreP boot parts relocation as well
def prepare_boot_partitions_for_softraid(device, holders, efi_part,
target_boot_mode):