The patches are from 2.6.7rc1. (#4922) Don't truncate remotely-sourced files on 404 (#5073) Download plugins even if you're filtering on tags (#5428) More fully "stub" Puppet::Resource::Reference for use with storedconfigsepel9
parent
9bfa9137f0
commit
97a1f9e0c1
@ -0,0 +1,273 @@
|
||||
From 743e03930758d17ed35fc6b73f7c2c68d8212137 Mon Sep 17 00:00:00 2001
|
||||
From: Nick Lewis <nick@puppetlabs.com>
|
||||
Date: Mon, 28 Feb 2011 13:40:18 -0800
|
||||
Subject: [PATCH/puppet] (#4922) Don't truncate remotely-sourced files on 404
|
||||
|
||||
We were 'handling' 404's on remote file content retrieval by returning nil
|
||||
rather than raising an exception. This caused no content to be written to the
|
||||
temporary file, but still appeared successful, so the destination file was
|
||||
overwritten, instead of preserved. Now we just handle 404 like any other
|
||||
error.
|
||||
|
||||
Note that the root cause of these 404s seems to have been #4319, which has been
|
||||
fixed. However, in the event we do happen to get a 404 here, it's better not to
|
||||
have code to specifically handle it incorrectly.
|
||||
|
||||
Paired-With: Max Martin
|
||||
Reviewed-By: Matt Robinson
|
||||
---
|
||||
lib/puppet/type/file/content.rb | 1 -
|
||||
spec/unit/type/file/content_spec.rb | 175 ++++++++---------------------------
|
||||
2 files changed, 38 insertions(+), 138 deletions(-)
|
||||
|
||||
diff --git a/lib/puppet/type/file/content.rb b/lib/puppet/type/file/content.rb
|
||||
index 63c0aaf..1b36acb 100755
|
||||
--- a/lib/puppet/type/file/content.rb
|
||||
+++ b/lib/puppet/type/file/content.rb
|
||||
@@ -194,7 +194,6 @@ module Puppet
|
||||
connection = Puppet::Network::HttpPool.http_instance(source_or_content.server, source_or_content.port)
|
||||
connection.request_get(indirection2uri(request), add_accept_encoding({"Accept" => "raw"})) do |response|
|
||||
case response.code
|
||||
- when "404"; nil
|
||||
when /^2/; uncompress(response) { |uncompressor| response.read_body { |chunk| yield uncompressor.uncompress(chunk) } }
|
||||
else
|
||||
# Raise the http error if we didn't get a 'success' of some kind.
|
||||
diff --git a/spec/unit/type/file/content_spec.rb b/spec/unit/type/file/content_spec.rb
|
||||
index 9178c94..7d23399 100755
|
||||
--- a/spec/unit/type/file/content_spec.rb
|
||||
+++ b/spec/unit/type/file/content_spec.rb
|
||||
@@ -4,15 +4,14 @@ Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f
|
||||
|
||||
content = Puppet::Type.type(:file).attrclass(:content)
|
||||
describe content do
|
||||
+ include PuppetSpec::Files
|
||||
before do
|
||||
- @resource = Puppet::Type.type(:file).new :path => "/foo/bar"
|
||||
+ @filename = tmpfile('testfile')
|
||||
+ @resource = Puppet::Type.type(:file).new :path => @filename
|
||||
+ File.open(@filename, 'w') {|f| f.write "initial file content"}
|
||||
content.stubs(:standalone?).returns(false)
|
||||
end
|
||||
|
||||
- it "should be a subclass of Property" do
|
||||
- content.superclass.must == Puppet::Property
|
||||
- end
|
||||
-
|
||||
describe "when determining the checksum type" do
|
||||
it "should use the type specified in the source checksum if a source is set" do
|
||||
@resource[:source] = "/foo"
|
||||
@@ -249,10 +248,10 @@ describe content do
|
||||
describe "when writing" do
|
||||
before do
|
||||
@content = content.new(:resource => @resource)
|
||||
- @fh = stub_everything
|
||||
end
|
||||
|
||||
it "should attempt to read from the filebucket if no actual content nor source exists" do
|
||||
+ @fh = File.open(@filename, 'w')
|
||||
@content.should = "{md5}foo"
|
||||
@content.resource.bucket.class.any_instance.stubs(:getfile).returns "foo"
|
||||
@content.write(@fh)
|
||||
@@ -302,166 +301,68 @@ describe content do
|
||||
|
||||
describe "from local source" do
|
||||
before(:each) do
|
||||
- @content.stubs(:actual_content).returns(nil)
|
||||
- @source = stub_everything 'source', :local? => true, :full_path => "/path/to/source"
|
||||
- @resource.stubs(:parameter).with(:source).returns @source
|
||||
-
|
||||
- @sum = stub_everything 'sum'
|
||||
- @resource.stubs(:parameter).with(:checksum).returns(@sum)
|
||||
-
|
||||
- @digest = stub_everything 'digest'
|
||||
- @sum.stubs(:sum_stream).yields(@digest)
|
||||
-
|
||||
- @file = stub_everything 'file'
|
||||
- File.stubs(:open).yields(@file)
|
||||
- @file.stubs(:read).with(8192).returns("chunk1").then.returns("chunk2").then.returns(nil)
|
||||
- end
|
||||
-
|
||||
- it "should open the local file" do
|
||||
- File.expects(:open).with("/path/to/source", "r")
|
||||
- @content.write(@fh)
|
||||
- end
|
||||
+ @resource = Puppet::Type.type(:file).new :path => @filename, :backup => false
|
||||
+ @sourcename = tmpfile('source')
|
||||
+ @source_content = "source file content"*10000
|
||||
+ @sourcefile = File.open(@sourcename, 'w') {|f| f.write @source_content}
|
||||
|
||||
- it "should read the local file by chunks" do
|
||||
- @file.expects(:read).with(8192).returns("chunk1").then.returns(nil)
|
||||
- @content.write(@fh)
|
||||
+ @content = @resource.newattr(:content)
|
||||
+ @source = @resource.newattr(:source)
|
||||
+ @source.stubs(:metadata).returns stub_everything('metadata', :source => @sourcename, :ftype => 'file')
|
||||
end
|
||||
|
||||
- it "should write each chunk to the file" do
|
||||
- @fh.expects(:print).with("chunk1").then.with("chunk2")
|
||||
- @content.write(@fh)
|
||||
- end
|
||||
-
|
||||
- it "should pass each chunk to the current sum stream" do
|
||||
- @digest.expects(:<<).with("chunk1").then.with("chunk2")
|
||||
- @content.write(@fh)
|
||||
+ it "should copy content from the source to the file" do
|
||||
+ @resource.write(@source)
|
||||
+ File.read(@filename).should == @source_content
|
||||
end
|
||||
|
||||
it "should return the checksum computed" do
|
||||
- @sum.stubs(:sum_stream).yields(@digest).returns("checksum")
|
||||
- @content.write(@fh).should == "checksum"
|
||||
+ File.open(@filename, 'w') do |file|
|
||||
+ @content.write(file).should == "{md5}#{Digest::MD5.hexdigest(@source_content)}"
|
||||
+ end
|
||||
end
|
||||
end
|
||||
|
||||
describe "from remote source" do
|
||||
before(:each) do
|
||||
- @response = stub_everything 'mock response', :code => "404"
|
||||
+ @resource = Puppet::Type.type(:file).new :path => @filename, :backup => false
|
||||
+ @response = stub_everything 'response', :code => "200"
|
||||
+ @source_content = "source file content"*10000
|
||||
+ @response.stubs(:read_body).multiple_yields(*(["source file content"]*10000))
|
||||
+
|
||||
@conn = stub_everything 'connection'
|
||||
@conn.stubs(:request_get).yields(@response)
|
||||
Puppet::Network::HttpPool.stubs(:http_instance).returns @conn
|
||||
|
||||
- @content.stubs(:actual_content).returns(nil)
|
||||
- @source = stub_everything 'source', :local? => false, :full_path => "/path/to/source", :server => "server", :port => 1234
|
||||
- @resource.stubs(:parameter).with(:source).returns @source
|
||||
-
|
||||
- @sum = stub_everything 'sum'
|
||||
- @resource.stubs(:parameter).with(:checksum).returns(@sum)
|
||||
-
|
||||
- @digest = stub_everything 'digest'
|
||||
- @sum.stubs(:sum_stream).yields(@digest)
|
||||
- end
|
||||
-
|
||||
- it "should open a network connection to source server and port" do
|
||||
- Puppet::Network::HttpPool.expects(:http_instance).with("server", 1234).returns @conn
|
||||
- @content.write(@fh)
|
||||
- end
|
||||
-
|
||||
- it "should send the correct indirection uri" do
|
||||
- @conn.expects(:request_get).with { |uri,headers| uri == "/production/file_content/path/to/source" }.yields(@response)
|
||||
- @content.write(@fh)
|
||||
+ @content = @resource.newattr(:content)
|
||||
+ @sourcename = "puppet:///test/foo"
|
||||
+ @source = @resource.newattr(:source)
|
||||
+ @source.stubs(:metadata).returns stub_everything('metadata', :source => @sourcename, :ftype => 'file')
|
||||
end
|
||||
|
||||
- it "should return nil if source is not found" do
|
||||
- @response.expects(:code).returns("404")
|
||||
- @content.write(@fh).should == nil
|
||||
+ it "should write the contents to the file" do
|
||||
+ @resource.write(@source)
|
||||
+ File.read(@filename).should == @source_content
|
||||
end
|
||||
|
||||
it "should not write anything if source is not found" do
|
||||
- @response.expects(:code).returns("404")
|
||||
- @fh.expects(:print).never
|
||||
- @content.write(@fh).should == nil
|
||||
+ @response.stubs(:code).returns("404")
|
||||
+ lambda {@resource.write(@source)}.should raise_error(Net::HTTPError) { |e| e.message =~ /404/ }
|
||||
+ File.read(@filename).should == "initial file content"
|
||||
end
|
||||
|
||||
it "should raise an HTTP error in case of server error" do
|
||||
- @response.expects(:code).returns("500")
|
||||
- lambda { @content.write(@fh) }.should raise_error
|
||||
- end
|
||||
-
|
||||
- it "should write content by chunks" do
|
||||
- @response.expects(:code).returns("200")
|
||||
- @response.expects(:read_body).multiple_yields("chunk1","chunk2")
|
||||
- @fh.expects(:print).with("chunk1").then.with("chunk2")
|
||||
- @content.write(@fh)
|
||||
- end
|
||||
-
|
||||
- it "should pass each chunk to the current sum stream" do
|
||||
- @response.expects(:code).returns("200")
|
||||
- @response.expects(:read_body).multiple_yields("chunk1","chunk2")
|
||||
- @digest.expects(:<<).with("chunk1").then.with("chunk2")
|
||||
- @content.write(@fh)
|
||||
+ @response.stubs(:code).returns("500")
|
||||
+ lambda { @content.write(@fh) }.should raise_error { |e| e.message.include? @source_content }
|
||||
end
|
||||
|
||||
it "should return the checksum computed" do
|
||||
- @response.expects(:code).returns("200")
|
||||
- @response.expects(:read_body).multiple_yields("chunk1","chunk2")
|
||||
- @sum.expects(:sum_stream).yields(@digest).returns("checksum")
|
||||
- @content.write(@fh).should == "checksum"
|
||||
- end
|
||||
-
|
||||
- it "should get the current accept encoding header value" do
|
||||
- @content.expects(:add_accept_encoding)
|
||||
- @content.write(@fh)
|
||||
- end
|
||||
-
|
||||
- it "should uncompress body on error" do
|
||||
- @response.expects(:code).returns("500")
|
||||
- @response.expects(:body).returns("compressed body")
|
||||
- @content.expects(:uncompress_body).with(@response).returns("uncompressed")
|
||||
- lambda { @content.write(@fh) }.should raise_error { |e| e.message =~ /uncompressed/ }
|
||||
- end
|
||||
-
|
||||
- it "should uncompress chunk by chunk" do
|
||||
- uncompressor = stub_everything 'uncompressor'
|
||||
- @content.expects(:uncompress).with(@response).yields(uncompressor)
|
||||
- @response.expects(:code).returns("200")
|
||||
- @response.expects(:read_body).multiple_yields("chunk1","chunk2")
|
||||
-
|
||||
- uncompressor.expects(:uncompress).with("chunk1").then.with("chunk2")
|
||||
- @content.write(@fh)
|
||||
- end
|
||||
-
|
||||
- it "should write uncompressed chunks to the file" do
|
||||
- uncompressor = stub_everything 'uncompressor'
|
||||
- @content.expects(:uncompress).with(@response).yields(uncompressor)
|
||||
- @response.expects(:code).returns("200")
|
||||
- @response.expects(:read_body).multiple_yields("chunk1","chunk2")
|
||||
-
|
||||
- uncompressor.expects(:uncompress).with("chunk1").returns("uncompressed1")
|
||||
- uncompressor.expects(:uncompress).with("chunk2").returns("uncompressed2")
|
||||
-
|
||||
- @fh.expects(:print).with("uncompressed1")
|
||||
- @fh.expects(:print).with("uncompressed2")
|
||||
-
|
||||
- @content.write(@fh)
|
||||
- end
|
||||
-
|
||||
- it "should pass each uncompressed chunk to the current sum stream" do
|
||||
- uncompressor = stub_everything 'uncompressor'
|
||||
- @content.expects(:uncompress).with(@response).yields(uncompressor)
|
||||
- @response.expects(:code).returns("200")
|
||||
- @response.expects(:read_body).multiple_yields("chunk1","chunk2")
|
||||
-
|
||||
- uncompressor.expects(:uncompress).with("chunk1").returns("uncompressed1")
|
||||
- uncompressor.expects(:uncompress).with("chunk2").returns("uncompressed2")
|
||||
-
|
||||
- @digest.expects(:<<).with("uncompressed1").then.with("uncompressed2")
|
||||
- @content.write(@fh)
|
||||
+ File.open(@filename, 'w') do |file|
|
||||
+ @content.write(file).should == "{md5}#{Digest::MD5.hexdigest(@source_content)}"
|
||||
+ end
|
||||
end
|
||||
end
|
||||
|
||||
- describe "from a filebucket" do
|
||||
- end
|
||||
-
|
||||
# These are testing the implementation rather than the desired behaviour; while that bites, there are a whole
|
||||
# pile of other methods in the File type that depend on intimate details of this implementation and vice-versa.
|
||||
# If these blow up, you are gonna have to review the callers to make sure they don't explode! --daniel 2011-02-01
|
||||
--
|
||||
1.7.4.1
|
||||
|
@ -0,0 +1,123 @@
|
||||
From 852fb9744320c253772c85e52b262b0290fb7dd4 Mon Sep 17 00:00:00 2001
|
||||
From: Matt Robinson <matt@puppetlabs.com>
|
||||
Date: Tue, 15 Mar 2011 16:13:15 -0700
|
||||
Subject: [PATCH/puppet] (#5073) Download plugins even if you're filtering on tags
|
||||
|
||||
When we eval a resource in transaction.rb it was being skipped when
|
||||
filtering on tags and downloading the plugins. There's a lot of
|
||||
complicated conditions for whether to skip a resource, but this is a
|
||||
condensed version of the path that was causing plugins not to be
|
||||
downloaded.
|
||||
|
||||
skip?
|
||||
missing_tags?
|
||||
!ignore_tags?
|
||||
!host_config
|
||||
|
||||
The Puppet::Configurer::Downloader creates separate catalogs and applies them
|
||||
to get custom facts and plugins, so should be setting host_config to false.
|
||||
Puppet::Util::Settings also sets host_config to false when you call use on
|
||||
settings, while normal catalog application defaults to true.
|
||||
|
||||
Thanks to Stefan Schulte <stefan.schulte@taunusstein.net> for suggesting
|
||||
the implementation fix.
|
||||
---
|
||||
lib/puppet/configurer/downloader.rb | 1 +
|
||||
lib/puppet/configurer/plugin_handler.rb | 9 +++++++-
|
||||
spec/unit/configurer/downloader_spec.rb | 32 +++++++++++++++++++++---------
|
||||
3 files changed, 31 insertions(+), 11 deletions(-)
|
||||
|
||||
diff --git a/lib/puppet/configurer/downloader.rb b/lib/puppet/configurer/downloader.rb
|
||||
index 1b587ed..b369620 100644
|
||||
--- a/lib/puppet/configurer/downloader.rb
|
||||
+++ b/lib/puppet/configurer/downloader.rb
|
||||
@@ -50,6 +50,7 @@ class Puppet::Configurer::Downloader
|
||||
|
||||
def catalog
|
||||
catalog = Puppet::Resource::Catalog.new
|
||||
+ catalog.host_config = false
|
||||
catalog.add_resource(file)
|
||||
catalog
|
||||
end
|
||||
diff --git a/lib/puppet/configurer/plugin_handler.rb b/lib/puppet/configurer/plugin_handler.rb
|
||||
index cfc6b5a..ae088f2 100644
|
||||
--- a/lib/puppet/configurer/plugin_handler.rb
|
||||
+++ b/lib/puppet/configurer/plugin_handler.rb
|
||||
@@ -9,7 +9,14 @@ module Puppet::Configurer::PluginHandler
|
||||
# Retrieve facts from the central server.
|
||||
def download_plugins
|
||||
return nil unless download_plugins?
|
||||
- Puppet::Configurer::Downloader.new("plugin", Puppet[:plugindest], Puppet[:pluginsource], Puppet[:pluginsignore]).evaluate.each { |file| load_plugin(file) }
|
||||
+ plugin_downloader = Puppet::Configurer::Downloader.new(
|
||||
+ "plugin",
|
||||
+ Puppet[:plugindest],
|
||||
+ Puppet[:pluginsource],
|
||||
+ Puppet[:pluginsignore]
|
||||
+ )
|
||||
+
|
||||
+ plugin_downloader.evaluate.each { |file| load_plugin(file) }
|
||||
end
|
||||
|
||||
def load_plugin(file)
|
||||
diff --git a/spec/unit/configurer/downloader_spec.rb b/spec/unit/configurer/downloader_spec.rb
|
||||
index c57f39f..4080263 100755
|
||||
--- a/spec/unit/configurer/downloader_spec.rb
|
||||
+++ b/spec/unit/configurer/downloader_spec.rb
|
||||
@@ -5,6 +5,8 @@ require File.dirname(__FILE__) + '/../../spec_helper'
|
||||
require 'puppet/configurer/downloader'
|
||||
|
||||
describe Puppet::Configurer::Downloader do
|
||||
+ require 'puppet_spec/files'
|
||||
+ include PuppetSpec::Files
|
||||
it "should require a name" do
|
||||
lambda { Puppet::Configurer::Downloader.new }.should raise_error(ArgumentError)
|
||||
end
|
||||
@@ -96,25 +98,35 @@ describe Puppet::Configurer::Downloader do
|
||||
|
||||
describe "when creating the catalog to do the downloading" do
|
||||
before do
|
||||
- @dler = Puppet::Configurer::Downloader.new("foo", "path", "source")
|
||||
+ @dler = Puppet::Configurer::Downloader.new("foo", "/download/path", "source")
|
||||
end
|
||||
|
||||
it "should create a catalog and add the file to it" do
|
||||
- file = mock 'file'
|
||||
- catalog = mock 'catalog'
|
||||
-
|
||||
- @dler.expects(:file).returns file
|
||||
-
|
||||
- Puppet::Resource::Catalog.expects(:new).returns catalog
|
||||
- catalog.expects(:add_resource).with(file)
|
||||
+ catalog = @dler.catalog
|
||||
+ catalog.resources.size.should == 1
|
||||
+ catalog.resources.first.class.should == Puppet::Type::File
|
||||
+ catalog.resources.first.name.should == "/download/path"
|
||||
+ end
|
||||
|
||||
- @dler.catalog.should equal(catalog)
|
||||
+ it "should specify that it is not managing a host catalog" do
|
||||
+ @dler.catalog.host_config.should == false
|
||||
end
|
||||
+
|
||||
end
|
||||
|
||||
describe "when downloading" do
|
||||
before do
|
||||
- @dler = Puppet::Configurer::Downloader.new("foo", "path", "source")
|
||||
+ @dl_name = tmpfile("downloadpath")
|
||||
+ source_name = tmpfile("source")
|
||||
+ File.open(source_name, 'w') {|f| f.write('hola mundo') }
|
||||
+ @dler = Puppet::Configurer::Downloader.new("foo", @dl_name, source_name)
|
||||
+ end
|
||||
+
|
||||
+ it "should not skip downloaded resources when filtering on tags" do
|
||||
+ Puppet[:tags] = 'maytag'
|
||||
+ @dler.evaluate
|
||||
+
|
||||
+ File.exists?(@dl_name).should be_true
|
||||
end
|
||||
|
||||
it "should log that it is downloading" do
|
||||
--
|
||||
1.7.4.1
|
||||
|
@ -0,0 +1,182 @@
|
||||
From ff9e2425a58bb2b1ab836e440c3344b4012623c5 Mon Sep 17 00:00:00 2001
|
||||
From: Jacob Helwig <jacob@puppetlabs.com>
|
||||
Date: Fri, 25 Feb 2011 17:03:56 -0800
|
||||
Subject: [PATCH/puppet] (#5428) More fully "stub" Puppet::Resource::Reference for use with storedconfigs
|
||||
|
||||
The Puppet::Resource::Reference class wasn't stubbing enough of the 0.25.x
|
||||
behavior to satisfy the needs of storedconfigs. Since P::R::Reference,
|
||||
and Puppet::Resource were merged as part of 2.6.x, we can pretend that
|
||||
P::Resource is P::R::Reference for the purposes of loading data from
|
||||
storedconfigs. This should still satisfy the over-the-wire serialization
|
||||
needs of 0.25.x.
|
||||
|
||||
This also changes internal references to @parameters in
|
||||
Puppet::Resource(::Reference) to go through a parameters method. This
|
||||
allows us to "initialize" this instance variable lazily, since loading via
|
||||
YAML bypasses the normal initialize method.
|
||||
|
||||
Paired-with: Daniel Pittman <daniel@puppetlabs.com>
|
||||
Reviewed-by: Markus Roberts <markus@puppetlabs.com>
|
||||
---
|
||||
lib/puppet/resource.rb | 35 +++++++++++++++++++----------------
|
||||
spec/unit/resource_spec.rb | 26 ++++++++++++++++++++++++--
|
||||
2 files changed, 43 insertions(+), 18 deletions(-)
|
||||
|
||||
diff --git a/lib/puppet/resource.rb b/lib/puppet/resource.rb
|
||||
index e832804..e47fc7e 100644
|
||||
--- a/lib/puppet/resource.rb
|
||||
+++ b/lib/puppet/resource.rb
|
||||
@@ -5,6 +5,11 @@ require 'puppet/util/pson'
|
||||
# The simplest resource class. Eventually it will function as the
|
||||
# base class for all resource-like behaviour.
|
||||
class Puppet::Resource
|
||||
+ # This stub class is only needed for serialization compatibility with 0.25.x.
|
||||
+ # Specifically, it exists to provide a compatibility API when using YAML
|
||||
+ # serialized objects loaded from StoreConfigs.
|
||||
+ Reference = Puppet::Resource
|
||||
+
|
||||
include Puppet::Util::Tagging
|
||||
|
||||
require 'puppet/resource/type_collection_helper'
|
||||
@@ -104,7 +109,7 @@ class Puppet::Resource
|
||||
# be overridden at some point, but this works for now.
|
||||
%w{has_key? keys length delete empty? <<}.each do |method|
|
||||
define_method(method) do |*args|
|
||||
- @parameters.send(method, *args)
|
||||
+ parameters.send(method, *args)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -112,13 +117,13 @@ class Puppet::Resource
|
||||
# to lower-case symbols.
|
||||
def []=(param, value)
|
||||
validate_parameter(param) if validate_parameters
|
||||
- @parameters[parameter_name(param)] = value
|
||||
+ parameters[parameter_name(param)] = value
|
||||
end
|
||||
|
||||
# Return a given parameter's value. Converts all passed names
|
||||
# to lower-case symbols.
|
||||
def [](param)
|
||||
- @parameters[parameter_name(param)]
|
||||
+ parameters[parameter_name(param)]
|
||||
end
|
||||
|
||||
def ==(other)
|
||||
@@ -140,11 +145,11 @@ class Puppet::Resource
|
||||
|
||||
# Iterate over each param/value pair, as required for Enumerable.
|
||||
def each
|
||||
- @parameters.each { |p,v| yield p, v }
|
||||
+ parameters.each { |p,v| yield p, v }
|
||||
end
|
||||
|
||||
def include?(parameter)
|
||||
- super || @parameters.keys.include?( parameter_name(parameter) )
|
||||
+ super || parameters.keys.include?( parameter_name(parameter) )
|
||||
end
|
||||
|
||||
# These two methods are extracted into a Helper
|
||||
@@ -170,14 +175,6 @@ class Puppet::Resource
|
||||
end
|
||||
end
|
||||
|
||||
- # This stub class is only needed for serialization compatibility with 0.25.x
|
||||
- class Reference
|
||||
- attr_accessor :type,:title
|
||||
- def initialize(type,title)
|
||||
- @type,@title = type,title
|
||||
- end
|
||||
- end
|
||||
-
|
||||
# Create our resource.
|
||||
def initialize(type, title = nil, attributes = {})
|
||||
@parameters = {}
|
||||
@@ -204,7 +201,7 @@ class Puppet::Resource
|
||||
tag(self.type)
|
||||
tag(self.title) if valid_tag?(self.title)
|
||||
|
||||
- @reference = Reference.new(@type,@title) # for serialization compatibility with 0.25.x
|
||||
+ @reference = self # for serialization compatibility with 0.25.x
|
||||
if strict? and ! resource_type
|
||||
if @type == 'Class'
|
||||
raise ArgumentError, "Could not find declared class #{title}"
|
||||
@@ -234,7 +231,7 @@ class Puppet::Resource
|
||||
|
||||
# Produce a simple hash of our parameters.
|
||||
def to_hash
|
||||
- parse_title.merge @parameters
|
||||
+ parse_title.merge parameters
|
||||
end
|
||||
|
||||
def to_s
|
||||
@@ -256,7 +253,7 @@ class Puppet::Resource
|
||||
# Convert our resource to Puppet code.
|
||||
def to_manifest
|
||||
"%s { '%s':\n%s\n}" % [self.type.to_s.downcase, self.title,
|
||||
- @parameters.collect { |p, v|
|
||||
+ parameters.collect { |p, v|
|
||||
if v.is_a? Array
|
||||
" #{p} => [\'#{v.join("','")}\']"
|
||||
else
|
||||
@@ -422,4 +419,10 @@ class Puppet::Resource
|
||||
return { :name => title.to_s }
|
||||
end
|
||||
end
|
||||
+
|
||||
+ def parameters
|
||||
+ # @parameters could have been loaded from YAML, causing it to be nil (by
|
||||
+ # bypassing initialize).
|
||||
+ @parameters ||= {}
|
||||
+ end
|
||||
end
|
||||
diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb
|
||||
index ff31b24..4c1dc49 100755
|
||||
--- a/spec/unit/resource_spec.rb
|
||||
+++ b/spec/unit/resource_spec.rb
|
||||
@@ -99,11 +99,11 @@ describe Puppet::Resource do
|
||||
end
|
||||
|
||||
it 'should fail if strict is set and type does not exist' do
|
||||
- lambda { Puppet::Resource.new('foo', 'title', {:strict=>true}) }.should raise_error(ArgumentError, 'Invalid resource type foo')
|
||||
+ lambda { Puppet::Resource.new('foo', 'title', {:strict=>true}) }.should raise_error(ArgumentError, 'Invalid resource type foo')
|
||||
end
|
||||
|
||||
it 'should fail if strict is set and class does not exist' do
|
||||
- lambda { Puppet::Resource.new('Class', 'foo', {:strict=>true}) }.should raise_error(ArgumentError, 'Could not find declared class foo')
|
||||
+ lambda { Puppet::Resource.new('Class', 'foo', {:strict=>true}) }.should raise_error(ArgumentError, 'Could not find declared class foo')
|
||||
end
|
||||
|
||||
it "should fail if the title is a hash and the type is not a valid resource reference string" do
|
||||
@@ -463,6 +463,28 @@ describe Puppet::Resource do
|
||||
end
|
||||
end
|
||||
|
||||
+ describe "when loading 0.25.x storedconfigs YAML" do
|
||||
+ before :each do
|
||||
+ @old_storedconfig_yaml = %q{--- !ruby/object:Puppet::Resource::Reference
|
||||
+builtin_type:
|
||||
+title: /tmp/bar
|
||||
+type: File
|
||||
+}
|
||||
+ end
|
||||
+
|
||||
+ it "should deserialize a Puppet::Resource::Reference without exceptions" do
|
||||
+ lambda { YAML.load(@old_storedconfig_yaml) }.should_not raise_error
|
||||
+ end
|
||||
+
|
||||
+ it "should deserialize as a Puppet::Resource::Reference as a Puppet::Resource" do
|
||||
+ YAML.load(@old_storedconfig_yaml).class.should == Puppet::Resource
|
||||
+ end
|
||||
+
|
||||
+ it "should to_hash properly" do
|
||||
+ YAML.load(@old_storedconfig_yaml).to_hash.should == { :path => "/tmp/bar" }
|
||||
+ end
|
||||
+ end
|
||||
+
|
||||
describe "when converting to a RAL resource" do
|
||||
it "should use the resource type's :new method to create the resource if the resource is of a builtin type" do
|
||||
resource = Puppet::Resource.new("file", @basepath+"/my/file")
|
||||
--
|
||||
1.7.4.1
|
||||
|
Loading…
Reference in new issue