diff options
-rw-r--r-- | lib/puppet/client.rb | 8 | ||||
-rw-r--r-- | lib/puppet/storage.rb | 1 | ||||
-rw-r--r-- | lib/puppet/type.rb | 6 | ||||
-rw-r--r-- | lib/puppet/type/pfile.rb | 19 | ||||
-rw-r--r-- | test/types/tc_file.rb | 32 |
5 files changed, 44 insertions, 22 deletions
diff --git a/lib/puppet/client.rb b/lib/puppet/client.rb index 1768ca466..3689b2033 100644 --- a/lib/puppet/client.rb +++ b/lib/puppet/client.rb @@ -69,11 +69,18 @@ module Puppet # manipulations def config(tree) Puppet.debug("Calling config") + + # XXX this is kind of a problem; if the user changes the state file + # after this, then we have to reload the file and everything... + Puppet::Storage.init + Puppet::Storage.load + container = Marshal::load(tree).to_type # this is a gross hack... but i don't see a good way around it # set all of the variables to empty Puppet::Transaction.init + # for now we just evaluate the top-level container, but eventually # there will be schedules and such associated with each object, # and probably with the container itself @@ -87,6 +94,7 @@ module Puppet Metric.store Metric.graph end + Puppet::Storage.store self.shutdown end diff --git a/lib/puppet/storage.rb b/lib/puppet/storage.rb index 5dac7dc35..67969c76f 100644 --- a/lib/puppet/storage.rb +++ b/lib/puppet/storage.rb @@ -15,6 +15,7 @@ module Puppet end def Storage.init + Puppet.debug "Initializing Storage" @@state = Hash.new { |hash,key| hash[key] = Hash.new(nil) } diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index 652366dcb..bc54b31cd 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -398,6 +398,8 @@ class Type < Puppet::Element #--------------------------------------------------------------- # this abstracts accessing parameters and states, and normalizes # access to always be symbols, not strings + # XXX this returns a _value_, not an object + # if you want a state object, use <type>.state(<state>) def [](name) if name.is_a?(String) name = name.intern @@ -545,8 +547,6 @@ class Type < Puppet::Element hash.delete(namevar) # else something's screwy else - p hash - p namevar raise TypeError.new("A name must be provided to %s at initialization time" % self.class) end @@ -733,7 +733,7 @@ class Type < Puppet::Element # now record how many changes we've resulted in Puppet::Metric.add(self.class,self,:changes,changes.length) - return changes + return changes.flatten end #--------------------------------------------------------------- diff --git a/lib/puppet/type/pfile.rb b/lib/puppet/type/pfile.rb index dbd54404b..6b4ecbc5d 100644 --- a/lib/puppet/type/pfile.rb +++ b/lib/puppet/type/pfile.rb @@ -55,13 +55,15 @@ module Puppet if hash = state[self.parent[:path]] if hash.include?(@checktype) @should = hash[@checktype] + Puppet.warning "Found checksum %s for %s" % + [@should,self.parent[:path]] else - Puppet.debug "Found checksum for %s but not of type %s" % + Puppet.warning "Found checksum for %s but not of type %s" % [self.parent[:path],@checktype] @should = nil end else - Puppet.debug "No checksum for %s" % self.parent[:path] + Puppet.warning "No checksum for %s" % self.parent[:path] end end @@ -101,9 +103,9 @@ module Puppet } end when "timestamp","mtime": - sum = File.stat(self.parent[:path]).mtime + sum = File.stat(self.parent[:path]).mtime.to_s when "time": - sum = File.stat(self.parent[:path]).ctime + sum = File.stat(self.parent[:path]).ctime.to_s end self.is = sum @@ -115,6 +117,9 @@ module Puppet # at this point, we don't actually modify the system, we just kick # off an event if we detect a change def sync + if @is.nil? + Puppet.err "@is is nil" + end if self.updatesum return :file_modified else @@ -125,16 +130,20 @@ module Puppet def updatesum state = Puppet::Storage.state(self) unless state.include?(self.parent[:path]) + Puppet.debug "Initializing state hash for %s" % + self.parent[:path] + state[self.parent[:path]] = Hash.new end # if we're replacing, vs. updating if state[self.parent[:path]].include?(@checktype) Puppet.debug "Replacing checksum %s with %s" % [state[self.parent[:path]][@checktype],@is] + Puppet.debug "@is: %s; @should: %s" % [@is,@should] result = true else Puppet.debug "Creating checksum %s for %s of type %s" % - [@is,self.parent[:path],@checktype] + [self.is,self.parent[:path],@checktype] result = false end state[self.parent[:path]][@checktype] = @is diff --git a/test/types/tc_file.rb b/test/types/tc_file.rb index 05d49b367..0b50d94f2 100644 --- a/test/types/tc_file.rb +++ b/test/types/tc_file.rb @@ -36,13 +36,13 @@ class TestFile < Test::Unit::TestCase @file[:owner] = user } assert_nothing_raised() { - @file.retrieve + @file.evaluate } assert_nothing_raised() { @file.sync } assert_nothing_raised() { - @file.retrieve + @file.evaluate } assert(@file.insync?()) } @@ -50,7 +50,7 @@ class TestFile < Test::Unit::TestCase @file[:owner] = "root" } assert_nothing_raised() { - @file.retrieve + @file.evaluate } # we might already be in sync assert(!@file.insync?()) @@ -65,13 +65,13 @@ class TestFile < Test::Unit::TestCase @file[:group] = group } assert_nothing_raised() { - @file.retrieve + @file.evaluate } assert_nothing_raised() { @file.sync } assert_nothing_raised() { - @file.retrieve + @file.evaluate } assert(@file.insync?()) assert_nothing_raised() { @@ -90,13 +90,13 @@ class TestFile < Test::Unit::TestCase ) } assert_nothing_raised() { - file.retrieve + file.evaluate } assert_nothing_raised() { file.sync } assert_nothing_raised() { - file.retrieve + file.evaluate } assert(file.insync?()) assert_nothing_raised() { @@ -111,13 +111,13 @@ class TestFile < Test::Unit::TestCase @file[:mode] = mode } assert_nothing_raised() { - @file.retrieve + @file.evaluate } assert_nothing_raised() { @file.sync } assert_nothing_raised() { - @file.retrieve + @file.evaluate } assert(@file.insync?()) assert_nothing_raised() { @@ -148,7 +148,7 @@ class TestFile < Test::Unit::TestCase ) } assert_nothing_raised() { - file.retrieve + file.evaluate } assert_nothing_raised() { events = file.sync @@ -167,7 +167,7 @@ class TestFile < Test::Unit::TestCase #system("cat %s" % path) } assert_nothing_raised() { - file.retrieve + file.evaluate } assert_nothing_raised() { events = file.sync @@ -188,6 +188,7 @@ class TestFile < Test::Unit::TestCase def cyclefile(path) file = nil + changes = nil assert_nothing_raised { file = Puppet::Type::PFile.new( :path => path, @@ -196,11 +197,14 @@ class TestFile < Test::Unit::TestCase ) } assert_nothing_raised { - file.retrieve + changes = file.evaluate } - assert_nothing_raised { - file.sync + changes.each { |change| + change.go } + #assert_nothing_raised { + # file.sync + #} end def test_recursion |