File tree Expand file tree Collapse file tree
lib/puppet/parser/functions
spec/unit/puppet/parser/functions Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ require 'puppet/util/execution'
2+
13module Puppet ::Parser ::Functions
24 newfunction ( :validate_cmd , :doc => <<-'ENDHEREDOC' ) do |args |
35 Perform validation of a string with an external command.
@@ -28,14 +30,18 @@ module Puppet::Parser::Functions
2830
2931 # Test content in a temporary file
3032 tmpfile = Tempfile . new ( "validate_cmd" )
31- tmpfile . write ( content )
32- tmpfile . close
33- output = `#{ checkscript } #{ tmpfile . path } 2>&1 1>/dev/null`
34- r = $?
35- File . delete ( tmpfile . path )
36- if output
37- msg += "\n Output is:\n #{ output } "
33+ begin
34+ tmpfile . write ( content )
35+ if Puppet ::Util ::Execution . respond_to? ( 'execute' )
36+ Puppet ::Util ::Execution . execute ( "#{ checkscript } #{ tmpfile . path } " )
37+ else
38+ Puppet ::Util . execute ( "#{ checkscript } #{ tmpfile . path } " )
39+ end
40+ rescue Puppet ::ExecutionFailure => detail
41+ msg += "\n #{ detail } "
42+ raise Puppet ::ParseError , msg
43+ ensure
44+ tmpfile . unlink
3845 end
39- raise Puppet ::ParseError , ( msg ) unless r == 0
4046 end
4147end
Original file line number Diff line number Diff line change 7474
7575 describe "Test output message" do
7676 it "validate_cmd('whatever', 'kthnksbye') should fail" do
77- expect { subject . call [ 'whatever' , 'kthnksbye' ] } . to raise_error /kthnksbye.*not found /
77+ expect { subject . call [ 'whatever' , 'kthnksbye' ] } . to raise_error /kthnksbye.* returned 1 /
7878 end
7979 end
8080 end
You can’t perform that action at this time.
0 commit comments