projg2 / eclean-kernel

Installed kernel cleanup tool
GNU General Public License v2.0
31 stars 10 forks source link

Fix GRUB2._autogen AttributeError #6

Closed KSmanis closed 3 years ago

KSmanis commented 3 years ago

GRUB2._autogen should and can be determined on initialization, rather than when retrieving the list of kernels (which may or may not happen before the attribute is accessed).

codecov-commenter commented 3 years ago

Codecov Report

Merging #6 into master will increase coverage by 0.18%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master       #6      +/-   ##
==========================================
+ Coverage   83.87%   84.05%   +0.18%     
==========================================
  Files          16       16              
  Lines         713      715       +2     
==========================================
+ Hits          598      601       +3     
+ Misses        115      114       -1     
Impacted Files Coverage Δ
ecleankernel/bootloader/grub2.py 53.57% <100.00%> (+7.41%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update b0cace4...b01ffa3. Read the comment docs.

KSmanis commented 3 years ago

How to reproduce crash

Status:

$ ecleankernel -l --debug
DEBUG:root:Layout failed: <class 'ecleankernel.layout.blspec.BlSpecLayout'>; exception: /boot/[EFI/]93a9982519b2395c5604b18300000007 not found
DEBUG:root:Layout: <ecleankernel.layout.std.StdLayout object at 0x7fe4f0765350>
DEBUG:root:Bootloader failed: <class 'ecleankernel.bootloader.lilo.LILO'>
DEBUG:root:/boot/grub/grub.cfg found
DEBUG:root:Bootloader: <ecleankernel.bootloader.grub2.GRUB2 object at 0x7fe4f0765390>
DEBUG:root:Sorter: <ecleankernel.sort.VersionSort object at 0x7fe4f07653d0>
5.7.9-gentoo [5.7.9-gentoo]
- systemmap: /boot/System.map-5.7.9-gentoo
- config: /boot/config-5.7.9-gentoo
- vmlinuz: /boot/vmlinuz-5.7.9-gentoo
- modules: /lib/modules/5.7.9-gentoo
- build: /usr/src/linux-5.7.9-gentoo
- last modified: 2020-07-16 13:53:23
5.7.9 [5.7.9]
- systemmap: /boot/System.map-5.7.9
- config: /boot/config-5.7.9
- initramfs: /boot/initramfs-5.7.9.img
- vmlinuz: /boot/vmlinuz-5.7.9
- modules: /lib/modules/5.7.9
- build: /lib/modules/5.7.9/../../../usr/src/linux-5.7.9
- last modified: 2020-07-17 10:13:35

Before:

$ ecleankernel -a -d -p --debug
DEBUG:root:Layout failed: <class 'ecleankernel.layout.blspec.BlSpecLayout'>; exception: /boot/[EFI/]93a9982519b2395c5604b18300000007 not found
DEBUG:root:Layout: <ecleankernel.layout.std.StdLayout object at 0x7f462abf9f90>
DEBUG:root:Bootloader failed: <class 'ecleankernel.bootloader.lilo.LILO'>
DEBUG:root:/boot/grub/grub.cfg found
DEBUG:root:Bootloader: <ecleankernel.bootloader.grub2.GRUB2 object at 0x7f462abf9ed0>
DEBUG:root:Sorter: <ecleankernel.sort.VersionSort object at 0x7f462abf9fd0>
DEBUG:root:in get_removal_list()
Preserving currently running kernel (5.7.9-gentoo)
Traceback (most recent call last):
  File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/socrates/Development/projects/git/eclean-kernel/ecleankernel/__main__.py", line 386, in <module>
    setuptools_main()
  File "/home/socrates/Development/projects/git/eclean-kernel/ecleankernel/__main__.py", line 382, in setuptools_main
    sys.exit(main(sys.argv[1:]))
  File "/home/socrates/Development/projects/git/eclean-kernel/ecleankernel/__main__.py", line 264, in main
    and bootloader.has_postrm()):
  File "/home/socrates/Development/projects/git/eclean-kernel/ecleankernel/bootloader/grub2.py", line 34, in has_postrm
    return self._autogen
AttributeError: 'GRUB2' object has no attribute '_autogen'

After:

$ ecleankernel -a -d -p --debug
DEBUG:root:Layout failed: <class 'ecleankernel.layout.blspec.BlSpecLayout'>; exception: /boot/[EFI/]93a9982519b2395c5604b18300000007 not found
DEBUG:root:Layout: <ecleankernel.layout.std.StdLayout object at 0x7f53fcf555d0>
DEBUG:root:Bootloader failed: <class 'ecleankernel.bootloader.lilo.LILO'>
DEBUG:root:/boot/grub/grub.cfg found
DEBUG:root:Bootloader: <ecleankernel.bootloader.grub2.GRUB2 object at 0x7f53fce0d350>
DEBUG:root:Sorter: <ecleankernel.sort.VersionSort object at 0x7f53fce0d290>
DEBUG:root:in get_removal_list()
Preserving currently running kernel (5.7.9-gentoo)
Legend:
[-] file being removed
[+] file being kept (used by other kernels

These are the kernels which would be removed:
- 5.7.9: unwanted
 [-] /boot/vmlinuz-5.7.9
 [-] /lib/modules/5.7.9/../../../usr/src/linux-5.7.9
 [-] /lib/modules/5.7.9
 [-] /boot/initramfs-5.7.9.img
 [-] /boot/config-5.7.9
 [-] /boot/System.map-5.7.9
Bootloader grub2 config will be updated
mgorny commented 3 years ago

Thanks. The change seems to make sense, so I'll merge it.

mgorny commented 3 years ago

Oh, could you please sign off on your changes (https://developercertificate.org/)?

anyuta1166 commented 3 years ago

I've updated from app-admin/eclean-kernel-2.99.1 to app-admin/eclean-kernel-9999 because 2.99.1 didn't update grub configuration file. And now I'm encountering the error addressed in this PR. Will this PR be merged someday?

mgorny commented 3 years ago

I'm sorry about the delay, I have missed the push.