Skip to content

Commit 88eaa4c

Browse files
authored
Merge pull request #8769 from Dorin-Pleava/PUP-11208/retry_pkg_install_when_exitcode_7
(PUP-11208) Retry pkg install on Solaris
2 parents 62c2cba + 2faf6ce commit 88eaa4c

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

lib/puppet/provider/package/pkg.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,17 @@ def install(nofail = false)
241241
end
242242
self.unhold if self.properties[:mark] == :hold
243243
begin
244+
tries = 1
245+
# pkg install exits with code 7 when the image is currently in use by another process and cannot be modified
244246
r = exec_cmd(command(:pkg), command, *args, name)
247+
while r[:exit] == 7 do
248+
if tries > 4
249+
raise Puppet::Error, _("Pkg could not install %{name} after %{tries} tries. Aborting run") % { name: name, tries: tries }
250+
end
251+
sleep 2 ** tries
252+
tries += 1
253+
r = exec_cmd(command(:pkg), command, *args, name)
254+
end
245255
ensure
246256
self.hold if @resource[:mark] == :hold
247257
end

spec/unit/provider/package/pkg_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,20 @@ def self.it_should_respond_to(*actions)
411411
allow($CHILD_STATUS).to receive(:exitstatus).and_return(0)
412412
provider.insync?(is)
413413
end
414+
415+
it "should try 5 times to install and fail when all tries failed" do
416+
allow_any_instance_of(Kernel).to receive(:sleep)
417+
418+
expect(provider).to receive(:query).and_return({:ensure => :absent})
419+
expect(provider).to receive(:properties).and_return({:mark => :hold})
420+
expect(provider).to receive(:unhold)
421+
expect(Puppet::Util::Execution).to receive(:execute)
422+
.with(['/bin/pkg', 'install', *hash[:flags], 'dummy'], {:failonfail => false, :combine => true}).exactly(5).times
423+
allow($CHILD_STATUS).to receive(:exitstatus).and_return(7)
424+
expect {
425+
provider.update
426+
}.to raise_error(Puppet::Error, /Pkg could not install dummy after 5 tries. Aborting run/)
427+
end
414428
end
415429
end
416430
end

0 commit comments

Comments
 (0)