From 51f5a4fd725a3a87d6d4b8bf6771e52317466a93 Mon Sep 17 00:00:00 2001 From: rvasikarla Date: Sun, 5 Apr 2026 12:22:29 -0500 Subject: [PATCH 1/2] fix: add dnf5 compatibility by removing deprecated -d and -e flags dnf5 (default in Fedora 41+) removed the -d (debuglevel) and -e (errorlevel) flags, causing puppet package management to fail with: Unknown argument "-d" for command "dnf5" Extract the flag-building into a quiet_flags class method on the yum provider, then override it in the dnf provider to return an empty array. This preserves backward compatibility for yum while fixing dnf5. Also update dnfmodule provider to use quiet_flags instead of hardcoded flags. Fixes #9506 --- lib/puppet/provider/package/dnf.rb | 8 ++++++++ lib/puppet/provider/package/dnfmodule.rb | 12 ++++++------ lib/puppet/provider/package/yum.rb | 13 +++++++++---- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/lib/puppet/provider/package/dnf.rb b/lib/puppet/provider/package/dnf.rb index 4f4fb1e4fde..0799e4c8da6 100644 --- a/lib/puppet/provider/package/dnf.rb +++ b/lib/puppet/provider/package/dnf.rb @@ -46,6 +46,14 @@ def self.update_command 'upgrade' end + # dnf5 removed the -d (debuglevel) and -e (errorlevel) flags. + # These were already deprecated in dnf4. + # + # @return [Array] empty array + def self.quiet_flags + [] + end + # The value to pass to DNF as its error output level. # DNF differs from Yum slightly with regards to error outputting. # diff --git a/lib/puppet/provider/package/dnfmodule.rb b/lib/puppet/provider/package/dnfmodule.rb index 8d58d2fdd8f..0f6d5a6f9f5 100644 --- a/lib/puppet/provider/package/dnfmodule.rb +++ b/lib/puppet/provider/package/dnfmodule.rb @@ -35,7 +35,7 @@ def self.prefetch(packages) def self.instances packages = [] - cmd = "#{command(:dnf)} module list -y -d 0 -e #{error_level}" + cmd = ([command(:dnf), 'module', 'list', '-y'] + quiet_flags).join(' ') execute(cmd).each_line do |line| # select only lines with actual packages since DNF clutters the output next unless line =~ /\[[eix]\][, ]/ @@ -90,7 +90,7 @@ def install enable(args) else begin - execute([command(:dnf), 'module', 'install', '-d', '0', '-e', self.class.error_level, '-y', args]) + execute([command(:dnf), 'module', 'install'] + self.class.quiet_flags + ['-y', args]) rescue Puppet::ExecutionFailure => e # module has no default profile and no profile was requested, so just enable the stream # DNF versions prior to 4.2.8 do not need this workaround @@ -117,20 +117,20 @@ def insync?(is) end def enable(args = @resource[:name]) - execute([command(:dnf), 'module', 'enable', '-d', '0', '-e', self.class.error_level, '-y', args]) + execute([command(:dnf), 'module', 'enable'] + self.class.quiet_flags + ['-y', args]) end def uninstall - execute([command(:dnf), 'module', 'remove', '-d', '0', '-e', self.class.error_level, '-y', @resource[:name]]) + execute([command(:dnf), 'module', 'remove'] + self.class.quiet_flags + ['-y', @resource[:name]]) reset # reset module to the default stream end def disable(args = @resource[:name]) - execute([command(:dnf), 'module', 'disable', '-d', '0', '-e', self.class.error_level, '-y', args]) + execute([command(:dnf), 'module', 'disable'] + self.class.quiet_flags + ['-y', args]) end def reset - execute([command(:dnf), 'module', 'reset', '-d', '0', '-e', self.class.error_level, '-y', @resource[:name]]) + execute([command(:dnf), 'module', 'reset'] + self.class.quiet_flags + ['-y', @resource[:name]]) end def flavor diff --git a/lib/puppet/provider/package/yum.rb b/lib/puppet/provider/package/yum.rb index 15bc372c6b3..ac02716c381 100644 --- a/lib/puppet/provider/package/yum.rb +++ b/lib/puppet/provider/package/yum.rb @@ -186,6 +186,12 @@ def self.error_level '0' end + # Flags to suppress debug and error output from the package manager. + # @return [Array] command-line flags + def self.quiet_flags + ['-d', '0', '-e', error_level] + end + def self.update_command # In yum both `upgrade` and `update` can be used to update packages # `yum upgrade` == `yum --obsoletes update` @@ -243,11 +249,11 @@ def available_versions(package_name, disablerepo, enablerepo, disableexcludes) def install wanted = @resource[:name] - error_level = self.class.error_level + quiet_flags = self.class.quiet_flags update_command = self.class.update_command # 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)] + quiet_flags + ['-y', install_options, :list, wanted].compact) end should = @resource.should(:ensure) @@ -309,8 +315,7 @@ 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 + command = [command(:cmd)] + quiet_flags + ["-y", install_options, operation, wanted].compact output = execute(command) if output.to_s =~ /^No package #{wanted} available\.$/ From 129dac80990d4b56ffa67e19e8e98d6b70be9e67 Mon Sep 17 00:00:00 2001 From: Raman Vasikarla <25852516+raman1236@users.noreply.github.com> Date: Mon, 11 May 2026 03:47:39 +0000 Subject: [PATCH 2/2] test: add quiet_flags spec to verify dnf5 compatibility (empty array) --- spec/unit/provider/package/dnf_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spec/unit/provider/package/dnf_spec.rb b/spec/unit/provider/package/dnf_spec.rb index 9332d4200f6..a30825c35fb 100644 --- a/spec/unit/provider/package/dnf_spec.rb +++ b/spec/unit/provider/package/dnf_spec.rb @@ -58,5 +58,11 @@ it { is_expected.to be_install_only } end + describe '.quiet_flags' do + it 'returns an empty array to avoid using deprecated -d/-e flags removed in dnf5' do + expect(described_class.quiet_flags).to eq([]) + end + end + it_behaves_like 'RHEL package provider', described_class, 'dnf' end