summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2022-03-02 16:55:43 +0000
committerGerrit Code Review <review@openstack.org>2022-03-02 16:55:43 +0000
commitcf4644312095ff836c522569ba0a66666bf8857d (patch)
treed2b14d2147136e5ffdb9bfebc99f974503a8c64f
parent48f30ab52892f54b949cbb27dac91942c1d45dce (diff)
parent697fa6f3b6db10408eaadd57450456de87f13519 (diff)
downloadironic-python-agent-cf4644312095ff836c522569ba0a66666bf8857d.tar.gz
Merge "Use utf-16-le if BOM not present"
-rw-r--r--ironic_python_agent/efi_utils.py10
-rw-r--r--releasenotes/notes/detect-endianness-f53a6c4571aba3fe.yaml6
2 files changed, 14 insertions, 2 deletions
diff --git a/ironic_python_agent/efi_utils.py b/ironic_python_agent/efi_utils.py
index ea7a9474..c4e9dcc7 100644
--- a/ironic_python_agent/efi_utils.py
+++ b/ironic_python_agent/efi_utils.py
@@ -297,8 +297,14 @@ def _run_efibootmgr(valid_efi_bootloaders, device, efi_partition,
'File: %s', v_bl)
# These files are always UTF-16 encoded, sometimes have a header.
# Positive bonus is python silently drops the FEFF header.
- with open(mount_point + '/' + v_bl, 'r', encoding='utf-16') as csv:
- contents = str(csv.read())
+ try:
+ with open(mount_point + '/' + v_bl, 'r',
+ encoding='utf-16') as csv:
+ contents = str(csv.read())
+ except UnicodeError:
+ with open(mount_point + '/' + v_bl, 'r',
+ encoding='utf-16-le') as csv:
+ contents = str(csv.read())
csv_contents = contents.split(',', maxsplit=3)
csv_filename = v_bl.split('/')[-1]
v_efi_bl_path = v_bl.replace(csv_filename, str(csv_contents[0]))
diff --git a/releasenotes/notes/detect-endianness-f53a6c4571aba3fe.yaml b/releasenotes/notes/detect-endianness-f53a6c4571aba3fe.yaml
new file mode 100644
index 00000000..82d90886
--- /dev/null
+++ b/releasenotes/notes/detect-endianness-f53a6c4571aba3fe.yaml
@@ -0,0 +1,6 @@
+---
+fixes:
+ - |
+ In case the CSV file used for the bootloader hint does not have BOM
+ we fail reading its content as utf-16 codec is too generic.
+ Fail over to utf-16-le as Little Endian is mostly used.