Skip to content

Commit

Permalink
correctly enable module:stream without default profile with dnfmodule
Browse files Browse the repository at this point in the history
the old code would work correctly for ensure => present, but not for
ensure => 'some_stream', as dnf does include the whole module spec in
the error message and the old regex didn't match anymore.

```
Error: Problems in request:
broken groups or modules: 389-ds

Error: Problems in request:
broken groups or modules: 389-ds:1.4
```
  • Loading branch information
evgeni committed Oct 30, 2023
1 parent a980249 commit c16adb6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/puppet/provider/package/dnfmodule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def install
# 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
# see https://bugzilla.redhat.com/show_bug.cgi?id=1669527
if @resource[:flavor] == nil && e.message =~ /^(?:missing|broken) groups or modules: #{Regexp.quote(@resource[:name])}$/
if @resource[:flavor] == nil && e.message =~ /^(?:missing|broken) groups or modules: #{Regexp.quote(args)}$/
enable(args)
else
raise
Expand Down
24 changes: 22 additions & 2 deletions spec/unit/provider/package/dnfmodule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
provider.install
end

it "should just enable the module if it has no default profile(missing groups or modules)" do
it "should just enable the module if it has no default profile (missing groups or modules)" do
dnf_exception = Puppet::ExecutionFailure.new("Error: Problems in request:\nmissing groups or modules: #{resource[:name]}")
allow(provider).to receive(:execute).with(array_including('install')).and_raise(dnf_exception)
resource[:ensure] = :present
Expand All @@ -132,7 +132,17 @@
provider.install
end

it "should just enable the module if it has no default profile(broken groups or modules)" do
it "should just enable the module with the right stream if it has no default profile (missing groups or modules)" do
stream = '12.3'
dnf_exception = Puppet::ExecutionFailure.new("Error: Problems in request:\nmissing groups or modules: #{resource[:name]}:#{stream}")
allow(provider).to receive(:execute).with(array_including('install')).and_raise(dnf_exception)
resource[:ensure] = stream
expect(provider).to receive(:execute).with(array_including('install')).ordered
expect(provider).to receive(:execute).with(array_including('enable')).ordered
provider.install
end

it "should just enable the module if it has no default profile (broken groups or modules)" do
dnf_exception = Puppet::ExecutionFailure.new("Error: Problems in request:\nbroken groups or modules: #{resource[:name]}")
allow(provider).to receive(:execute).with(array_including('install')).and_raise(dnf_exception)
resource[:ensure] = :present
Expand All @@ -141,6 +151,16 @@
provider.install
end

it "should just enable the module with the right stream if it has no default profile (broken groups or modules)" do
stream = '12.3'
dnf_exception = Puppet::ExecutionFailure.new("Error: Problems in request:\nbroken groups or modules: #{resource[:name]}:#{stream}")
allow(provider).to receive(:execute).with(array_including('install')).and_raise(dnf_exception)
resource[:ensure] = stream
expect(provider).to receive(:execute).with(array_including('install')).ordered
expect(provider).to receive(:execute).with(array_including('enable')).ordered
provider.install
end

it "should just enable the module if enable_only = true" do
resource[:ensure] = :present
resource[:enable_only] = true
Expand Down

0 comments on commit c16adb6

Please sign in to comment.