[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. puppet-0.24.5-rc3-1601-gf8c1b08

James Turnbull james at lovedthanlost.net
Fri Jan 15 09:06:51 UTC 2010


The following commit has been merged in the upstream branch:
commit b8470b8064503baea21d43d5c1dcf349bc4daf59
Author: Markus Roberts <Markus at reality.com>
Date:   Sat Oct 31 12:13:55 2009 -0700

    Fix #2757 & CSR 92 (symlinks in recursively managed dirs)
    
    The fundemental problem was that, despite what the comment said,
    the early bailout for file content management only applied to
    directories, not to links.  Making links bail out at as well fixed
    the problem for most users.
    
    However, it would still occur for users with mixed ruby version
    system since there were no to_/from_pson methods for file metadata.
    So the second (and far larger) part of this patch adds metadata
    pson support.
    
    The testing is unit level only, as there's no pratical way to do
    the cross-ruby-version acceptance testing and no benifit to doing
    "integration" testing short of that.
    
    Signed-off-by: Markus Roberts <Markus at reductivelabs.com>

diff --git a/lib/puppet/external/pson/common.rb b/lib/puppet/external/pson/common.rb
index 71b85ce..87bce98 100644
--- a/lib/puppet/external/pson/common.rb
+++ b/lib/puppet/external/pson/common.rb
@@ -48,7 +48,7 @@ module PSON
         case
         when c.empty?             then p
         when p.const_defined?(c)  then p.const_get(c)
-        else                      raise ArgumentError, "can't find const #{path}"
+        else                      raise ArgumentError, "can't find const for unregistered document type #{path}"
         end
       end
     end
diff --git a/lib/puppet/file_serving/base.rb b/lib/puppet/file_serving/base.rb
index c82bb19..02132e8 100644
--- a/lib/puppet/file_serving/base.rb
+++ b/lib/puppet/file_serving/base.rb
@@ -74,4 +74,19 @@ class Puppet::FileServing::Base
         end
         File.send(@stat_method, full_path())
     end
+
+    def to_pson_data_hash
+        {
+            # No 'document_type' since we don't send these bare
+            'data'       => {
+                'path'          => @path,
+                'relative_path' => @relative_path,
+                'links'         => @links
+                },
+            'metadata' => {
+                'api_version' => 1
+                }
+       }
+    end
+
 end
diff --git a/lib/puppet/file_serving/metadata.rb b/lib/puppet/file_serving/metadata.rb
index 335dad4..275a090 100644
--- a/lib/puppet/file_serving/metadata.rb
+++ b/lib/puppet/file_serving/metadata.rb
@@ -71,8 +71,47 @@ class Puppet::FileServing::Metadata < Puppet::FileServing::Base
         end
     end
 
-    def initialize(*args)
-        @checksum_type = "md5"
-        super
+    def initialize(path,data={})
+        @owner       = data.delete('owner')
+        @group       = data.delete('group')
+        @mode        = data.delete('mode')
+        if checksum = data.delete('checksum')
+            @checksum_type = checksum['type']
+            @checksum      = checksum['value']
+        end
+        @checksum_type ||= "md5"
+        @ftype       = data.delete('type')
+        @destination = data.delete('destination')
+        super(path,data)
+    end
+
+    PSON.register_document_type('FileMetadata',self)
+    def to_pson_data_hash
+        {
+            'document_type' => 'FileMetadata',
+            'data'       => super['data'].update({
+                'owner'        => owner,
+                'group'        => group,
+                'mode'         => mode,
+                'checksum'     => {
+                    'type'   => checksum_type,
+                    'value'  => checksum
+                },
+                'type'         => ftype,
+                'destination'  => destination,
+                }),
+            'metadata' => {
+                'api_version' => 1
+                }
+       }
+    end
+
+    def to_pson(*args)
+       to_pson_data_hash.to_pson(*args)
+    end
+
+    def self.from_pson(data)
+       new(data.delete('path'), data)
     end
+
 end
diff --git a/lib/puppet/type/file/content.rb b/lib/puppet/type/file/content.rb
index ff71a55..7f19083 100755
--- a/lib/puppet/type/file/content.rb
+++ b/lib/puppet/type/file/content.rb
@@ -114,14 +114,14 @@ module Puppet
 
         def retrieve
             return :absent unless stat = @resource.stat
-
+            ftype = stat.ftype
             # Don't even try to manage the content on directories or links
-            return nil if stat.ftype == "directory"
+            return nil if ["directory","link"].include? ftype
 
             begin
-                return "{#{checksum_type}}" + send(checksum_type.to_s + "_file", resource[:path]).to_s
+                "{#{checksum_type}}" + send(checksum_type.to_s + "_file", resource[:path]).to_s
             rescue => detail
-                raise Puppet::Error, "Could not read %s: %s" % [@resource.title, detail]
+                raise Puppet::Error, "Could not read #{ftype} #{@resource.title}: #{detail}"
             end
         end
 
diff --git a/spec/unit/file_serving/metadata.rb b/spec/unit/file_serving/metadata.rb
index de0c457..c27efd6 100755
--- a/spec/unit/file_serving/metadata.rb
+++ b/spec/unit/file_serving/metadata.rb
@@ -20,6 +20,84 @@ describe Puppet::FileServing::Metadata do
     it "should have a method that triggers attribute collection" do
         Puppet::FileServing::Metadata.new("/foo/bar").should respond_to(:collect)
     end
+
+    it "should support pson serialization" do
+        Puppet::FileServing::Metadata.new("/foo/bar").should respond_to(:to_pson) 
+    end
+
+    it "should support to_pson_data_hash" do
+        Puppet::FileServing::Metadata.new("/foo/bar").should respond_to(:to_pson_data_hash) 
+    end
+
+    it "should support pson deserialization" do
+        Puppet::FileServing::Metadata.should respond_to(:from_pson) 
+    end
+
+    describe "when serializing" do
+        before do
+            @metadata = Puppet::FileServing::Metadata.new("/foo/bar")
+        end
+        it "should perform pson serialization by calling to_pson on it's pson_data_hash" do
+            pdh = mock "data hash"
+            pdh_as_pson = mock "data as pson"
+            @metadata.expects(:to_pson_data_hash).returns pdh
+            pdh.expects(:to_pson).returns pdh_as_pson
+            @metadata.to_pson.should == pdh_as_pson 
+        end
+
+        it "should serialize as FileMetadata" do
+            @metadata.to_pson_data_hash['document_type'].should == "FileMetadata"
+        end
+
+        it "the data should include the path, relative_path, links, owner, group, mode, checksum, type, and destination" do
+            @metadata.to_pson_data_hash['data'].keys.sort.should == %w{ path relative_path links owner group mode checksum type destination }.sort
+        end
+
+        it "should pass the path in the hash verbatum" do
+            @metadata.to_pson_data_hash['data']['path'] == @metadata.path
+        end
+
+        it "should pass the relative_path in the hash verbatum" do
+            @metadata.to_pson_data_hash['data']['relative_path'] == @metadata.relative_path
+        end
+
+        it "should pass the links in the hash verbatum" do
+            @metadata.to_pson_data_hash['data']['links'] == @metadata.links
+        end
+
+        it "should pass the path owner in the hash verbatum" do
+            @metadata.to_pson_data_hash['data']['owner'] == @metadata.owner
+        end
+
+        it "should pass the group in the hash verbatum" do
+            @metadata.to_pson_data_hash['data']['group'] == @metadata.group
+        end
+
+        it "should pass the mode in the hash verbatum" do
+            @metadata.to_pson_data_hash['data']['mode'] == @metadata.mode
+        end
+
+        it "should pass the ftype in the hash verbatum as the 'type'" do
+            @metadata.to_pson_data_hash['data']['type'] == @metadata.ftype
+        end
+
+        it "should pass the destination verbatum" do
+            @metadata.to_pson_data_hash['data']['destination'] == @metadata.destination
+        end
+
+        it "should pass the checksum in the hash as a nested hash" do
+            @metadata.to_pson_data_hash['data']['checksum'].should be_is_a Hash
+        end
+
+        it "should pass the checksum_type in the hash verbatum as the checksum's type" do
+            @metadata.to_pson_data_hash['data']['checksum']['type'] == @metadata.checksum_type
+        end
+
+        it "should pass the checksum in the hash verbatum as the checksum's value" do
+            @metadata.to_pson_data_hash['data']['checksum']['value'] == @metadata.checksum
+        end
+
+    end
 end
 
 describe Puppet::FileServing::Metadata, " when finding the file to use for setting attributes" do
diff --git a/spec/unit/network/rights.rb b/spec/unit/network/rights.rb
index 244fa18..7f00891 100755
--- a/spec/unit/network/rights.rb
+++ b/spec/unit/network/rights.rb
@@ -391,7 +391,7 @@ describe Puppet::Network::Rights do
             end
 
             it "should match as a regex" do
-                @acl.match?("this shoud work.rb").should_not be_nil
+                @acl.match?("this should work.rb").should_not be_nil
             end
 
             it "should return nil if no match" do
diff --git a/spec/unit/type/file/content.rb b/spec/unit/type/file/content.rb
index 8bdb1f2..901d52d 100755
--- a/spec/unit/type/file/content.rb
+++ b/spec/unit/type/file/content.rb
@@ -119,6 +119,15 @@ describe content do
             @content.retrieve.should be_nil
         end
 
+        it "should not manage content on links" do
+            @content = content.new(:resource => @resource)
+
+            stat = mock 'stat', :ftype => "link"
+            @resource.expects(:stat).returns stat
+
+            @content.retrieve.should be_nil
+        end
+
         it "should always return the checksum as a string" do
             @content = content.new(:resource => @resource)
             @content.stubs(:checksum_type).returns "mtime"

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list