validate_cmd: Use Puppet::Util.execute
This commit is contained in:
parent
bda25ac087
commit
683ac8f8aa
2 changed files with 7 additions and 8 deletions
|
@ -1,3 +1,5 @@
|
|||
require 'puppet/util/execution'
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:validate_cmd, :doc => <<-'ENDHEREDOC') do |args|
|
||||
Perform validation of a string with an external command.
|
||||
|
@ -30,15 +32,12 @@ module Puppet::Parser::Functions
|
|||
tmpfile = Tempfile.new("validate_cmd")
|
||||
begin
|
||||
tmpfile.write(content)
|
||||
output = `#{checkscript} #{tmpfile.path} 2>&1 1>/dev/null`
|
||||
r = $?
|
||||
Puppet::Util.execute("#{checkscript} #{tmpfile.path}")
|
||||
rescue Puppet::ExecutionFailure => detail
|
||||
msg += "\n#{detail}"
|
||||
raise Puppet::ParseError, msg
|
||||
ensure
|
||||
tmpfile.close
|
||||
tmpfile.unlink
|
||||
end
|
||||
if output
|
||||
msg += "\nOutput is:\n#{output}"
|
||||
end
|
||||
raise Puppet::ParseError, (msg) unless r == 0
|
||||
end
|
||||
end
|
||||
|
|
|
@ -74,7 +74,7 @@ describe Puppet::Parser::Functions.function(:validate_cmd) do
|
|||
|
||||
describe "Test output message" do
|
||||
it "validate_cmd('whatever', 'kthnksbye') should fail" do
|
||||
expect { subject.call ['whatever', 'kthnksbye'] }.to raise_error /kthnksbye.*not found/
|
||||
expect { subject.call ['whatever', 'kthnksbye'] }.to raise_error /kthnksbye.* returned 1/
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue