diff options
| author | Dmitry Tantsur <dtantsur@protonmail.com> | 2020-04-15 12:44:37 +0200 |
|---|---|---|
| committer | Dmitry Tantsur <dtantsur@protonmail.com> | 2020-04-15 18:38:15 +0200 |
| commit | ff49b04e28b74d89a5fa6334411c56628f502bee (patch) | |
| tree | 95ae813c8bd25d4965545c3d7827dbe9873977db /ironic_python_agent/utils.py | |
| parent | f6668f94c909d739ddb8182d40a285c9e58d3083 (diff) | |
| download | ironic-python-agent-ff49b04e28b74d89a5fa6334411c56628f502bee.tar.gz | |
A boot partition on a GPT disk should be considered an EFI partition
DIB builds instance images with EFI partitions that only have the boot
flag, but not esp. According to parted documentation, boot is an alias
for esp on GPT, so accept it as well.
To avoid complexities when parsing parted output, the implementation
is switched to existing utils and ironic-lib functions.
Change-Id: I5f57535e5a89528c38d0879177b59db6c0f5c06e
Story: #2007455
Task: #39423
Diffstat (limited to 'ironic_python_agent/utils.py')
| -rw-r--r-- | ironic_python_agent/utils.py | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/ironic_python_agent/utils.py b/ironic_python_agent/utils.py index e74cc1f1..dca48d11 100644 --- a/ironic_python_agent/utils.py +++ b/ironic_python_agent/utils.py @@ -25,6 +25,7 @@ import tarfile import tempfile import time +from ironic_lib import disk_utils from ironic_lib import utils as ironic_utils from oslo_concurrency import processutils from oslo_config import cfg @@ -73,7 +74,6 @@ DEVICE_EXTRACTOR = re.compile(r'^(?:(.*\d)p|(.*\D))(?:\d+)$') PARTED_TABLE_TYPE_REGEX = re.compile(r'^.*partition\s+table\s*:\s*(gpt|msdos)', re.IGNORECASE) -PARTED_ESP_PATTERN = re.compile(r'^\s*(\d+)\s.*\s\s.*\s.*esp(,|\s|$).*$') def execute(*cmd, **kwargs): @@ -611,23 +611,21 @@ def scan_partition_table_type(device): def get_efi_part_on_device(device): - """Looks for the efi partition on a given device + """Looks for the efi partition on a given device. + + A boot partition on a GPT disk is assumed to be an EFI partition as well. :param device: lock device upon which to check for the efi partition :return: the efi partition or None """ - efi_part = None - out, _u = execute('parted', '-s', device, '--', 'print') - for line in out.splitlines(): - m = PARTED_ESP_PATTERN.match(line) - if m: - efi_part = m.group(1) - - LOG.debug("Found efi partition %s on device %s.", efi_part, device) - break + is_gpt = scan_partition_table_type(device) == 'gpt' + for part in disk_utils.list_partitions(device): + flags = {x.strip() for x in part['flags'].split(',')} + if 'esp' in flags or ('boot' in flags and is_gpt): + LOG.debug("Found EFI partition %s on device %s.", part, device) + return part['number'] else: LOG.debug("No efi partition found on device %s", device) - return efi_part _LARGE_KEYS = frozenset(['configdrive', 'system_logs']) |
