Skip to content
Open
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions lib/puppet/provider/package/dnf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>] 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.
#
Expand Down
12 changes: 6 additions & 6 deletions lib/puppet/provider/package/dnfmodule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]\][, ]/
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
13 changes: 9 additions & 4 deletions lib/puppet/provider/package/yum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ def self.error_level
'0'
end

# Flags to suppress debug and error output from the package manager.
# @return [Array<String>] 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`
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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\.$/
Expand Down