From da34348698fad3a280e496f776f836a385b125db Mon Sep 17 00:00:00 2001 From: Hugo Haakseth Date: Sat, 22 Apr 2023 12:30:16 +0200 Subject: [PATCH] Workaround libaugeas save/load issue --- lib/puppet/provider/augeasprovider/default.rb | 4 ++++ .../provider/augeasprovider/default_spec.rb | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/lib/puppet/provider/augeasprovider/default.rb b/lib/puppet/provider/augeasprovider/default.rb index 0eb1f29..65e93eb 100644 --- a/lib/puppet/provider/augeasprovider/default.rb +++ b/lib/puppet/provider/augeasprovider/default.rb @@ -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 diff --git a/spec/unit/puppet/provider/augeasprovider/default_spec.rb b/spec/unit/puppet/provider/augeasprovider/default_spec.rb index a921c87..511d050 100755 --- a/spec/unit/puppet/provider/augeasprovider/default_spec.rb +++ b/spec/unit/puppet/provider/augeasprovider/default_spec.rb @@ -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