diff options
-rw-r--r-- | lib/puppet.rb | 4 | ||||
-rw-r--r-- | lib/puppet/type.rb | 5 | ||||
-rwxr-xr-x | lib/puppet/type/exec.rb | 32 | ||||
-rwxr-xr-x | test/types/exec.rb | 17 |
4 files changed, 47 insertions, 11 deletions
diff --git a/lib/puppet.rb b/lib/puppet.rb index 9bbec2761..102024dfb 100644 --- a/lib/puppet.rb +++ b/lib/puppet.rb @@ -48,10 +48,6 @@ module Puppet str = @message.to_s end - #if Puppet[:debug] and @stack - # str += @stack.to_s - #end - return str end end diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index 6a28184f2..8663a6aa4 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -928,7 +928,8 @@ class Type < Puppet::Element end param = klass.new param.parent = self - if value + + unless value.nil? param.value = value end @@ -1338,6 +1339,8 @@ class Type < Puppet::Element if hash.include?(name) begin self[name] = hash[name] + rescue ArgumentError, Puppet::Error, TypeError + raise rescue => detail self.devfail( "Could not set %s on %s: %s" % diff --git a/lib/puppet/type/exec.rb b/lib/puppet/type/exec.rb index d5c2ea7d1..a7d637e57 100755 --- a/lib/puppet/type/exec.rb +++ b/lib/puppet/type/exec.rb @@ -240,6 +240,10 @@ module Puppet desc "The directory from which to run the command. If this directory does not exist, the command will fail." + validate do |dir| + self.fail("CWD must be a fully qualified path") unless dir + end + munge do |dir| if dir.is_a?(Array) dir = dir[0] @@ -284,6 +288,8 @@ module Puppet " + newvalues(:true, :false) + # We always fail this test, because we're only supposed to run # on refresh. def check @@ -309,6 +315,8 @@ module Puppet # FIXME if they try to set this and fail, then we should probably # fail the entire exec, right? validate do |file| + self.fail("'creates' must be set to a fully qualified path") unless file + unless file =~ %r{^#{File::SEPARATOR}} self.fail "'creates' files must be fully qualified." end @@ -337,6 +345,10 @@ module Puppet which is to say that it must be fully qualified if the path is not set. " + validate do |cmd| + @parent.validatecmd(cmd) + end + # Return true if the command does not return 0. def check output, status = @parent.run(self.value) @@ -360,6 +372,10 @@ module Puppet which is to say that it must be fully qualified if the path is not set. " + validate do |cmd| + @parent.validatecmd(cmd) + end + # Return true if the command returns 0. def check output, status = @parent.run(self.value) @@ -372,12 +388,7 @@ module Puppet @isomorphic = false validate do - # if we're not fully qualified, require a path - if self[:command] !~ /^\// - if self[:path].nil? - self.fail "both unqualifed and specified no search path" - end - end + validatecmd(self[:command]) end autorequire(:file) do @@ -478,6 +489,15 @@ module Puppet def to_s "exec(%s)" % self.name end + + def validatecmd(cmd) + # if we're not fully qualified, require a path + if cmd !~ /^\// + if self[:path].nil? + self.fail "both unqualifed and specified no search path" + end + end + end end end diff --git a/test/types/exec.rb b/test/types/exec.rb index 3006ef0ec..f776dbd3b 100755 --- a/test/types/exec.rb +++ b/test/types/exec.rb @@ -432,6 +432,23 @@ class TestExec < Test::Unit::TestCase assert(FileTest.exists?(path), "Exec ran first") assert(File.stat(path).mode & 007777 == 0755) end + + def test_falsevals + exec = nil + assert_nothing_raised do + exec = Puppet.type(:exec).create( + :command => "/bin/touch yayness" + ) + end + + Puppet.type(:exec).checks.each do |check| + klass = Puppet.type(:exec).paramclass(check) + next if klass.values.include? :false + assert_raise(Puppet::Error, "Check %s did not fail on false" % check) do + exec[check] = false + end + end + end end # $Id$ |