From 3fd65d784c69b85502b4307b7375899877223002 Mon Sep 17 00:00:00 2001 From: Alan Date: Mon, 18 Mar 2024 12:38:16 +1100 Subject: [PATCH] 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. --- lib/puppet/provider/package/pkg.rb | 4 ++++ spec/unit/provider/package/pkg_spec.rb | 18 ++++++------------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/lib/puppet/provider/package/pkg.rb b/lib/puppet/provider/package/pkg.rb index 68b0d68cab7..8fc4c200663 100644 --- a/lib/puppet/provider/package/pkg.rb +++ b/lib/puppet/provider/package/pkg.rb @@ -160,6 +160,10 @@ def insync?(is) warning(_("Implicit version %{should} has %{n} possible matches") % { should: should, n: n }) end potential_matches.each { |p| + # If the version that we match is installed then we don't need + # to check if it's installed (or installable), just return true + return true if is != :absent && p[:status] == 'installed' + command = is == :absent ? 'install' : 'update' options = ['-n'] options.concat(join_options(@resource[:install_options])) if @resource[:install_options] diff --git a/spec/unit/provider/package/pkg_spec.rb b/spec/unit/provider/package/pkg_spec.rb index 588f2574738..9ab46eb417a 100644 --- a/spec/unit/provider/package/pkg_spec.rb +++ b/spec/unit/provider/package/pkg_spec.rb @@ -286,13 +286,9 @@ def self.it_should_respond_to(*actions) it "should install specific version(2)" do resource[:ensure] = '0.0.8' - expect(provider).to receive(:properties).and_return({:mark => :hold}) - expect(Puppet::Util::Execution).to receive(:execute) - .with(['/bin/pkg', 'unfreeze', 'dummy'], {:failonfail => false, :combine => true}) - .and_return(Puppet::Util::Execution::ProcessOutput.new('', 0)) - expect(Puppet::Util::Execution).to receive(:execute) - .with(['/bin/pkg', 'list', '-Hv', 'dummy'], {:failonfail => false, :combine => true}) - .and_return(Puppet::Util::Execution::ProcessOutput.new('pkg://foo/dummy@0.0.7,5.11-0.151006:20131230T130000Z installed -----', 0)) + expect(Puppet::Util::Execution).to receive(:execute) + .with(['/bin/pkg', 'list', '-Hv', 'dummy'], {:failonfail => false, :combine => true}) + .and_return(Puppet::Util::Execution::ProcessOutput.new('pkg://foo/dummy@0.0.7,5.11-0.151006:20131230T13000 installed -----', 0)).exactly(2).times expect(Puppet::Util::Execution).to receive(:execute) .with(['/bin/pkg', 'update', *hash[:flags], 'dummy@0.0.8'], {:failonfail => false, :combine => true}) .and_return(Puppet::Util::Execution::ProcessOutput.new('', 0)) @@ -301,11 +297,9 @@ def self.it_should_respond_to(*actions) it "should downgrade to specific version" do resource[:ensure] = '0.0.7' - expect(provider).to receive(:properties).and_return({:mark => :hold}) - expect(provider).to receive(:query).with(no_args).and_return({:ensure => '0.0.8,5.11-0.151106:20131230T130000Z'}) - expect(Puppet::Util::Execution).to receive(:execute) - .with(['/bin/pkg', 'unfreeze', 'dummy'], {:failonfail => false, :combine => true}) - .and_return(Puppet::Util::Execution::ProcessOutput.new('', 0)) + expect(Puppet::Util::Execution).to receive(:execute) + .with(['/bin/pkg', 'list', '-Hv', 'dummy'], {:failonfail => false, :combine => true}) + .and_return(Puppet::Util::Execution::ProcessOutput.new('pkg://foo/dummy@0.0.8,5.11-0.151106:20131230T130000Z installed -----', 0)).exactly(2).times expect(Puppet::Util::Execution).to receive(:execute) .with(['/bin/pkg', 'update', *hash[:flags], 'dummy@0.0.7'], {:failonfail => false, :combine => true}) .and_return(Puppet::Util::Execution::ProcessOutput.new('', 0))