[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. 2.6.5rc1-120-g2247c80
Paul Berry
paul at puppetlabs.com
Mon Feb 7 06:40:03 UTC 2011
The following commit has been merged in the upstream branch:
commit a002231f45339da9b152162c2f48126d95e2e246
Author: Jesse Wolfe <jes5199 at gmail.com>
Date: Mon Jan 10 18:30:42 2011 -0800
(#5171) Made filebucket able to perform diffs
It is now possible to ask the filebucket to diff two files using a URL
of the form:
https://puppet/production/file_bucket_file/md5/{first file hash}?diff_with={second file hash}
The returned diff is a string, the output of the "diff" command.
Paired-with: Paul Berry <paul at puppetlabs.com>
diff --git a/lib/puppet/indirector/file_bucket_file/file.rb b/lib/puppet/indirector/file_bucket_file/file.rb
index 318858a..9d9cee7 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 309eed7..a010c4e 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 61ae2d2..f22498b 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 aa3ade6..7bf02b5 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 76a9c55..cdbce41 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)
--
Puppet packaging for Debian
More information about the Pkg-puppet-devel
mailing list