diff options
-rwxr-xr-x | lib/puppet/provider/parsedfile.rb | 2 | ||||
-rwxr-xr-x | lib/puppet/type/cron.rb | 31 | ||||
-rwxr-xr-x | lib/puppet/type/exec.rb | 64 | ||||
-rwxr-xr-x | lib/puppet/type/pfile/ensure.rb | 2 | ||||
-rw-r--r-- | lib/puppet/util/fileparsing.rb | 2 | ||||
-rwxr-xr-x | test/language/ast.rb | 2 | ||||
-rw-r--r-- | test/lib/puppettest/fileparsing.rb | 1 | ||||
-rwxr-xr-x | test/network/handler/resource.rb | 2 | ||||
-rwxr-xr-x | test/rails/host.rb | 1 | ||||
-rwxr-xr-x | test/ral/providers/host/parsed.rb | 7 | ||||
-rwxr-xr-x | test/ral/types/cron.rb | 56 | ||||
-rwxr-xr-x | test/ral/types/exec.rb | 2 |
12 files changed, 89 insertions, 83 deletions
diff --git a/lib/puppet/provider/parsedfile.rb b/lib/puppet/provider/parsedfile.rb index 3c1ee0943..8d1936ceb 100755 --- a/lib/puppet/provider/parsedfile.rb +++ b/lib/puppet/provider/parsedfile.rb @@ -135,7 +135,7 @@ class Puppet::Provider::ParsedFile < Puppet::Provider define_method(attr.to_s + "=") do |val| # Mark that this target was modified. - modeltarget = @model[:target] || self.class.default_target + modeltarget = @model.should(:target) || self.class.default_target # If they're the same, then just mark that one as modified if @property_hash[:target] and @property_hash[:target] == modeltarget diff --git a/lib/puppet/type/cron.rb b/lib/puppet/type/cron.rb index dd9ed3ab5..ccf5d0449 100755 --- a/lib/puppet/type/cron.rb +++ b/lib/puppet/type/cron.rb @@ -105,6 +105,14 @@ Puppet::Type.newtype(:cron) do end end + def is=(val) + if val.is_a?(Array) + @is = val + else + @is = [val] + end + end + def is_to_s if @is unless @is.is_a?(Array) @@ -122,7 +130,16 @@ Puppet::Type.newtype(:cron) do end def should - @should + if @should and @should[0] == :absent + :absent + else + @should + end + end + + def should=(ary) + super + @should.flatten! end # The method that does all of the actual parameter value @@ -189,6 +206,14 @@ Puppet::Type.newtype(:cron) do All cron parameters support ``absent`` as a value; this will remove any existing values for that field." + def is + if @is + @is[0] + else + nil + end + end + def should if @should if @should.is_a? Array @@ -352,10 +377,10 @@ Puppet::Type.newtype(:cron) do name = symbolize(name) ret = nil if obj = @parameters[name] - ret = obj.should_to_s + ret = obj.should if ret.nil? - ret = obj.is_to_s + ret = obj.is end if ret == :absent diff --git a/lib/puppet/type/exec.rb b/lib/puppet/type/exec.rb index 33796b129..fd85d1202 100755 --- a/lib/puppet/type/exec.rb +++ b/lib/puppet/type/exec.rb @@ -83,39 +83,6 @@ module Puppet return "executed successfully" end - # Verify that we have the executable - def checkexe - cmd = self.parent[:command] - if cmd =~ /^\// - exe = cmd.split(/ /)[0] - unless FileTest.exists?(exe) - self.fail( - "Could not find executable %s" % exe - ) - end - unless FileTest.executable?(exe) - self.fail( - "%s is not executable" % exe - ) - end - elsif path = self.parent[:path] - exe = cmd.split(/ /)[0] - withenv :PATH => self.parent[:path].join(":") do - path = %{which #{exe}}.chomp - if path == "" - self.fail( - "Could not find command '%s'" % exe - ) - end - end - else - self.fail( - "%s is somehow not qualified with no search path" % - self.parent[:command] - ) - end - end - # First verify that all of our checks pass. def retrieve # Default to somethinng @@ -131,8 +98,6 @@ module Puppet def sync olddir = nil - self.checkexe - # We need a dir to change to, even if it's just the cwd dir = self.parent[:cwd] || Dir.pwd @@ -493,6 +458,33 @@ module Puppet return true end + # Verify that we have the executable + def checkexe(cmd) + if cmd =~ /^\// + exe = cmd.split(/ /)[0] + unless FileTest.exists?(exe) + raise ArgumentError, "Could not find executable %s" % exe + end + unless FileTest.executable?(exe) + raise ArgumentError, + "%s is not executable" % exe + end + elsif path = self[:path] + exe = cmd.split(/ /)[0] + withenv :PATH => self[:path].join(":") do + path = %{which #{exe}}.chomp + if path == "" + raise ArgumentError, + "Could not find command '%s'" % exe + end + end + else + raise ArgumentError, + "%s is somehow not qualified with no search path" % + self[:command] + end + end + def output if self.property(:returns).nil? return nil @@ -519,6 +511,8 @@ module Puppet dir = nil + checkexe(command) + if dir = self[:cwd] unless File.directory?(dir) if check diff --git a/lib/puppet/type/pfile/ensure.rb b/lib/puppet/type/pfile/ensure.rb index bb4b3d27a..ea4154f80 100755 --- a/lib/puppet/type/pfile/ensure.rb +++ b/lib/puppet/type/pfile/ensure.rb @@ -109,7 +109,7 @@ module Puppet end def change_to_s - if property = (@parent.property(:content) || @parent.property(:source)) + if property = (@parent.property(:content) || @parent.property(:source)) and ! property.insync? return property.change_to_s else super diff --git a/lib/puppet/util/fileparsing.rb b/lib/puppet/util/fileparsing.rb index 6b59975ab..6ffb69503 100644 --- a/lib/puppet/util/fileparsing.rb +++ b/lib/puppet/util/fileparsing.rb @@ -82,7 +82,7 @@ module Puppet::Util::FileParsing fields.collect { |field| # If the field is marked absent, use the appropriate replacement - if details[field] == :absent or details[field].nil? + if details[field] == :absent or details[field] == [:absent] or details[field].nil? if self.optional.include?(field) self.absent else diff --git a/test/language/ast.rb b/test/language/ast.rb index a71d26c76..29b8004dc 100755 --- a/test/language/ast.rb +++ b/test/language/ast.rb @@ -290,7 +290,7 @@ class TestAST < Test::Unit::TestCase end assert_nothing_raised("Could not find resource") do retval = Puppet::Rails::Resource.find(:all, - :include => :params, + :include => :param_values, :conditions => str) end diff --git a/test/lib/puppettest/fileparsing.rb b/test/lib/puppettest/fileparsing.rb index 65c47e235..ba4f5ad9c 100644 --- a/test/lib/puppettest/fileparsing.rb +++ b/test/lib/puppettest/fileparsing.rb @@ -16,6 +16,7 @@ module PuppetTest::FileParsing assert_nothing_raised("failed to generate %s" % file) do text = @provider.to_file(@provider.target_records(file)) end + text.gsub!(/^# HEADER.+\n/, '') yield if block_given? diff --git a/test/network/handler/resource.rb b/test/network/handler/resource.rb index c714fa156..b89eacac5 100755 --- a/test/network/handler/resource.rb +++ b/test/network/handler/resource.rb @@ -160,8 +160,8 @@ class TestResourceServer < Test::Unit::TestCase assert(! object.should(property), "Incorrectly retrieved %s" % property) end + #assert_apply(object) assert_events([:directory_created], object) - assert(FileTest.directory?(file), "Directory did not get recreated") Dir.rmdir(file) end diff --git a/test/rails/host.rb b/test/rails/host.rb index e8b9a1603..be8bbc288 100755 --- a/test/rails/host.rb +++ b/test/rails/host.rb @@ -155,6 +155,7 @@ class TestRailsHost < Test::Unit::TestCase # I expect it's a caching problem. count = 0 host.resources.find(:all).find_all { |r| r.title =~ /file2/ }.each do |r| + r.save puts "%s => %s" % [r.ref, r.parameters.inspect] assert_equal("notice", r.parameter("loglevel"), "loglevel was not added") diff --git a/test/ral/providers/host/parsed.rb b/test/ral/providers/host/parsed.rb index 2a015e086..eefe0f8ab 100755 --- a/test/ral/providers/host/parsed.rb +++ b/test/ral/providers/host/parsed.rb @@ -111,7 +111,7 @@ class TestParsedHostProvider < Test::Unit::TestCase newtext = nil assert_nothing_raised do - newtext = @provider.to_file(instances) + newtext = @provider.to_file(instances).gsub(/^# HEADER.+\n/, '') end assert_equal(text, newtext) @@ -221,11 +221,6 @@ class TestParsedHostProvider < Test::Unit::TestCase assert(hash[:ip], "Could not find ip for host %s" % name) } end - - def test_mountsparse - files = fakedata("data/types/hosts") - fakedataparse(*files) - end end # $Id$ diff --git a/test/ral/types/cron.rb b/test/ral/types/cron.rb index 96d7cb3f6..ce9631d97 100755 --- a/test/ral/types/cron.rb +++ b/test/ral/types/cron.rb @@ -198,7 +198,7 @@ class TestCron < Test::Unit::TestCase } if value.is_a?(Integer) - assert_equal(value.to_s, cron.should(param), + assert_equal([value.to_s], cron.should(param), "Cron value was not set correctly") end when :invalid: @@ -355,38 +355,33 @@ class TestCron < Test::Unit::TestCase property.is = :absent } - # Make sure our minute default is 0, not * - val = if param == :minute - "*" # the "0" thing is disabled for now - else - "*" - end + val = [:absent] assert_equal(val, cron.value(param)) # Make sure we correctly get the "is" value if that's all there is cron.is = [param, "1"] - assert_equal("1", cron.value(param)) + assert_equal(%w{1}, cron.value(param)) # Make sure arrays work, too cron.is = [param, ["1"]] - assert_equal("1", cron.value(param)) + assert_equal(%w{1}, cron.value(param)) # Make sure values get comma-joined - cron.is = [param, ["2", "3"]] - assert_equal("2,3", cron.value(param)) + cron.is = [param, %w{2 3}] + assert_equal(%w{2 3}, cron.value(param)) # Make sure "should" values work, too cron[param] = "4" - assert_equal("4", cron.value(param)) + assert_equal(%w{4}, cron.value(param)) cron[param] = ["4"] - assert_equal("4", cron.value(param)) + assert_equal(%w{4}, cron.value(param)) cron[param] = ["4", "5"] - assert_equal("4,5", cron.value(param)) + assert_equal(%w{4 5}, cron.value(param)) cron.is = [param, :absent] - assert_equal("4,5", cron.value(param)) + assert_equal(%w{4 5}, cron.value(param)) end Puppet[:trace] = false @@ -400,36 +395,31 @@ class TestCron < Test::Unit::TestCase property.is = :absent } - assert(property, "Did not get command property") - assert_raise(Puppet::DevError) do - cron.value(:command) - end - param = :command # Make sure we correctly get the "is" value if that's all there is - cron.is = [param, "1"] - assert_equal("1", cron.value(param)) + cron.is = [param, "/bin/echo"] + assert_equal("/bin/echo", cron.value(param)) # Make sure arrays work, too - cron.is = [param, ["1"]] - assert_equal("1", cron.value(param)) + cron.is = [param, ["/bin/echo"]] + assert_equal("/bin/echo", cron.value(param)) # Make sure values are not comma-joined - cron.is = [param, ["2", "3"]] - assert_equal("2", cron.value(param)) + cron.is = [param, %w{/bin/echo /bin/test}] + assert_equal("/bin/echo", cron.value(param)) # Make sure "should" values work, too - cron[param] = "4" - assert_equal("4", cron.value(param)) + cron[param] = "/bin/echo" + assert_equal("/bin/echo", cron.value(param)) - cron[param] = ["4"] - assert_equal("4", cron.value(param)) + cron[param] = ["/bin/echo"] + assert_equal("/bin/echo", cron.value(param)) - cron[param] = ["4", "5"] - assert_equal("4", cron.value(param)) + cron[param] = %w{/bin/echo /bin/test} + assert_equal("/bin/echo", cron.value(param)) cron.is = [param, :absent] - assert_equal("4", cron.value(param)) + assert_equal("/bin/echo", cron.value(param)) end def test_multiple_users diff --git a/test/ral/types/exec.rb b/test/ral/types/exec.rb index 6dd126631..e36316031 100755 --- a/test/ral/types/exec.rb +++ b/test/ral/types/exec.rb @@ -536,7 +536,7 @@ class TestExec < Test::Unit::TestCase def test_missing_checks_cause_failures # Solaris's sh exits with 1 here instead of 127 return if Facter.value(:operatingsystem) == "Solaris" - exec = Puppet::Type.newexec( + exec = Puppet::Type.type(:exec).create( :command => "echo true", :path => ENV["PATH"], :onlyif => "/bin/nosuchthingexists" |