Skip to content

Commit

Permalink
Merge pull request #309 from traylenator/fix295
Browse files Browse the repository at this point in the history
Fix purge of unwanted kernels on DNF based machines
  • Loading branch information
traylenator committed Jun 14, 2023
2 parents 5bdb9c8 + 413fbc6 commit 65d19f4
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 11 deletions.
23 changes: 13 additions & 10 deletions manifests/init.pp
Expand Up @@ -205,19 +205,22 @@
default => '3',
}

$_pc_cmd = [
'/usr/bin/package-cleanup',
'--oldkernels',
"--count=${_real_installonly_limit}",
'-y',
$keep_kernel_devel ? {
true => '--keepdevel',
default => undef,
$_keep_kernel_devel = $keep_kernel_devel ? {
true => $facts['package_provider'] ? {
'yum' => '--keepdevel ',
'dnf' => '--exclude kernel-release',
default => fail("Fact package_provider is not set to \'yum\' or \'dnf\' - giving up"),
},
].filter |$val| { $val =~ NotUndef }
default => '',
}

$_pc_cmd = $facts['package_provider'] ? {
'yum' => "/usr/bin/package-cleanup --oldkernels --count=${_real_installonly_limit} -y${$_keep_kernel_devel}",
default => "/usr/bin/dnf -y remove $(/usr/bin/dnf repoquery --installonly --latest-limit=-${_real_installonly_limit}${_keep_kernel_devel} | /usr/bin/grep -v ${facts['kernelrelease']})"
}

exec { 'package-cleanup_oldkernels':
command => shellquote($_pc_cmd),
command => $_pc_cmd,
refreshonly => true,
require => Package[$utils_package_name],
subscribe => $_clean_old_kernels_subscribe,
Expand Down
20 changes: 20 additions & 0 deletions spec/acceptance/yum_config_install_limit_2_spec.rb
@@ -0,0 +1,20 @@
# frozen_string_literal: true

require 'spec_helper_acceptance'

describe 'yum::config installonly_limit 1' do
context 'simple parameters' do
# Using puppet_apply as a helper
it 'must work idempotently with no errors' do
pp = <<-EOS
yum::config{'installonly_limit':
ensure => 2, # yum (and not dnf) does not like the value 1
}
include yum
EOS
# Run it twice and test for idempotency
apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_changes: true)
end
end
end
16 changes: 15 additions & 1 deletion spec/classes/init_spec.rb
Expand Up @@ -10,7 +10,7 @@

it 'contains Exec[package-cleanup_oldkernels' do
is_expected.to contain_exec('package-cleanup_oldkernels').with(
command: "/usr/bin/package-cleanup --oldkernels --count=#{value} -y",
command: %r{/usr/bin/dnf -y remove \$\(/usr/bin/dnf repoquery --installonly --latest-limit=-\$\{value\} | /usr/bin/grep -v \S+\)},
refreshonly: true
).that_subscribes_to('Yum::Config[installonly_limit]')
end
Expand Down Expand Up @@ -45,6 +45,20 @@
it { is_expected.to have_yumrepo_resource_count(0) }
end

context 'with package_provider yum' do
let(:facts) do
facts.merge({ package_provider: 'yum' })
end

it { is_expected.to compile.with_all_deps }

it {
is_expected.to contain_exec('package-cleanup_oldkernels').with(
command: '/usr/bin/package-cleanup --oldkernels --count=3 -y'
)
}
end

context 'when `manage_os_default_repos` is enabled' do
let(:params) { { 'manage_os_default_repos' => true } }

Expand Down

0 comments on commit 65d19f4

Please sign in to comment.