Merge branch 'pull-126'

This commit is contained in:
Adrien Thebo 2013-02-12 10:20:22 -08:00
commit 36a7b29630
2 changed files with 15 additions and 9 deletions

View file

@ -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.
@ -28,14 +30,18 @@ module Puppet::Parser::Functions
# Test content in a temporary file
tmpfile = Tempfile.new("validate_cmd")
tmpfile.write(content)
tmpfile.close
output = `#{checkscript} #{tmpfile.path} 2>&1 1>/dev/null`
r = $?
File.delete(tmpfile.path)
if output
msg += "\nOutput is:\n#{output}"
begin
tmpfile.write(content)
if Puppet::Util::Execution.respond_to?('execute')
Puppet::Util::Execution.execute("#{checkscript} #{tmpfile.path}")
else
Puppet::Util.execute("#{checkscript} #{tmpfile.path}")
end
rescue Puppet::ExecutionFailure => detail
msg += "\n#{detail}"
raise Puppet::ParseError, msg
ensure
tmpfile.unlink
end
raise Puppet::ParseError, (msg) unless r == 0
end
end

View file

@ -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