[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. 2.6.1rc1-141-gcdb2b90

markus (none) markus at AVA-351181.
Mon Aug 16 12:48:48 UTC 2010


The following commit has been merged in the upstream branch:
commit 1faebdd7b54a55b023f151976644dbc3405c486b
Author: Jesse Wolfe <jes5199 at gmail.com>
Date:   Mon Aug 2 17:23:36 2010 -0700

    [#4423] repair parameterized class instantiation
    
    My earlier #4397 patch was not aware of the parameterized class
    instantiation syntax, and failed on manifests that instantiate
    parameterized classes.

diff --git a/lib/puppet/parser/ast/resource.rb b/lib/puppet/parser/ast/resource.rb
index 9149b06..0c58538 100644
--- a/lib/puppet/parser/ast/resource.rb
+++ b/lib/puppet/parser/ast/resource.rb
@@ -33,11 +33,12 @@ 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.
-    resource_type = scope.find_resource_type(type)
+    fully_qualified_type, resource_titles = scope.resolve_type_and_titles(type, resource_titles)
+
     resource_titles.flatten.collect { |resource_title|
       exceptwrap :type => Puppet::ParseError do
         resource = Puppet::Parser::Resource.new(
-          resource_type.name, resource_title,
+          fully_qualified_type, resource_title,
           :parameters => paramobjects,
           :file => self.file,
           :line => self.line,
diff --git a/lib/puppet/parser/ast/resource_reference.rb b/lib/puppet/parser/ast/resource_reference.rb
index 5b1b0aa..0f8e655 100644
--- a/lib/puppet/parser/ast/resource_reference.rb
+++ b/lib/puppet/parser/ast/resource_reference.rb
@@ -7,23 +7,9 @@ class Puppet::Parser::AST::ResourceReference < Puppet::Parser::AST::Branch
   # Evaluate our object, but just return a simple array of the type
   # and name.
   def evaluate(scope)
-    a_type = type
     titles = Array(title.safeevaluate(scope))
 
-    case type.downcase
-    when "class"
-      # resolve the titles
-      titles = titles.collect do |a_title|
-        hostclass = scope.find_hostclass(a_title)
-        hostclass ?  hostclass.name : a_title
-      end
-    when "node"
-      # no-op
-    else
-      # resolve the type
-      resource_type = scope.find_resource_type(type)
-      a_type = resource_type.name if resource_type
-    end
+    a_type, titles = scope.resolve_type_and_titles(type, titles)
 
     resources = titles.collect{ |a_title|
       Puppet::Resource.new(a_type, a_title)
diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb
index 2ca28d8..24f1d01 100644
--- a/lib/puppet/parser/scope.rb
+++ b/lib/puppet/parser/scope.rb
@@ -488,6 +488,27 @@ class Puppet::Parser::Scope
     environment.known_resource_types.find_definition(namespaces, type.to_s.downcase)
   end
 
+  def resolve_type_and_titles(type, titles)
+    raise ArgumentError, "titles must be an array" unless titles.is_a?(Array)
+
+    case type.downcase
+    when "class"
+      # resolve the titles
+      titles = titles.collect do |a_title|
+        hostclass = find_hostclass(a_title)
+        hostclass ?  hostclass.name : a_title
+      end
+    when "node"
+      # no-op
+    else
+      # resolve the type
+      resource_type = find_resource_type(type)
+      type = resource_type.name if resource_type
+    end
+
+    return [type, titles]
+  end
+
   private
 
   def extend_with_functions_module
diff --git a/spec/unit/parser/ast/resource_spec.rb b/spec/unit/parser/ast/resource_spec.rb
index 58ffae9..5c94ac0 100755
--- a/spec/unit/parser/ast/resource_spec.rb
+++ b/spec/unit/parser/ast/resource_spec.rb
@@ -113,6 +113,13 @@ describe Puppet::Parser::AST::Resource do
       resource("file").evaluate(@twoscope)[0].type.should == "File"
     end
 
+    it "should correctly generate resources that can look up defined classes by title" do
+      @scope.known_resource_types.add_hostclass Puppet::Resource::Type.new(:hostclass, "Myresource", {})
+      res = resource("class").evaluate(@twoscope)[0]
+      res.type.should == "Class"
+      res.title.should == "Myresource"
+    end
+
     it "should fail for resource types that do not exist" do
       lambda { resource("nosuchtype").evaluate(@twoscope) }.should raise_error(Puppet::ParseError)
     end

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list