diff options
author | Raphaël Pinson <raphael.pinson@camptocamp.com> | 2013-02-05 09:01:48 +0100 |
---|---|---|
committer | Raphaël Pinson <raphael.pinson@camptocamp.com> | 2013-02-06 18:03:11 +0100 |
commit | 683ac8f8aa5f349ece98165d92a8d271b99b855e (patch) | |
tree | 4a57f604278711ee1f586b7bf558514ebda7d776 | |
parent | bda25ac0872a101b59d8ab473218ff0f14bb7433 (diff) | |
download | puppet-stdlib-683ac8f8aa5f349ece98165d92a8d271b99b855e.tar.gz puppet-stdlib-683ac8f8aa5f349ece98165d92a8d271b99b855e.tar.bz2 |
validate_cmd: Use Puppet::Util.execute
-rw-r--r-- | lib/puppet/parser/functions/validate_cmd.rb | 13 | ||||
-rw-r--r-- | spec/unit/puppet/parser/functions/validate_cmd_spec.rb | 2 |
2 files changed, 7 insertions, 8 deletions
diff --git a/lib/puppet/parser/functions/validate_cmd.rb b/lib/puppet/parser/functions/validate_cmd.rb index 00fe1ae..4f6a766 100644 --- a/lib/puppet/parser/functions/validate_cmd.rb +++ b/lib/puppet/parser/functions/validate_cmd.rb @@ -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 diff --git a/spec/unit/puppet/parser/functions/validate_cmd_spec.rb b/spec/unit/puppet/parser/functions/validate_cmd_spec.rb index 0730a59..69ea7f4 100644 --- a/spec/unit/puppet/parser/functions/validate_cmd_spec.rb +++ b/spec/unit/puppet/parser/functions/validate_cmd_spec.rb @@ -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 |