[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. 0.25.5-639-g8f94f35

Markus Roberts Markus at reality.com
Wed Jul 14 10:35:38 UTC 2010


The following commit has been merged in the upstream branch:
commit 153d7cd69b8b5216695206cbc235dd89a65dec76
Author: Brice Figureau <brice-puppet at daysofwonder.com>
Date:   Sat Apr 24 17:41:01 2010 +0200

    Fix #3665 - part 2, node inheritance fixes
    
    We were looking only to the class hierarchies when trying to find an
    ancestor to the current type. Thus we were never trying to climb up
    the hierarchy of nodes when evaluating nodes.
    
    Signed-off-by: Brice Figureau <brice-puppet at daysofwonder.com>

diff --git a/lib/puppet/resource/type.rb b/lib/puppet/resource/type.rb
index 825cce3..cb87cc4 100644
--- a/lib/puppet/resource/type.rb
+++ b/lib/puppet/resource/type.rb
@@ -178,7 +178,7 @@ class Puppet::Resource::Type
         return nil unless parent
 
         unless @parent_type ||= resource_type_collection.send(type, parent)
-            fail Puppet::ParseError, "Could not find parent resource type '#{parent}'"
+            fail Puppet::ParseError, "Could not find parent resource type '#{parent}' of type #{type}"
         end
 
         @parent_type
@@ -219,12 +219,14 @@ class Puppet::Resource::Type
         if caller_name = scope.parent_module_name and ! set.include?(:caller_module_name)
             scope.setvar("caller_module_name", caller_name)
         end
-        scope.class_set(self.name,scope) if hostclass?
+        scope.class_set(self.name,scope) if hostclass? or node?
     end
 
     # Create a new subscope in which to evaluate our code.
     def subscope(scope, resource)
-        scope.newscope :resource => resource, :namespace => self.namespace, :source => self
+        scope = scope.newscope :resource => resource, :namespace => self.namespace, :source => self
+        scope.nodescope = true if @type == :node
+        scope
     end
 
     # Check whether a given argument is valid.
@@ -261,8 +263,7 @@ class Puppet::Resource::Type
     end
 
     def evaluate_parent_type(resource)
-        #return unless klass = parent_type and parent_resource = resource.scope.compiler.catalog.resource(:class, klass.name)
-        return unless klass = parent_type and parent_resource = resource.catalog.resource(:class, klass.name)
+        return unless klass = parent_type and parent_resource = resource.scope.compiler.catalog.resource(:class, klass.name) || resource.scope.compiler.catalog.resource(:node, klass.name)
         parent_resource.evaluate unless parent_resource.evaluated?
         return parent_scope(resource.scope, klass)
     end
diff --git a/spec/unit/resource/type_spec.rb b/spec/unit/resource/type_spec.rb
index 2a8802c..044b81e 100755
--- a/spec/unit/resource/type_spec.rb
+++ b/spec/unit/resource/type_spec.rb
@@ -489,6 +489,47 @@ describe Puppet::Resource::Type do
                 @scope.class_scope(@type).parent.object_id.should == @scope.class_scope(@parent_type).object_id
             end
         end
+
+        describe "and it has a parent node" do
+            before do
+                @type = Puppet::Resource::Type.new(:node, "foo")
+                @parent_type = Puppet::Resource::Type.new(:node, "parent")
+                @type.parent = "parent"
+                @parent_resource = Puppet::Parser::Resource.new(:node, "parent", :scope => @scope)
+
+                @compiler.add_resource @scope, @parent_resource
+
+                @type.resource_type_collection = @scope.known_resource_types
+                @type.resource_type_collection.stubs(:node).with("parent").returns(@parent_type)
+                @type.resource_type_collection.stubs(:node).with("Parent").returns(@parent_type)
+            end
+
+            it "should evaluate the parent's resource" do
+                @type.evaluate_code(@resource)
+
+                @scope.class_scope(@parent_type).should_not be_nil
+            end
+
+            it "should not evaluate the parent's resource if it has already been evaluated" do
+                @parent_resource.evaluate
+
+                @parent_resource.expects(:evaluate).never
+
+                @type.evaluate_code(@resource)
+            end
+
+            it "should use a nodescope subscope" do
+                @type.evaluate_code(@resource)
+
+                @scope.class_scope(@type).nodescope.should be_true
+            end
+
+            it "should use the parent's scope as its base scope" do
+                @type.evaluate_code(@resource)
+
+                @scope.class_scope(@type).parent.object_id.should == @scope.class_scope(@parent_type).object_id
+            end
+        end
     end
 
     describe "when creating a resource" do

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list