Skip to content

Commit 3fd65d7

Browse files
Calling "pkg update -n" on Solaris too frequently causes problems with zones
On a Solaris system, running "pkg update -n" in the global zone at the same time that it is running in a non-global zone, can cause the command to fail in one or the other. If we have puppet running this command, it causes the puppet run to fail for that specific resource. This patch removes some unnecessary calls to this command, and appropriately updates rspec.
1 parent 1a53bf7 commit 3fd65d7

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

lib/puppet/provider/package/pkg.rb

+4
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ def insync?(is)
160160
warning(_("Implicit version %{should} has %{n} possible matches") % { should: should, n: n })
161161
end
162162
potential_matches.each { |p|
163+
# If the version that we match is installed then we don't need
164+
# to check if it's installed (or installable), just return true
165+
return true if is != :absent && p[:status] == 'installed'
166+
163167
command = is == :absent ? 'install' : 'update'
164168
options = ['-n']
165169
options.concat(join_options(@resource[:install_options])) if @resource[:install_options]

spec/unit/provider/package/pkg_spec.rb

+6-12
Original file line numberDiff line numberDiff line change
@@ -286,13 +286,9 @@ def self.it_should_respond_to(*actions)
286286

287287
it "should install specific version(2)" do
288288
resource[:ensure] = '0.0.8'
289-
expect(provider).to receive(:properties).and_return({:mark => :hold})
290-
expect(Puppet::Util::Execution).to receive(:execute)
291-
.with(['/bin/pkg', 'unfreeze', 'dummy'], {:failonfail => false, :combine => true})
292-
.and_return(Puppet::Util::Execution::ProcessOutput.new('', 0))
293-
expect(Puppet::Util::Execution).to receive(:execute)
294-
.with(['/bin/pkg', 'list', '-Hv', 'dummy'], {:failonfail => false, :combine => true})
295-
.and_return(Puppet::Util::Execution::ProcessOutput.new('pkg://foo/[email protected],5.11-0.151006:20131230T130000Z installed -----', 0))
289+
expect(Puppet::Util::Execution).to receive(:execute)
290+
.with(['/bin/pkg', 'list', '-Hv', 'dummy'], {:failonfail => false, :combine => true})
291+
.and_return(Puppet::Util::Execution::ProcessOutput.new('pkg://foo/[email protected],5.11-0.151006:20131230T13000 installed -----', 0)).exactly(2).times
296292
expect(Puppet::Util::Execution).to receive(:execute)
297293
.with(['/bin/pkg', 'update', *hash[:flags], '[email protected]'], {:failonfail => false, :combine => true})
298294
.and_return(Puppet::Util::Execution::ProcessOutput.new('', 0))
@@ -301,11 +297,9 @@ def self.it_should_respond_to(*actions)
301297

302298
it "should downgrade to specific version" do
303299
resource[:ensure] = '0.0.7'
304-
expect(provider).to receive(:properties).and_return({:mark => :hold})
305-
expect(provider).to receive(:query).with(no_args).and_return({:ensure => '0.0.8,5.11-0.151106:20131230T130000Z'})
306-
expect(Puppet::Util::Execution).to receive(:execute)
307-
.with(['/bin/pkg', 'unfreeze', 'dummy'], {:failonfail => false, :combine => true})
308-
.and_return(Puppet::Util::Execution::ProcessOutput.new('', 0))
300+
expect(Puppet::Util::Execution).to receive(:execute)
301+
.with(['/bin/pkg', 'list', '-Hv', 'dummy'], {:failonfail => false, :combine => true})
302+
.and_return(Puppet::Util::Execution::ProcessOutput.new('pkg://foo/[email protected],5.11-0.151106:20131230T130000Z installed -----', 0)).exactly(2).times
309303
expect(Puppet::Util::Execution).to receive(:execute)
310304
.with(['/bin/pkg', 'update', *hash[:flags], '[email protected]'], {:failonfail => false, :combine => true})
311305
.and_return(Puppet::Util::Execution::ProcessOutput.new('', 0))

0 commit comments

Comments
 (0)