diff options
author | Brice Figureau <brice-puppet@daysofwonder.com> | 2010-04-24 17:41:01 +0200 |
---|---|---|
committer | Markus Roberts <Markus@reality.com> | 2010-06-28 14:19:54 -0700 |
commit | 153d7cd69b8b5216695206cbc235dd89a65dec76 (patch) | |
tree | c04f05a495bbbc72a29df86f2b1d0b881f77f614 | |
parent | dd4fa6686b31501ab8d8f800a81715e713b14031 (diff) | |
download | puppet-153d7cd69b8b5216695206cbc235dd89a65dec76.tar.gz puppet-153d7cd69b8b5216695206cbc235dd89a65dec76.tar.xz puppet-153d7cd69b8b5216695206cbc235dd89a65dec76.zip |
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@daysofwonder.com>
-rw-r--r-- | lib/puppet/resource/type.rb | 11 | ||||
-rwxr-xr-x | spec/unit/resource/type_spec.rb | 41 |
2 files changed, 47 insertions, 5 deletions
diff --git a/lib/puppet/resource/type.rb b/lib/puppet/resource/type.rb index 825cce39e..cb87cc44f 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 2a8802c73..044b81e41 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 |