summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/external/pson/common.rb2
-rw-r--r--lib/puppet/file_serving/base.rb15
-rw-r--r--lib/puppet/file_serving/metadata.rb45
-rwxr-xr-xlib/puppet/type/file/content.rb8
-rwxr-xr-xspec/unit/file_serving/metadata.rb78
-rwxr-xr-xspec/unit/network/rights.rb2
-rwxr-xr-xspec/unit/type/file/content.rb9
7 files changed, 150 insertions, 9 deletions
diff --git a/lib/puppet/external/pson/common.rb b/lib/puppet/external/pson/common.rb
index 71b85ce54..87bce988b 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 c82bb1992..02132e885 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 335dad497..275a090eb 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 ff71a55ce..7f1908394 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 de0c4570c..c27efd6bb 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 244fa18c8..7f00891ac 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 8bdb1f226..901d52d74 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"