From 878bf496175a4efd6791bf43b7adae6f5164aa27 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Thu, 21 Nov 2013 16:30:24 -0800 Subject: [PATCH] (FM-486) Fix deprecated Puppet::Util::SUIDManager.run_and_capture Puppet::Util::SUIDManager.run_and_capture recently changed to Execution.execute, switch before it blows up and stops working. --- lib/puppet/provider/postgresql_psql/ruby.rb | 24 ++++++++++++-- .../provider/postgresql_psql/ruby_spec.rb | 32 +++++++++---------- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/lib/puppet/provider/postgresql_psql/ruby.rb b/lib/puppet/provider/postgresql_psql/ruby.rb index 70d0704..18a2d8f 100644 --- a/lib/puppet/provider/postgresql_psql/ruby.rb +++ b/lib/puppet/provider/postgresql_psql/ruby.rb @@ -16,9 +16,15 @@ Puppet::Type.type(:postgresql_psql).provide(:ruby) do return nil end - output, status = run_unless_sql_command(resource[:unless]) + if Puppet::PUPPETVERSION.to_f < 4 + output, status = run_unless_sql_command(resource[:unless]) + else + output = run_unless_sql_command(resource[:unless]) + status = output.exitcode + end if status != 0 + puts status self.fail("Error evaluating 'unless' clause: '#{output}'") end result_count = output.strip.to_i @@ -61,10 +67,24 @@ Puppet::Type.type(:postgresql_psql).provide(:ruby) do if resource[:cwd] Dir.chdir resource[:cwd] do - Puppet::Util::SUIDManager.run_and_capture(command, resource[:psql_user], resource[:psql_group]) + run_command(command, resource[:psql_user], resource[:psql_group]) end else + run_command(command, resource[:psql_user], resource[:psql_group]) + end + end + + def run_command(command, user, group) + if Puppet::PUPPETVERSION.to_f < 4 Puppet::Util::SUIDManager.run_and_capture(command, resource[:psql_user], resource[:psql_group]) + else + Puppet::Util::Execution.execute(command, {:uid => resource[:psql_user], + :gid => resource[:psql_group], + :failonfail=>false, + :combine=>true, + :override_locale=>true, + :custom_environment=>{} + }) end end diff --git a/spec/unit/puppet/provider/postgresql_psql/ruby_spec.rb b/spec/unit/puppet/provider/postgresql_psql/ruby_spec.rb index ee1a595..325e3db 100644 --- a/spec/unit/puppet/provider/postgresql_psql/ruby_spec.rb +++ b/spec/unit/puppet/provider/postgresql_psql/ruby_spec.rb @@ -13,11 +13,10 @@ describe Puppet::Type.type(:postgresql_psql).provider(:ruby) do let(:attributes) do { :db => 'spec_db' } end it "executes with the given psql_path on the given DB" do - expect(Puppet::Util::SUIDManager).to receive(:run_and_capture).with( - ['psql', '-d', attributes[:db], '-t', '-c', 'SELECT something'], - 'postgres', - 'postgres' - ) + expect(provider).to receive(:run_command).with(['psql', '-d', + attributes[:db], '-t', '-c', 'SELECT something'], 'postgres', + 'postgres') + provider.run_sql_command("SELECT something") end end @@ -32,11 +31,10 @@ describe Puppet::Type.type(:postgresql_psql).provider(:ruby) do it "executes with the given psql_path on the given DB" do expect(Dir).to receive(:chdir).with(attributes[:cwd]).and_yield - expect(Puppet::Util::SUIDManager).to receive(:run_and_capture).with( - [attributes[:psql_path], '-d', attributes[:db], '-t', '-c', 'SELECT something'], - attributes[:psql_user], - attributes[:psql_group] - ) + expect(provider).to receive(:run_command).with([attributes[:psql_path], + '-d', attributes[:db], '-t', '-c', 'SELECT something'], + attributes[:psql_user], attributes[:psql_group]) + provider.run_sql_command("SELECT something") end end @@ -46,11 +44,10 @@ describe Puppet::Type.type(:postgresql_psql).provider(:ruby) do } end it "executes with the given search_path" do - expect(Puppet::Util::SUIDManager).to receive(:run_and_capture).with( - ['psql', '-t', '-c', 'set search_path to schema1; SELECT something'], - 'postgres', - 'postgres' - ) + expect(provider).to receive(:run_command).with(['psql', '-t', '-c', + 'set search_path to schema1; SELECT something'], + 'postgres', 'postgres') + provider.run_sql_command("SELECT something") end end @@ -60,11 +57,12 @@ describe Puppet::Type.type(:postgresql_psql).provider(:ruby) do } end it "executes with the given search_path" do - expect(Puppet::Util::SUIDManager).to receive(:run_and_capture).with( - ['psql', '-t', '-c', 'set search_path to schema1,schema2; SELECT something'], + expect(provider).to receive(:run_command).with(['psql', '-t', '-c', + 'set search_path to schema1,schema2; SELECT something'], 'postgres', 'postgres' ) + provider.run_sql_command("SELECT something") end end