[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. 0.25.5-639-g8f94f35

Luke Kanies luke at puppetlabs.com
Wed Jul 14 10:32:23 UTC 2010


The following commit has been merged in the upstream branch:
commit effa7196781c2c233935206388c7e18d410e8e5f
Author: Luke Kanies <luke at puppetlabs.com>
Date:   Mon Apr 12 11:06:06 2010 -0700

    Cleaning up content/source code
    
    This is probably a slight refactor, but only because
    it fixed a bug (content not being copied over correctly
    from metadata), which required that slight refactor.
    
    Mostly this just makes the code a bit cleaner.
    
    Signed-off-by: Luke Kanies <luke at puppetlabs.com>

diff --git a/lib/puppet/type/file/content.rb b/lib/puppet/type/file/content.rb
index b6c671b..cc2494b 100755
--- a/lib/puppet/type/file/content.rb
+++ b/lib/puppet/type/file/content.rb
@@ -96,17 +96,9 @@ module Puppet
             end
 
             return true if ! @resource.replace?
+            return true unless self.should
 
-            if self.should
-                result = super
-            elsif source = resource.parameter(:source)
-                fail "Got a remote source with no checksum" unless source.checksum
-                result = (is == source.checksum)
-            else
-                # We've got no content specified, and no source from which to
-                # get content.
-                return true
-            end
+            result = super
 
             if ! result and Puppet[:show_diff]
                 string_file_diff(@resource[:path], actual_content)
diff --git a/lib/puppet/type/file/source.rb b/lib/puppet/type/file/source.rb
index 838dabb..7eb3d01 100755
--- a/lib/puppet/type/file/source.rb
+++ b/lib/puppet/type/file/source.rb
@@ -112,11 +112,15 @@ module Puppet
 
             # Take each of the stats and set them as states on the local file
             # if a value has not already been provided.
-            [:owner, :mode, :group, :checksum].each do |param|
-                next if param == :owner and Puppet::Util::SUIDManager.uid != 0
-                next if param == :checksum and metadata.ftype == "directory"
-                unless value = resource[param] and value != :absent
-                    resource[param] = metadata.send(param)
+            [:owner, :mode, :group, :checksum].each do |metadata_method|
+                param_name = (metadata_method == :checksum) ? :content : metadata_method
+                next if metadata_method == :owner and Puppet::Util::SUIDManager.uid != 0
+                next if metadata_method == :checksum and metadata.ftype == "directory"
+
+                if resource[param_name].nil? or resource[param_name] == :absent
+                    v = metadata.send(metadata_method)
+                    resource.info "Setting #{param_name} to #{v}"
+                    resource[param_name] = metadata.send(metadata_method)
                 end
             end
 
diff --git a/spec/unit/type/file/content.rb b/spec/unit/type/file/content.rb
index 1f21009..5a3a859 100755
--- a/spec/unit/type/file/content.rb
+++ b/spec/unit/type/file/content.rb
@@ -201,32 +201,6 @@ describe content do
                     @content.insync?("{md5}" + Digest::MD5.hexdigest("some content"))
                 end
             end
-
-            describe "and the content is specified via a remote source" do
-                before do
-                    @metadata = stub 'metadata'
-                    @source = stub 'source', :metadata => @metadata
-                    @resource.stubs(:parameter).with(:source).returns @source
-                end
-
-                it "should use checksums to compare remote content, rather than downloading the content" do
-                    @source.stubs(:checksum).returns "{md5}whatever"
-
-                    @content.insync?("{md5}eh")
-                end
-
-                it "should return false if the current content is different from the remote content" do
-                    @source.stubs(:checksum).returns "{md5}whatever"
-
-                    @content.should_not be_insync("some content")
-                end
-
-                it "should return true if the current content is the same as the remote content" do
-                    @source.stubs(:checksum).returns("{md5}something")
-
-                    @content.must be_insync("{md5}something")
-                end
-            end
         end
 
         describe "and :replace is false" do
diff --git a/spec/unit/type/file/source.rb b/spec/unit/type/file/source.rb
index 8dd2ff3..e4e9ad9 100755
--- a/spec/unit/type/file/source.rb
+++ b/spec/unit/type/file/source.rb
@@ -147,7 +147,7 @@ describe Puppet::Type.type(:file).attrclass(:source) do
                 @metadata.stubs(:ftype).returns "file"
             end
 
-            it "should copy the metadata's owner, group, and mode to the resource if they are not set on the resource" do
+            it "should copy the metadata's owner, group, checksum, and mode to the resource if they are not set on the resource" do
                 Puppet::Util::SUIDManager.expects(:uid).returns 0
 
                 @source.copy_source_values
@@ -155,28 +155,23 @@ describe Puppet::Type.type(:file).attrclass(:source) do
                 @resource[:owner].must == 100
                 @resource[:group].must == 200
                 @resource[:mode].must == 123
-            end
-
-            it "should copy the metadata's owner, group, and mode to the resource if they are set to :absent on the resource" do
-                Puppet::Util::SUIDManager.expects(:uid).returns 0
-
-                @source.copy_source_values
 
-                @resource[:owner].must == 100
-                @resource[:group].must == 200
-                @resource[:mode].must == 123
+                # Metadata calls it checksum, we call it content.
+                @resource[:content].must == @metadata.checksum
             end
 
             it "should not copy the metadata's owner to the resource if it is already set" do
                 @resource[:owner] = 1
                 @resource[:group] = 2
                 @resource[:mode] = 3
+                @resource[:content] = "foobar"
 
                 @source.copy_source_values
 
                 @resource[:owner].must == 1
                 @resource[:group].must == 2
                 @resource[:mode].must == 3
+                @resource[:content].should_not == @metadata.checksum
             end
 
             describe "and puppet is not running as root" do

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list