Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
(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.
  • Loading branch information
Ashley Penney committed Nov 22, 2013
commit 878bf496175a4efd6791bf43b7adae6f5164aa27
24 changes: 22 additions & 2 deletions lib/puppet/provider/postgresql_psql/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@ def command()
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
Expand Down Expand Up @@ -61,10 +67,24 @@ def run_sql_command(sql)

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

Expand Down
32 changes: 15 additions & 17 deletions spec/unit/puppet/provider/postgresql_psql/ruby_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
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
Expand All @@ -32,11 +31,10 @@

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
Expand All @@ -46,11 +44,10 @@
} 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
Expand All @@ -60,11 +57,12 @@
} 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
Expand Down