summaryrefslogtreecommitdiff
path: root/ironic_python_agent/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'ironic_python_agent/utils.py')
-rw-r--r--ironic_python_agent/utils.py44
1 files changed, 32 insertions, 12 deletions
diff --git a/ironic_python_agent/utils.py b/ironic_python_agent/utils.py
index 7c4a2468..cb29fcd0 100644
--- a/ironic_python_agent/utils.py
+++ b/ironic_python_agent/utils.py
@@ -24,6 +24,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_log import log as logging
@@ -63,7 +64,8 @@ COLLECT_LOGS_COMMANDS = {
DEVICE_EXTRACTOR = re.compile(r'^(?:(.*\d)p|(.*\D))(?:\d+)$')
-PARTED_ESP_PATTERN = re.compile(r'^\s*(\d+)\s.*\s\s.*\s.*esp(,|\s|$).*$')
+PARTED_TABLE_TYPE_REGEX = re.compile(r'^.*partition\s+table\s*:\s*(gpt|msdos)',
+ re.IGNORECASE)
def execute(*cmd, **kwargs):
@@ -457,21 +459,39 @@ def extract_device(part):
return (m.group(1) or m.group(2))
-def get_efi_part_on_device(device):
- """Looks for the efi partition on a given device
+def scan_partition_table_type(device):
+ """Get partition table type, msdos or gpt.
- :param device: lock device upon which to check for the efi partition
- :return: the efi partition or None
+ :param device_name: the name of the device
+ :return: msdos, gpt or unknown
"""
- efi_part = None
out, _u = execute('parted', '-s', device, '--', 'print')
- for line in out.splitlines():
- m = PARTED_ESP_PATTERN.match(line)
+ out = out.splitlines()
+
+ for line in out:
+ m = PARTED_TABLE_TYPE_REGEX.match(line)
if m:
- efi_part = m.group(1)
+ return m.group(1)
+
+ LOG.warning("Unable to get partition table type for device %s.",
+ device)
+
+ return 'unknown'
+
- LOG.debug("Found efi partition %s on device %s.", efi_part, device)
- break
+def get_efi_part_on_device(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
+ """
+ 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