Skip to content

Add fix for package running dnf5 on fedora (alternative) #9536

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

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
12 changes: 6 additions & 6 deletions lib/puppet/provider/package/dnfmodule.rb
Original file line number Diff line number Diff line change
@@ -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"
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', '-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', '-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', '-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', '-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', '-y', @resource[:name]])
end

def flavor
7 changes: 2 additions & 5 deletions lib/puppet/provider/package/yum.rb
Original file line number Diff line number Diff line change
@@ -247,7 +247,7 @@ def install
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), '-y', install_options, :list, wanted].compact)
end

should = @resource.should(:ensure)
@@ -307,10 +307,7 @@ def install
end
end

# 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)] + ["-y", install_options, operation, wanted].compact
output = execute(command)

if output.to_s =~ /^No package #{wanted} available\.$/
22 changes: 11 additions & 11 deletions spec/unit/provider/package/yum_spec.rb
Original file line number Diff line number Diff line change
@@ -363,7 +363,7 @@

it 'selects best_version' do
expect(provider).to receive(:execute).with(
['/usr/bin/yum', '-d', '0', '-e', '0', '-y', :install, 'myresource-18.3.2']
['/usr/bin/yum', '-y', :install, 'myresource-18.3.2']
)
provider.install
end
@@ -374,7 +374,7 @@

it 'treats no epoch as zero' do
expect(provider).to receive(:execute).with(
['/usr/bin/yum', '-d', '0', '-e', '0', '-y', :install, 'myresource-18.3.2']
['/usr/bin/yum', '-y', :install, 'myresource-18.3.2']
)
provider.install
end
@@ -387,7 +387,7 @@

it 'selects best_version and removes epoch' do
expect(provider).to receive(:execute).with(
['/usr/bin/yum', '-d', '0', '-e', '0', '-y', :install, 'myresource-18.3.2']
['/usr/bin/yum', '-y', :install, 'myresource-18.3.2']
)
provider.install
end
@@ -399,14 +399,14 @@

it 'uses requested version' do
expect(provider).to receive(:execute).with(
['/usr/bin/yum', '-d', '0', '-e', '0', '-y', :install, "myresource->18.1 <19"]
['/usr/bin/yum', '-y', :install, "myresource->18.1 <19"]
)
provider.install
end

it 'logs a debug message' do
allow(provider).to receive(:execute).with(
['/usr/bin/yum', '-d', '0', '-e', '0', '-y', :install, "myresource->18.1 <19"]
['/usr/bin/yum', '-y', :install, "myresource->18.1 <19"]
)

expect(Puppet).to receive(:debug).with(
@@ -422,7 +422,7 @@

it 'passes the version to yum command' do
expect(provider).to receive(:execute).with(
['/usr/bin/yum', '-d', '0', '-e', '0', '-y', :install, "myresource-1:18.12"]
['/usr/bin/yum', '-y', :install, "myresource-1:18.12"]
)
provider.install
end
@@ -440,7 +440,7 @@

it 'adds update flag to install command' do
expect(provider).to receive(:execute).with(
['/usr/bin/yum', '-d', '0', '-e', '0', '-y', 'update', 'myresource-18.3.2']
['/usr/bin/yum', '-y', 'update', 'myresource-18.3.2']
)
provider.install
end
@@ -458,7 +458,7 @@

it 'adds downgrade flag to install command' do
expect(provider).to receive(:execute).with(
['/usr/bin/yum', '-d', '0', '-e', '0', '-y', :downgrade, 'myresource-18.3.2']
['/usr/bin/yum', '-y', :downgrade, 'myresource-18.3.2']
)
provider.install
end
@@ -470,7 +470,7 @@
context 'when execute command fails' do
before do
allow(provider).to receive(:execute).with(
['/usr/bin/yum', '-d', '0', '-e', '0', '-y', :install, "myresource-20"]
['/usr/bin/yum', '-y', :install, "myresource-20"]
).and_return('No package myresource-20 available.')
end

@@ -484,7 +484,7 @@
before do
allow(provider).to receive(:query)
allow(provider).to receive(:execute).with(
['/usr/bin/yum', '-d', '0', '-e', '0', '-y', :install, "myresource-20"]
['/usr/bin/yum', '-y', :install, "myresource-20"]
)
end

@@ -497,7 +497,7 @@
context 'when package is not installed' do
before do
allow(provider).to receive(:execute).with(
['/usr/bin/yum', '-d', '0', '-e', '0', '-y', :install, "myresource-20"]
['/usr/bin/yum', '-y', :install, "myresource-20"]
)
allow(provider).to receive(:insync?).and_return(false)
end