[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, master, updated. debian/0.24.7-1-98-gf19c0e5

James Turnbull james at lovedthanlost.net
Wed Apr 8 21:48:05 UTC 2009


The following commit has been merged in the master branch:
commit 6331bfc9b6dc5140147730b3c4f79fef35265a94
Author: Brice Figureau <brice-puppet at daysofwonder.com>
Date:   Thu Feb 5 19:55:29 2009 +0100

    Fix #1682 - Resource titles are not flattened as they should
    
    The following manifest:
    $groups = ["foo", "bar"]
    $type_groups = ["baz", "quux"]
    $user_groups = [$groups, $type_groups]
    notify{ $user_groups: }
    which outputs:
    notice: foo
    notice: //Notify[foobar]/message: defined 'message' as 'foo'
    notice: baz
    notice: //Notify[bazquux]/message: defined 'message' as 'baz'
    
    is not equivalent to
    $user_groups = [ ["foo", "bar"], ["baz", "quux"] ]
    notify{ $user_groups: }
    which outputs:
    notice: foo
    notice: //Notify[foo]/message: defined 'message' as 'foo'
    notice: baz
    notice: //Notify[baz]/message: defined 'message' as 'baz'
    notice: bar
    notice: //Notify[bar]/message: defined 'message' as 'bar'
    notice: quux
    notice: //Notify[quux]/message: defined 'message' as 'quux'
    
    Obviously the second one manages to flatten the arrays and not the
    first one.
    
    This changeset adds flattening to the resource titles evaluations
    in order to be consitent in all cases.
    
    Signed-off-by: Brice Figureau <brice-puppet at daysofwonder.com>

diff --git a/lib/puppet/parser/ast/resource.rb b/lib/puppet/parser/ast/resource.rb
index 1a07fc5..802410b 100644
--- a/lib/puppet/parser/ast/resource.rb
+++ b/lib/puppet/parser/ast/resource.rb
@@ -30,7 +30,7 @@ class Resource < AST::ResourceReference
         # This is where our implicit iteration takes place; if someone
         # passed an array as the name, then we act just like the called us
         # many times.
-        objtitles.collect { |objtitle|
+        objtitles.flatten.collect { |objtitle|
             exceptwrap :type => Puppet::ParseError do
                 exp = self.exported || scope.resource.exported?
                 # We want virtual to be true if exported is true.  We can't
diff --git a/spec/unit/parser/ast/resource.rb b/spec/unit/parser/ast/resource.rb
new file mode 100755
index 0000000..1546d65
--- /dev/null
+++ b/spec/unit/parser/ast/resource.rb
@@ -0,0 +1,90 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+describe Puppet::Parser::AST::Resource do
+
+    ast = Puppet::Parser::AST
+
+    before :each do
+        @title = stub_everything 'title'
+        @compiler = stub_everything 'compiler'
+        @scope = Puppet::Parser::Scope.new(:compiler => @compiler)
+        @param1 = stub_everything 'parameter', :is_a? => true
+        @scope.stubs(:resource).returns(stub_everything)
+        @params = ast::ASTArray.new( :children => [@param1])
+        @resource = ast::Resource.new(:title => @title, :type => "Resource", :params => @params )
+        @resource.stubs(:qualified_type).returns("Resource")
+        Puppet::Parser::Resource.stubs(:new).returns(stub_everything)
+    end
+
+    it "should evaluate all its parameters" do
+
+        @param1.expects(:safeevaluate).with(@scope)
+
+        @resource.evaluate(@scope)
+    end
+
+    it "should evaluate its title" do
+
+        @title.expects(:safeevaluate).with(@scope)
+
+        @resource.evaluate(@scope)
+    end
+
+    it "should flatten the titles array" do
+        titles = stub 'titles'
+        title_array = stub 'title_array', :is_a? => true
+
+        titles.stubs(:safeevaluate).with(@scope).returns(title_array)
+
+        title_array.expects(:flatten).returns([])
+
+        @resource.title = titles
+        @resource.evaluate(@scope)
+    end
+
+    it "should create one resource objects per title" do
+        titles = stub 'titles'
+        title_array = stub 'title_array', :is_a? => true
+
+        title_array.stubs(:flatten).returns([@title])
+        titles.stubs(:safeevaluate).with(@scope).returns(title_array)
+
+        Puppet::Parser::Resource.expects(:new).with { |hash| hash[:title] == @title }
+
+        @resource.title = titles
+        @resource.evaluate(@scope)
+    end
+
+    it "should handover resources to the compiler" do
+        resource = stub 'resource'
+        titles = stub 'titles'
+        title_array = stub 'title_array', :is_a? => true
+
+        title_array.stubs(:flatten).returns([@title])
+        titles.stubs(:safeevaluate).with(@scope).returns(title_array)
+        Puppet::Parser::Resource.stubs(:new).returns(resource)
+
+        @compiler.expects(:add_resource).with(@scope, resource)
+
+        @resource.title = titles
+        @resource.evaluate(@scope)
+    end
+
+    it "should return the newly created resources" do
+        resource = stub 'resource'
+        titles = stub 'titles'
+        title_array = stub 'title_array', :is_a? => true
+
+        title_array.stubs(:flatten).returns([@title])
+        titles.stubs(:safeevaluate).with(@scope).returns(title_array)
+        Puppet::Parser::Resource.stubs(:new).returns(resource)
+
+        @compiler.stubs(:add_resource).with(resource)
+
+        @resource.title = titles
+        @resource.evaluate(@scope).should == [resource]
+    end
+end
+

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list