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

Add fix for package running dnf5 on fedora #9520

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions lib/puppet/provider/package/yum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,15 @@ def install
wanted = @resource[:name]
error_level = self.class.error_level
update_command = self.class.update_command

# dnf5 on fedora 41 or later does not support -d or -e flags
no_debug = (Puppet.runtime[:facter].value('os.release.major').to_i > 5) ? ["-d", "0"] : []
no_debug = [] if Facter.value('os.name') == 'Fedora' && Facter.value('os.release.major').to_i > 40
no_error = (Facter.value('os.name') == 'Fedora' && Facter.value('os.release.major').to_i > 40) ? [] : ["-e", error_level]

# If not allowing virtual packages, do a query to ensure a real package exists
unless @resource.allow_virtual?
execute([command(:cmd), '-d', '0', '-e', error_level, '-y', install_options, :list, wanted].compact)
execute([command(:cmd)] + no_debug + no_error +['-y', install_options, :list, wanted].compact)
end

should = @resource.should(:ensure)
Expand Down Expand Up @@ -309,8 +315,11 @@ def install

# Yum on el-4 and el-5 returns exit status 0 when trying to install a package it doesn't recognize;
# ensure we capture output to check for errors.
no_debug = Puppet.runtime[:facter].value('os.release.major').to_i > 5 ? ["-d", "0"] : []
command = [command(:cmd)] + no_debug + ["-e", error_level, "-y", install_options, operation, wanted].compact
no_debug = (Puppet.runtime[:facter].value('os.release.major').to_i > 5) ? ["-d", "0"] : []
# dnf5 on fedora 41 or later does not support -d or -e flags
no_debug = [] if Facter.value('os.name') == 'Fedora' && Facter.value('os.release.major').to_i > 40
no_error = (Facter.value('os.name') == 'Fedora' && Facter.value('os.release.major').to_i > 40) ? [] : ["-e", error_level]
command = [command(:cmd)] + no_debug + no_error + ["-y", install_options, operation, wanted].compact
output = execute(command)

if output.to_s =~ /^No package #{wanted} available\.$/
Expand Down