Blame SOURCES/bootloader-raise-LookupError-on-unknown-BLS-keys.patch

ee88d8
From eda695b6cda61a5f1901479b6a0b22d8ba1ed96b Mon Sep 17 00:00:00 2001
ee88d8
From: "Bryn M. Reeves" <bmr@redhat.com>
ee88d8
Date: Wed, 9 Jan 2019 15:20:27 +0000
ee88d8
Subject: [PATCH] bootloader: raise LookupError on unknown BLS keys
ee88d8
ee88d8
When loading a BootEntry from file, if an unknown BLS key is read
ee88d8
a generic KeyError is raised when attempting to access a key in
ee88d8
the MAP_KEY (bls-to-boom key name map) dictionary. This leads to
ee88d8
a fairly cryptic error message:
ee88d8
ee88d8
 # boom list -V --debug all
ee88d8
 INFO - Could not load BootEntry '/boot/loader/entries/611f38fd887d41dea7eb3403b2730a76-4.15.17-200.fc26.x86_64.conf': 'id'
ee88d8
ee88d8
With --debug=all the cause is a little more obvious:
ee88d8
ee88d8
 # boom list --debug all
ee88d8
 Traceback (most recent call last):
ee88d8
   File "bin/boom", line 7, in <module>
ee88d8
     main(sys.argv)
ee88d8
   File "/home/breeves/src/git/boom/boom/command.py", line 1951, in main
ee88d8
     status = command[1](cmd_args, select, opts, identifier)
ee88d8
   File "/home/breeves/src/git/boom/boom/command.py", line 1287, in _list_cmd
ee88d8
     opts=opts, sort_keys=cmd_args.sort)
ee88d8
   File "/home/breeves/src/git/boom/boom/command.py", line 631, in print_entries
ee88d8
     bes = find_entries(selection=selection)
ee88d8
   File "/home/breeves/src/git/boom/boom/bootloader.py", line 769, in find_entries
ee88d8
     load_entries()
ee88d8
   File "/home/breeves/src/git/boom/boom/bootloader.py", line 659, in load_entries
ee88d8
     _add_entry(BootEntry(entry_file=entry_path))
ee88d8
   File "/home/breeves/src/git/boom/boom/bootloader.py", line 1310, in __init__
ee88d8
     return self.__from_file(entry_file, boot_params)
ee88d8
   File "/home/breeves/src/git/boom/boom/bootloader.py", line 1229, in __from_file
ee88d8
     key = MAP_KEY[_transform_key(bls_key)]
ee88d8
 KeyError: 'id'
ee88d8
ee88d8
Instead, raise the exception explicitly if the key is not present,
ee88d8
and set the exception string to a meaningful error:
ee88d8
ee88d8
 INFO - Could not load BootEntry '/boot/loader/entries/611f38fd887d41dea7eb3403b2730a76-4.15.17-200.fc26.x86_64.conf': Unknown BLS key 'id'
ee88d8
ee88d8
The more specific KeyError is not used here since it is specific
ee88d8
to dictionary lookup failures.
ee88d8
ee88d8
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
ee88d8
(cherry picked from commit 72a67d8beba4c4f36d1c0682a6628b2a823041a4)
ee88d8
ee88d8
Conflicts:
ee88d8
	boom/bootloader.py
ee88d8
---
ee88d8
 boom/bootloader.py | 4 ++++
ee88d8
 1 file changed, 4 insertions(+)
ee88d8
ee88d8
diff --git a/boom/bootloader.py b/boom/bootloader.py
ee88d8
index bc86cb8..dd2a53a 100644
ee88d8
--- a/boom/bootloader.py
ee88d8
+++ b/boom/bootloader.py
ee88d8
@@ -1067,6 +1067,10 @@ class BootEntry(object):
ee88d8
                     comment += line if line else ""
ee88d8
                 else:
ee88d8
                     bls_key, value = _parse_name_value(line, separator=None)
ee88d8
+                    # Convert BLS key name to Boom notation
ee88d8
+                    key = _transform_key(bls_key)
ee88d8
+                    if key not in MAP_KEY:
ee88d8
+                        raise LookupError("Unknown BLS key '%s'" % bls_key)
ee88d8
                     key = MAP_KEY[_transform_key(bls_key)]
ee88d8
                     entry_data[key] = value
ee88d8
                     if comment:
ee88d8
-- 
ee88d8
1.8.3.1
ee88d8