diff options
author | Brice Figureau <brice-puppet@daysofwonder.com> | 2009-03-25 22:44:58 +0100 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2009-03-27 00:09:43 +1100 |
commit | 62dad7a5f87f8d6285650ab1b727819db27cf2a7 (patch) | |
tree | fba5b99dee9163db41471fc92b29bafb956d44f2 | |
parent | cbee426854c09fae4d9675edb787d4563e9b9ac8 (diff) | |
download | puppet-62dad7a5f87f8d6285650ab1b727819db27cf2a7.tar.gz puppet-62dad7a5f87f8d6285650ab1b727819db27cf2a7.tar.xz puppet-62dad7a5f87f8d6285650ab1b727819db27cf2a7.zip |
Fix #2107 - flatten resource references arrays properly
Resource parameters of the form
[Res[a], Res[a,b]] ends being evaluated as
[Res[a], [ Res[a], Res[b] ]
This last form was not flattened when transfomed into RAL
type, which in turn prevented the sub array to be converted
in regular resource references.
Thus the type was choking when encountering those native
parser references instead of usual resource reference.
The fix consists in flattening array of references before
transformation to trans objects for RAL.
Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
-rw-r--r-- | lib/puppet/parser/resource.rb | 4 | ||||
-rwxr-xr-x | spec/unit/parser/resource.rb | 8 |
2 files changed, 12 insertions, 0 deletions
diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb index d4c7a1f0f..47dc798b3 100644 --- a/lib/puppet/parser/resource.rb +++ b/lib/puppet/parser/resource.rb @@ -289,6 +289,10 @@ class Puppet::Parser::Resource if v.is_a?(Puppet::Parser::Resource::Reference) v = Puppet::Resource::Reference.new(v.type, v.title) elsif v.is_a?(Array) + # flatten resource references arrays + if v.flatten.find { |av| av.is_a?(Puppet::Parser::Resource::Reference) } + v = v.flatten + end v = v.collect do |av| if av.is_a?(Puppet::Parser::Resource::Reference) av = Puppet::Resource::Reference.new(av.type, av.title) diff --git a/spec/unit/parser/resource.rb b/spec/unit/parser/resource.rb index 410494d43..92699e040 100755 --- a/spec/unit/parser/resource.rb +++ b/spec/unit/parser/resource.rb @@ -425,5 +425,13 @@ describe Puppet::Parser::Resource do result = @parser_resource.to_resource result[:fee].should == ["a", Puppet::Resource::Reference.new(:file, "/my/file")] end + + it "should convert any parser resource references to Puppet::Resource::Reference instances even if they are in an array of array, and even deeper" do + ref1 = Puppet::Parser::Resource::Reference.new(:title => "/my/file1", :type => "file") + ref2 = Puppet::Parser::Resource::Reference.new(:title => "/my/file2", :type => "file") + @parser_resource = mkresource :source => @source, :params => {:foo => "bar", :fee => ["a", [ref1,ref2]]} + result = @parser_resource.to_resource + result[:fee].should == ["a", Puppet::Resource::Reference.new(:file, "/my/file1"), Puppet::Resource::Reference.new(:file, "/my/file2")] + end end end |