diff options
| author | Luke Kanies <luke@madstop.com> | 2007-09-23 14:26:56 -0500 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2007-09-23 14:26:56 -0500 |
| commit | 048464f2563d3ccf781c16b873be6b74441f1f85 (patch) | |
| tree | 939a649265fbd20356205d12111f7f859f280d27 /lib | |
| parent | 84146d00eed4765e6dbe05dd8de9f4c3625463b7 (diff) | |
Adding my first integration test, verifying that
checksum interaction behaves as I expect when
interacting with the file terminus.
I've also changed how files and checksums behave a bit.
Files now create model instances with the content as
the only argument during initialization, and checksums
now calculate their checksums rather than having them passed
in.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/puppet/checksum.rb | 51 | ||||
| -rw-r--r-- | lib/puppet/defaults.rb | 4 | ||||
| -rw-r--r-- | lib/puppet/indirector/file.rb | 4 |
3 files changed, 43 insertions, 16 deletions
diff --git a/lib/puppet/checksum.rb b/lib/puppet/checksum.rb index 65fb7ef76..c607953c1 100644 --- a/lib/puppet/checksum.rb +++ b/lib/puppet/checksum.rb @@ -12,26 +12,53 @@ class Puppet::Checksum indirects :checksum - attr_accessor :name, :content - attr_reader :algorithm + attr_reader :algorithm, :content def algorithm=(value) - value = value.intern if value.respond_to?(:intern) + unless respond_to?(value) + raise ArgumentError, "Checksum algorithm %s is not supported" % value + end + value = value.intern if value.is_a?(String) @algorithm = value + # Reset the checksum so it's forced to be recalculated. + @checksum = nil end - def initialize(name) - raise ArgumentError.new("You must specify the checksum") unless name - - if name =~ /^\{(\w+)\}(.+$)$/ - @algorithm, @name = $1.intern, $2 - else - @name = name - @algorithm = :md5 + # Calculate (if necessary) and return the checksum + def checksum + unless @checksum + @checksum = send(algorithm) end + @checksum + end + + def initialize(content, algorithm = nil) + raise ArgumentError.new("You must specify the content") unless content + + @content = content + self.algorithm = algorithm || "md5" + + # Init to avoid warnings. + @checksum = nil + end + + # This can't be private, else respond_to? returns false. + def md5 + require 'digest/md5' + Digest::MD5.hexdigest(content) + end + + # This is here so the Indirector::File terminus works correctly. + def name + checksum + end + + def sha1 + require 'digest/sha1' + Digest::SHA1.hexdigest(content) end def to_s - "Checksum<{%s}%s>" % [algorithm, name] + "Checksum<{%s}%s>" % [algorithm, checksum] end end diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb index dbbe5e29d..f76ae9b84 100644 --- a/lib/puppet/defaults.rb +++ b/lib/puppet/defaults.rb @@ -498,7 +498,9 @@ module Puppet # we get an infinite loop otherwise. self.setdefaults(:main, :facts_terminus => ["yaml", - "The backend store to use for client facts."] + "The backend store to use for client facts."], + :checksum_terminus => ["file", + "The backend store to use for storing files by checksum (i.e., filebuckets)."] ) self.setdefaults(:yaml, diff --git a/lib/puppet/indirector/file.rb b/lib/puppet/indirector/file.rb index 4f231e9ec..c2d36c46b 100644 --- a/lib/puppet/indirector/file.rb +++ b/lib/puppet/indirector/file.rb @@ -32,9 +32,7 @@ class Puppet::Indirector::File < Puppet::Indirector::Terminus raise Puppet::Error, "Could not retrieve path %s: %s" % [path, detail] end - file = model.new(name) - file.content = content - return file + return model.new(content) end def save(file) |
