Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix purge of unwanted kernels on DNF based machines #309

Merged
merged 1 commit into from Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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