Skip to content

Commit

Permalink
Merge pull request #49 from StatensPensjonskasse/Workaround-libaugeas…
Browse files Browse the repository at this point in the history
…-save/load-issue

Workaround libaugeas save/load issue
  • Loading branch information
ekohl authored Apr 24, 2023
2 parents 9f5bf7f + da34348 commit 401a167
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/puppet/provider/augeasprovider/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ def self.augsave!(aug, reload = false)
raise Augeas::Error, 'Failed to save Augeas tree to file. See debug logs for details.'
ensure
aug.load! if reload
# https://github.com/hercules-team/augeas/commit/eb04250a05671b2d001444b72b8778328d209d75 introduced a bug in libaugeas.so.0.25.0
# bundled with puppet7.
# A temporary fix is to invoke load! twice.
aug.load! if reload && Puppet::Util::Package.versioncmp(aug_version, '1.13.0') >= 0
end

# Define a method with a block passed to #augopen
Expand Down
20 changes: 20 additions & 0 deletions spec/unit/puppet/provider/augeasprovider/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,26 @@ class Test < provider_class
-> { provider.augsave!(aug) }.should raise_error Augeas::Error, %r{Failed to save Augeas tree}
end
end

describe 'with reload' do
it 'is expected to call #load! once with augeas < 1.13.0' do
provider.augopen(resource) do |aug|
allow(provider).to receive(:aug_version).twice.and_return '1.12.0' # rubocop:disable RSpec/SubjectStub
expect(aug).to receive(:load!).once
aug.set("/files#{thetarget}/dummy")
provider.augsave!(aug, true)
end
end

it 'is expected to call #load! twice with augeas >= 1.13.0' do
provider.augopen(resource) do |aug|
allow(provider).to receive(:aug_version).twice.and_return '1.13.0' # rubocop:disable RSpec/SubjectStub
expect(aug).to receive(:load!).twice
aug.set("/files#{thetarget}/dummy")
provider.augsave!(aug, true)
end
end
end
end

describe '#path_label' do
Expand Down

0 comments on commit 401a167

Please sign in to comment.