rackerlabs / kthresher

Tool to remove unused kernels in Debian/Ubuntu
Apache License 2.0
17 stars 12 forks source link

Keep argument does not default always to 1. #64

Closed tonyskapunk closed 5 years ago

tonyskapunk commented 5 years ago

Debian package maintainer @jkirk reported this inconsistency with the keep argument:

"--keep defaults to 1". This does not seem true:

% kthresher -k -d INFO: Attempting to read /etc/kthresher.conf. INFO: Options found: ['include']. INFO: Valid setting found "include" INFO: include = /etc/kthresher.d/.conf INFO: Options: {'purge': False, 'headers': False, 'verbose': False, 'dry_run': True, 'include': '/etc/kthresher.d/.conf', 'keep': 0} INFO: ----- DRY RUN ----- INFO: Running kernel is linux-image-4.18.0-0.bpo.1-amd64 v[4.18.6-1~bpo9+1] INFO: No packages available for autoremoval.

Without keep:

% kthresher -d INFO: Attempting to read /etc/kthresher.conf. INFO: Options found: ['include']. INFO: Valid setting found "include" INFO: include = /etc/kthresher.d/.conf INFO: Options: {'purge': False, 'headers': False, 'verbose': False, 'dry_run': True, 'include': '/etc/kthresher.d/.conf', 'keep': 1} INFO: ----- DRY RUN ----- INFO: Running kernel is linux-image-4.18.0-0.bpo.1-amd64 v[4.18.6-1~bpo9+1] INFO: No packages available for autoremoval.

--keep defaults to 1 if --keep is not given, but defaults to 0 if no value for --keep is given.

tonyskapunk commented 5 years ago

I have the fix in #65 examples with the fix in place:

Without keep:

$ kthresher -d
INFO: Attempting to read /etc/kthresher.conf.
INFO: Options found: ['include'].
INFO: Valid setting found "include"
INFO:   include = /etc/kthresher.d/*.conf
INFO: Attempting to read /etc/kthresher.d/kthresher.conf.
INFO: Options found: ['headers'].
INFO: Valid setting found "headers"
INFO:   headers = True
INFO: Options: {'dry_run': True, 'headers': True, 'include': '/etc/kthresher.d/*.conf', 'keep': 1, 'verbose': False, 'purge': False}
INFO: ----- DRY RUN -----
INFO: Running kernel is linux-image-4.9.0-8-amd64 v[4.9.110-3+deb9u6]
INFO: Attempting to keep 1 kernel package(s)
INFO: Found 4 kernel image(s) installed and available for autoremoval
INFO: Pre-sorting: ['4.9.65-3+deb9u1', '4.9.88-1+deb9u1', '4.9.110-3+deb9u2', '4.9.65-3+deb9u2']
INFO: Post-sorting: ['4.9.65-3+deb9u1', '4.9.65-3+deb9u2', '4.9.88-1+deb9u1', '4.9.110-3+deb9u2']
INFO:   Purging packages from version: 4.9.65-3+deb9u1
INFO:       Purging: linux-image-4.9.0-4-amd64
INFO:   Purging packages from version: 4.9.65-3+deb9u2
INFO:       Purging: linux-image-4.9.0-5-amd64
INFO:       Purging: linux-headers-4.9.0-5-amd64
INFO:       Purging: linux-headers-4.9.0-5-common
INFO:   Purging packages from version: 4.9.88-1+deb9u1
INFO:       Purging: linux-image-4.9.0-6-amd64
INFO:       Purging: linux-headers-4.9.0-6-amd64
INFO:       Purging: linux-headers-4.9.0-6-common

With keep

$ kthresher -dk
INFO: Attempting to read /etc/kthresher.conf.
INFO: Options found: ['include'].
INFO: Valid setting found "include"
INFO:   include = /etc/kthresher.d/*.conf
INFO: Attempting to read /etc/kthresher.d/kthresher.conf.
INFO: Options found: ['headers'].
INFO: Valid setting found "headers"
INFO:   headers = True
INFO: Options: {'keep': 1, 'verbose': False, 'purge': False, 'include': '/etc/kthresher.d/*.conf', 'headers': True, 'dry_run': True}
INFO: ----- DRY RUN -----
INFO: Running kernel is linux-image-4.9.0-8-amd64 v[4.9.110-3+deb9u6]
INFO: Attempting to keep 1 kernel package(s)
INFO: Found 4 kernel image(s) installed and available for autoremoval
INFO: Pre-sorting: ['4.9.110-3+deb9u2', '4.9.65-3+deb9u1', '4.9.88-1+deb9u1', '4.9.65-3+deb9u2']
INFO: Post-sorting: ['4.9.65-3+deb9u1', '4.9.65-3+deb9u2', '4.9.88-1+deb9u1', '4.9.110-3+deb9u2']
INFO:   Purging packages from version: 4.9.65-3+deb9u1
INFO:       Purging: linux-image-4.9.0-4-amd64
INFO:   Purging packages from version: 4.9.65-3+deb9u2
INFO:       Purging: linux-image-4.9.0-5-amd64
INFO:       Purging: linux-headers-4.9.0-5-amd64
INFO:       Purging: linux-headers-4.9.0-5-common
INFO:   Purging packages from version: 4.9.88-1+deb9u1
INFO:       Purging: linux-image-4.9.0-6-amd64
INFO:       Purging: linux-headers-4.9.0-6-amd64
INFO:       Purging: linux-headers-4.9.0-6-common