summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Robinson <matt@puppetlabs.com>2011-03-02 10:45:53 -0800
committerMatt Robinson <matt@puppetlabs.com>2011-03-02 10:45:53 -0800
commit9571c99b6c8a1244e0cdda416a2e9ca0c52b25cb (patch)
treeeb7827afd6554cd276b2f6f0cbf79b4947f42570
parente5cfac3cb90cbea688afdef4943d4f9dd49d8058 (diff)
parent4e29f439189e0a40364724f50971c83652463085 (diff)
downloadpuppet-9571c99b6c8a1244e0cdda416a2e9ca0c52b25cb.tar.gz
puppet-9571c99b6c8a1244e0cdda416a2e9ca0c52b25cb.tar.xz
puppet-9571c99b6c8a1244e0cdda416a2e9ca0c52b25cb.zip
Merge branch 'ticket/2.6.next/6541-md5_in_content_truncates' into 2.6.next
* ticket/2.6.next/6541-md5_in_content_truncates: (#6541) maint: whitespace cleanup on the file integration spec (#6541) Fix content with checksum truncation bug
-rwxr-xr-xlib/puppet/type/file/content.rb12
-rwxr-xr-xspec/integration/type/file_spec.rb61
-rwxr-xr-xspec/unit/type/file/content_spec.rb23
3 files changed, 63 insertions, 33 deletions
diff --git a/lib/puppet/type/file/content.rb b/lib/puppet/type/file/content.rb
index 5223ee333..827183213 100755
--- a/lib/puppet/type/file/content.rb
+++ b/lib/puppet/type/file/content.rb
@@ -163,13 +163,15 @@ module Puppet
Puppet.settings[:name] == "apply"
end
+ # the content is munged so if it's a checksum source_or_content is nil
+ # unless the checksum indirectly comes from source
def each_chunk_from(source_or_content)
if source_or_content.is_a?(String)
yield source_or_content
- elsif source_or_content.nil? && resource.parameter(:ensure) && [:present, :file].include?(resource.parameter(:ensure).value)
- yield ''
- elsif source_or_content.nil?
+ elsif content_is_really_a_checksum? && source_or_content.nil?
yield read_file_from_filebucket
+ elsif source_or_content.nil?
+ yield ''
elsif self.class.standalone?
yield source_or_content.content
elsif source_or_content.local?
@@ -181,6 +183,10 @@ module Puppet
private
+ def content_is_really_a_checksum?
+ checksum?(should)
+ end
+
def chunk_file_from_disk(source_or_content)
File.open(source_or_content.full_path, "r") do |src|
while chunk = src.read(8192)
diff --git a/spec/integration/type/file_spec.rb b/spec/integration/type/file_spec.rb
index 4b91e5ef9..31f4adee6 100755
--- a/spec/integration/type/file_spec.rb
+++ b/spec/integration/type/file_spec.rb
@@ -173,7 +173,12 @@ describe Puppet::Type.type(:file) do
it "should be able to recurse over a nonexistent file" do
@path = tmpfile("file_integration_tests")
- @file = Puppet::Type::File.new(:name => @path, :mode => 0644, :recurse => true, :backup => false)
+ @file = Puppet::Type::File.new(
+ :name => @path,
+ :mode => 0644,
+ :recurse => true,
+ :backup => false
+ )
@catalog = Puppet::Resource::Catalog.new
@catalog.add_resource @file
@@ -186,7 +191,12 @@ describe Puppet::Type.type(:file) do
build_path(@path)
- @file = Puppet::Type::File.new(:name => @path, :mode => 0644, :recurse => true, :backup => false)
+ @file = Puppet::Type::File.new(
+ :name => @path,
+ :mode => 0644,
+ :recurse => true,
+ :backup => false
+ )
@catalog = Puppet::Resource::Catalog.new
@catalog.add_resource @file
@@ -393,10 +403,8 @@ describe Puppet::Type.type(:file) do
dest = tmpfile("files_with_content")
- file = Puppet::Type.type(:file).new(
-
- :name => dest,
-
+ file = Puppet::Type.type(:file).new(
+ :name => dest,
:content => "this is some content, yo"
)
@@ -411,11 +419,9 @@ describe Puppet::Type.type(:file) do
dest = tmpfile("files_with_content")
- file = Puppet::Type.type(:file).new(
-
- :name => dest,
- :ensure => "file",
-
+ file = Puppet::Type.type(:file).new(
+ :name => dest,
+ :ensure => "file",
:content => "this is some content, yo"
)
@@ -433,12 +439,10 @@ describe Puppet::Type.type(:file) do
File.open(dest, "w") { |f| f.puts "boo" }
- file = Puppet::Type.type(:file).new(
-
- :name => dest,
+ file = Puppet::Type.type(:file).new(
+ :name => dest,
:ensure => :absent,
:source => source,
-
:backup => false
)
@@ -465,24 +469,23 @@ describe Puppet::Type.type(:file) do
File.open(@purgee, "w") { |f| f.puts "footest" }
- @lfobj = Puppet::Type.newfile(
-
- :title => "localfile",
- :path => @localfile,
+ @lfobj = Puppet::Type.newfile(
+ :title => "localfile",
+ :path => @localfile,
:content => "rahtest\n",
- :ensure => :file,
-
- :backup => false
+ :ensure => :file,
+ :backup => false
)
- @destobj = Puppet::Type.newfile(
- :title => "destdir", :path => @destdir,
- :source => @sourcedir,
- :backup => false,
- :purge => true,
-
- :recurse => true)
+ @destobj = Puppet::Type.newfile(
+ :title => "destdir",
+ :path => @destdir,
+ :source => @sourcedir,
+ :backup => false,
+ :purge => true,
+ :recurse => true
+ )
@catalog = Puppet::Resource::Catalog.new
@catalog.add_resource @lfobj, @destobj
diff --git a/spec/unit/type/file/content_spec.rb b/spec/unit/type/file/content_spec.rb
index 7d23399cf..bd2b2adaf 100755
--- a/spec/unit/type/file/content_spec.rb
+++ b/spec/unit/type/file/content_spec.rb
@@ -375,17 +375,38 @@ describe content do
@content.each_chunk_from('i_am_a_string') { |chunk| chunk.should == 'i_am_a_string' }
end
+ # The following manifest is a case where source and content.should are both set
+ # file { "/tmp/mydir" :
+ # source => '/tmp/sourcedir',
+ # recurse => true,
+ # }
+ it "when content checksum comes from source" do
+ source_param = Puppet::Type.type(:file).attrclass(:source)
+ source = source_param.new(:resource => @resource)
+ @content.should = "{md5}123abcd"
+
+ @content.expects(:chunk_file_from_source).returns('from_source')
+ @content.each_chunk_from(source) { |chunk| chunk.should == 'from_source' }
+ end
+
it "when no content, source, but ensure present" do
@resource[:ensure] = :present
@content.each_chunk_from(nil) { |chunk| chunk.should == '' }
end
+ # you might do this if you were just auditing
it "when no content, source, but ensure file" do
@resource[:ensure] = :file
@content.each_chunk_from(nil) { |chunk| chunk.should == '' }
end
- it "when no content or source" do
+ it "when source_or_content is nil and content not a checksum" do
+ @content.each_chunk_from(nil) { |chunk| chunk.should == '' }
+ end
+
+ # the content is munged so that if it's a checksum nil gets passed in
+ it "when content is a checksum it should try to read from filebucket" do
+ @content.should = "{md5}123abcd"
@content.expects(:read_file_from_filebucket).once.returns('im_a_filebucket')
@content.each_chunk_from(nil) { |chunk| chunk.should == 'im_a_filebucket' }
end