summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Berry <paul@puppetlabs.com>2011-01-11 11:45:58 -0800
committerPaul Berry <paul@puppetlabs.com>2011-01-11 11:45:58 -0800
commitbf2b07158f5e4e16e7a1a52e84257ae5d84d9e1c (patch)
treecf51e75f954847fda264b561a7a3acdfa5869dda
parente6e88e7df7fa1cbec1400d73cb7ba9428c420be0 (diff)
parenta002231f45339da9b152162c2f48126d95e2e246 (diff)
downloadpuppet-bf2b07158f5e4e16e7a1a52e84257ae5d84d9e1c.tar.gz
puppet-bf2b07158f5e4e16e7a1a52e84257ae5d84d9e1c.tar.xz
puppet-bf2b07158f5e4e16e7a1a52e84257ae5d84d9e1c.zip
Merge branch 'ticket/2.6.next/5171-filebucket-diff' into 2.6.next
* ticket/2.6.next/5171-filebucket-diff: (#5171) Made filebucket able to perform diffs
-rw-r--r--lib/puppet/indirector/file_bucket_file/file.rb11
-rw-r--r--lib/puppet/indirector/indirection.rb2
-rw-r--r--lib/puppet/network/http/handler.rb6
-rwxr-xr-xspec/unit/indirector/file_bucket_file/file_spec.rb45
-rwxr-xr-xspec/unit/network/http/handler_spec.rb6
5 files changed, 67 insertions, 3 deletions
diff --git a/lib/puppet/indirector/file_bucket_file/file.rb b/lib/puppet/indirector/file_bucket_file/file.rb
index 318858aaf..9d9cee793 100644
--- a/lib/puppet/indirector/file_bucket_file/file.rb
+++ b/lib/puppet/indirector/file_bucket_file/file.rb
@@ -15,7 +15,16 @@ module Puppet::FileBucketFile
def find( request )
checksum, path = request_to_checksum_and_path( request )
- find_by_checksum( checksum, request.options )
+ file = find_by_checksum( checksum, request.options )
+
+ if file && request.options[:diff_with]
+ hash_protocol = sumtype(checksum)
+ file2 = find_by_checksum( "{#{hash_protocol}}#{request.options[:diff_with]}", request.options )
+ raise "could not find diff_with #{request.options[:diff_with]}" unless file2
+ return `diff #{path_for(file).inspect}/contents #{path_for(file2).inspect}/contents`
+ end
+
+ file
end
def save( request )
diff --git a/lib/puppet/indirector/indirection.rb b/lib/puppet/indirector/indirection.rb
index 309eed7b6..a010c4e40 100644
--- a/lib/puppet/indirector/indirection.rb
+++ b/lib/puppet/indirector/indirection.rb
@@ -191,7 +191,7 @@ class Puppet::Indirector::Indirection
# Otherwise, return the result from the terminus, caching if appropriate.
if ! request.ignore_terminus? and result = terminus.find(request)
- result.expiration ||= self.expiration
+ result.expiration ||= self.expiration if result.respond_to?(:expiration)
if cache? and request.use_cache?
Puppet.info "Caching #{self.name} for #{request.key}"
cache.save request(:save, result, *args)
diff --git a/lib/puppet/network/http/handler.rb b/lib/puppet/network/http/handler.rb
index 61ae2d2fc..f22498b70 100644
--- a/lib/puppet/network/http/handler.rb
+++ b/lib/puppet/network/http/handler.rb
@@ -109,7 +109,11 @@ module Puppet::Network::HTTP::Handler
format = format_to_use(request)
set_content_type(response, format)
- set_response(response, result.render(format))
+ if result.respond_to?(:render)
+ set_response(response, result.render(format))
+ else
+ set_response(response, result)
+ end
end
# Execute our search.
diff --git a/spec/unit/indirector/file_bucket_file/file_spec.rb b/spec/unit/indirector/file_bucket_file/file_spec.rb
index aa3ade6b6..7bf02b5b3 100755
--- a/spec/unit/indirector/file_bucket_file/file_spec.rb
+++ b/spec/unit/indirector/file_bucket_file/file_spec.rb
@@ -13,6 +13,51 @@ describe Puppet::FileBucketFile::File do
Puppet::FileBucketFile::File.doc.should be_instance_of(String)
end
+ describe "non-stubbing tests" do
+ include PuppetSpec::Files
+
+ before do
+ Puppet[:bucketdir] = tmpdir('bucketdir')
+ end
+
+ describe "when diffing files" do
+ def save_bucket_file(contents)
+ bucket_file = Puppet::FileBucket::File.new(contents)
+ bucket_file.save
+ bucket_file.checksum_data
+ end
+
+ it "should generate an empty string if there is no diff" do
+ checksum = save_bucket_file("I'm the contents of a file")
+ Puppet::FileBucket::File.find("md5/#{checksum}", :diff_with => checksum).should == ''
+ end
+
+ it "should generate a proper diff if there is a diff" do
+ checksum1 = save_bucket_file("foo\nbar\nbaz")
+ checksum2 = save_bucket_file("foo\nbiz\nbaz")
+ diff = Puppet::FileBucket::File.find("md5/#{checksum1}", :diff_with => checksum2)
+ diff.should == <<HERE
+2c2
+< bar
+---
+> biz
+HERE
+ end
+
+ it "should raise an exception if the hash to diff against isn't found" do
+ checksum = save_bucket_file("whatever")
+ bogus_checksum = "d1bf072d0e2c6e20e3fbd23f022089a1"
+ lambda { Puppet::FileBucket::File.find("md5/#{checksum}", :diff_with => bogus_checksum) }.should raise_error "could not find diff_with #{bogus_checksum}"
+ end
+
+ it "should return nil if the hash to diff from isn't found" do
+ checksum = save_bucket_file("whatever")
+ bogus_checksum = "d1bf072d0e2c6e20e3fbd23f022089a1"
+ Puppet::FileBucket::File.find("md5/#{bogus_checksum}", :diff_with => checksum).should == nil
+ end
+ end
+ end
+
describe "when initializing" do
it "should use the filebucket settings section" do
Puppet.settings.expects(:use).with(:filebucket)
diff --git a/spec/unit/network/http/handler_spec.rb b/spec/unit/network/http/handler_spec.rb
index 76a9c5530..cdbce41f7 100755
--- a/spec/unit/network/http/handler_spec.rb
+++ b/spec/unit/network/http/handler_spec.rb
@@ -209,6 +209,12 @@ describe Puppet::Network::HTTP::Handler do
@handler.do_find(@irequest, @request, @response)
end
+ it "should pass the result through without rendering it if the result is a string" do
+ @model_class.stubs(:find).returns "foo"
+ @handler.expects(:set_response).with(@response, "foo")
+ @handler.do_find(@irequest, @request, @response)
+ end
+
it "should use the default status when a model find call succeeds" do
@handler.expects(:set_response).with { |response, body, status| status.nil? }
@handler.do_find(@irequest, @request, @response)