diff options
author | Riccardo Pittau <elfosardo@gmail.com> | 2022-02-21 18:18:29 +0100 |
---|---|---|
committer | Julia Kreger <juliaashleykreger@gmail.com> | 2022-10-13 15:32:12 +0000 |
commit | 0f0ac47bae85d09d231eb9ac2999f50d8aae1e38 (patch) | |
tree | e6f4550cb3fd768972d73148c45252522e60d823 | |
parent | 59d8969dc4a447390cd2268babdfcabcae3a2724 (diff) | |
download | ironic-python-agent-0f0ac47bae85d09d231eb9ac2999f50d8aae1e38.tar.gz |
Use utf-16-le if BOM not present
In case no BOM is present in the CSV file the utf-16 codec won't work.
We fail over to utf-16-le as Little Endian is commonly used.
NOTE: The original change landed this fix in efi_utils.py, however
that was introduced after the Xena development cycle, so this
backport moves the original change to where the code originally
came from to populate the efi_utils.py file.
Change-Id: I3e25ce4997f5dd3df87caba753daced65838f85a
(cherry picked from commit 697fa6f3b6db10408eaadd57450456de87f13519)
(cherry picked from commit 99b9d1403cacd3bbd489a6cf6913f32746ef6083)
-rw-r--r-- | ironic_python_agent/extensions/image.py | 10 | ||||
-rw-r--r-- | releasenotes/notes/detect-endianness-f53a6c4571aba3fe.yaml | 6 |
2 files changed, 14 insertions, 2 deletions
diff --git a/ironic_python_agent/extensions/image.py b/ironic_python_agent/extensions/image.py index f5a0142d..3ea3b802 100644 --- a/ironic_python_agent/extensions/image.py +++ b/ironic_python_agent/extensions/image.py @@ -286,8 +286,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. |