diff options
| author | Riccardo Pittau <elfosardo@gmail.com> | 2022-02-21 18:18:29 +0100 |
|---|---|---|
| committer | Riccardo Pittau <elfosardo@gmail.com> | 2022-02-22 15:53:54 +0100 |
| commit | 697fa6f3b6db10408eaadd57450456de87f13519 (patch) | |
| tree | d7511f91fc92141417d18b566686791c6372d7ac /ironic_python_agent | |
| parent | a83f38479ec2925cd11839eeb0742d1ab278b868 (diff) | |
| download | ironic-python-agent-697fa6f3b6db10408eaadd57450456de87f13519.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.
Change-Id: I3e25ce4997f5dd3df87caba753daced65838f85a
Diffstat (limited to 'ironic_python_agent')
| -rw-r--r-- | ironic_python_agent/efi_utils.py | 10 |
1 files changed, 8 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])) |
