summaryrefslogtreecommitdiff
path: root/ironic_python_agent/utils.py
diff options
context:
space:
mode:
authorIury Gregory Melo Ferreira <imelofer@redhat.com>2019-12-04 19:55:27 +0100
committerIury Gregory Melo Ferreira <imelofer@redhat.com>2020-01-22 16:02:45 +0000
commit6a777e85878ab56c66b258a1386c459e8fd399df (patch)
treec6aa8b1715fc94511ef4d5a07b175f40a2746d33 /ironic_python_agent/utils.py
parent61128de52bf66307ccda345a4c46a65fbe70d19a (diff)
downloadironic-python-agent-6a777e85878ab56c66b258a1386c459e8fd399df.tar.gz
Search for efi partition
This patch adds a function that will be responsible to identify the efi partition on a give device, this is necessary on the Software Raid scenario and when installing bootloader. Conflicts: ironic_python_agent/tests/unit/test_utils.py ironic_python_agent/utils.py Change-Id: I5f326db2d37b2a15090ec84e477e63f7d92e7447 Co-Authored-By: Raphael Glon <raphael.glon@corp.ovh.com> (cherry picked from commit 966356e58c786fab1b176767615c481d449076a2)
Diffstat (limited to 'ironic_python_agent/utils.py')
-rw-r--r--ironic_python_agent/utils.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/ironic_python_agent/utils.py b/ironic_python_agent/utils.py
index f391b74d..8a804b16 100644
--- a/ironic_python_agent/utils.py
+++ b/ironic_python_agent/utils.py
@@ -17,6 +17,7 @@ import errno
import glob
import io
import os
+import re
import shutil
import subprocess
import tarfile
@@ -60,6 +61,9 @@ COLLECT_LOGS_COMMANDS = {
}
+PARTED_ESP_PATTERN = re.compile(r'^\s*(\d+)\s.*\sfat\d*\s.*esp(,|\s|$).*$')
+
+
def execute(*cmd, **kwargs):
"""Convenience wrapper around ironic_lib's execute() method.
@@ -437,3 +441,23 @@ def get_ssl_client_options(conf):
else:
cert = None
return verify, cert
+
+
+def get_efi_part_on_device(device):
+ """Looks for the efi partition on a given device
+
+ :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
+ else:
+ LOG.debug("No efi partition found on device %s", device)
+ return efi_part