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

Markus Roberts Markus at reality.com
Tue Jul 20 07:42:42 UTC 2010


The following commit has been merged in the upstream branch:
commit 1288f8c4051105d6cfbf4f532d5e5e926613e9df
Author: Jesse Wolfe <jes5199 at gmail.com>
Date:   Mon Jul 19 18:28:30 2010 -0700

    [#4270] Force inherited classes to load into the correct environment
    
    Parent classes were getting searched for in a way that fails if they
    were not already loaded into an environment. This patch replaces that
    codepath with a call that will load them if they are needed.
    
    This bug was masked by another bug that loads all classes into
    "production", whether they are used there or not.

diff --git a/lib/puppet/parser/type_loader.rb b/lib/puppet/parser/type_loader.rb
index c33f90d..35ad495 100644
--- a/lib/puppet/parser/type_loader.rb
+++ b/lib/puppet/parser/type_loader.rb
@@ -88,7 +88,7 @@ class Puppet::Parser::TypeLoader
         nil
       end
       if result = yield(filename)
-        Puppet.info "Automatically imported #{name} from #{filename}"
+        Puppet.info "Automatically imported #{name} from #{filename} into #{environment}"
         result.module_name = modname if modname and result.respond_to?(:module_name=)
         return result
       end
diff --git a/lib/puppet/resource.rb b/lib/puppet/resource.rb
index ca7c212..96d22e4 100644
--- a/lib/puppet/resource.rb
+++ b/lib/puppet/resource.rb
@@ -357,7 +357,8 @@ class Puppet::Resource
 
   def find_resource_type(type)
     # It still works fine without the type == 'class' short-cut, but it is a lot slower.
-    find_builtin_resource_type(type) || find_defined_resource_type(type) unless type.to_s.downcase == 'class'
+    return nil if ["class", "node"].include? type.to_s.downcase
+    find_builtin_resource_type(type) || find_defined_resource_type(type)
   end
 
   def find_builtin_resource_type(type)
diff --git a/lib/puppet/resource/type.rb b/lib/puppet/resource/type.rb
index c2b4271..85c0979 100644
--- a/lib/puppet/resource/type.rb
+++ b/lib/puppet/resource/type.rb
@@ -145,7 +145,12 @@ class Puppet::Resource::Type
     resource_type = type == :hostclass ? :class : :node
 
     # Make sure our parent class has been evaluated, if we have one.
-    parent_type.mk_plain_resource(scope) if parent and ! scope.catalog.resource(resource_type, parent)
+    if parent
+      parent_resource = scope.catalog.resource(resource_type, parent)
+      unless parent_resource
+        parent_type(scope).mk_plain_resource(scope)
+      end
+    end
 
     # Do nothing if the resource already exists; this makes sure we don't
     # get multiple copies of the class resource, which helps provide the
@@ -169,11 +174,14 @@ class Puppet::Resource::Type
     @name.is_a?(Regexp)
   end
 
-  def parent_type
+  def parent_type(scope = nil)
     return nil unless parent
 
-    unless @parent_type ||= resource_type_collection.send(type, parent)
-      fail Puppet::ParseError, "Could not find parent resource type '#{parent}' of type #{type}"
+    unless @parent_type
+      raise "Must pass scope to parent_type when called first time" unless scope
+      unless @parent_type = scope.environment.known_resource_types.send("find_#{type}", scope.namespaces, parent)
+        fail Puppet::ParseError, "Could not find parent resource type '#{parent}' of type #{type} in #{scope.environment}"
+      end
     end
 
     @parent_type
@@ -255,7 +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) || resource.scope.compiler.catalog.resource(:node, klass.name)
+    return unless klass = parent_type(resource.scope) 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?
     parent_scope(resource.scope, klass)
   end
diff --git a/lib/puppet/resource/type_collection.rb b/lib/puppet/resource/type_collection.rb
index 9ed2733..6a93336 100644
--- a/lib/puppet/resource/type_collection.rb
+++ b/lib/puppet/resource/type_collection.rb
@@ -134,7 +134,7 @@ class Puppet::Resource::TypeCollection
     loader.load_until(namespaces, name) { find(namespaces, name, type) }
   end
 
-  def find_node(name)
+  def find_node(namespaces, name)
     find("", name, :node)
   end
 
diff --git a/spec/unit/resource/type_collection_spec.rb b/spec/unit/resource/type_collection_spec.rb
index 788ea41..09643cd 100644
--- a/spec/unit/resource/type_collection_spec.rb
+++ b/spec/unit/resource/type_collection_spec.rb
@@ -263,7 +263,7 @@ describe Puppet::Resource::TypeCollection do
   it "should use the generic 'find' method with an empty namespace to find nodes" do
     loader = Puppet::Resource::TypeCollection.new("env")
     loader.expects(:find).with("", "bar", :node)
-    loader.find_node("bar")
+    loader.find_node(stub("ignored"), "bar")
   end
 
   it "should use the 'find_or_load' method to find hostclasses" do
diff --git a/spec/unit/resource/type_spec.rb b/spec/unit/resource/type_spec.rb
index be2e6b1..0ef4a51 100755
--- a/spec/unit/resource/type_spec.rb
+++ b/spec/unit/resource/type_spec.rb
@@ -346,6 +346,9 @@ describe Puppet::Resource::Type do
 
       @child = Puppet::Resource::Type.new(:hostclass, "foo", :parent => "bar")
       @code.add @child
+
+      @env   = stub "environment", :known_resource_types => @code
+      @scope = stub "scope", :environment => @env, :namespaces => [""]
     end
 
     it "should be able to define a parent" do
@@ -353,7 +356,7 @@ describe Puppet::Resource::Type do
     end
 
     it "should use the code collection to find the parent resource type" do
-      @child.parent_type.should equal(@parent)
+      @child.parent_type(@scope).should equal(@parent)
     end
 
     it "should be able to find parent nodes" do
@@ -362,16 +365,17 @@ describe Puppet::Resource::Type do
       child = Puppet::Resource::Type.new(:node, "foo", :parent => "bar")
       @code.add child
 
-      child.parent_type.should equal(parent)
+      child.parent_type(@scope).should equal(parent)
     end
 
     it "should cache a reference to the parent type" do
       @code.expects(:hostclass).once.with("bar").returns @parent
-      @child.parent_type
+      @child.parent_type(@scope)
       @child.parent_type
     end
 
     it "should correctly state when it is another type's child" do
+      @child.parent_type(@scope)
       @child.should be_child_of(@parent)
     end
 
@@ -379,6 +383,9 @@ describe Puppet::Resource::Type do
       @grandchild = Puppet::Resource::Type.new(:hostclass, "baz", :parent => "foo")
       @code.add @grandchild
 
+      @child.parent_type(@scope)
+      @grandchild.parent_type(@scope)
+
       @grandchild.should be_child_of(@parent)
     end
 
@@ -470,6 +477,8 @@ describe Puppet::Resource::Type do
       end
 
       it "should evaluate the parent's resource" do
+        @type.parent_type(@scope)
+        
         @type.evaluate_code(@resource)
 
         @scope.class_scope(@parent_type).should_not be_nil
@@ -477,6 +486,8 @@ describe Puppet::Resource::Type do
 
       it "should not evaluate the parent's resource if it has already been evaluated" do
         @parent_resource.evaluate
+        
+        @type.parent_type(@scope)
 
         @parent_resource.expects(:evaluate).never
 
@@ -484,6 +495,8 @@ describe Puppet::Resource::Type do
       end
 
       it "should use the parent's scope as its base scope" do
+        @type.parent_type(@scope)
+
         @type.evaluate_code(@resource)
 
         @scope.class_scope(@type).parent.object_id.should == @scope.class_scope(@parent_type).object_id
@@ -505,6 +518,8 @@ describe Puppet::Resource::Type do
       end
 
       it "should evaluate the parent's resource" do
+        @type.parent_type(@scope)
+
         @type.evaluate_code(@resource)
 
         @scope.class_scope(@parent_type).should_not be_nil
@@ -512,6 +527,8 @@ describe Puppet::Resource::Type do
 
       it "should not evaluate the parent's resource if it has already been evaluated" do
         @parent_resource.evaluate
+        
+        @type.parent_type(@scope)
 
         @parent_resource.expects(:evaluate).never
 
@@ -519,6 +536,8 @@ describe Puppet::Resource::Type do
       end
 
       it "should use the parent's scope as its base scope" do
+        @type.parent_type(@scope)
+
         @type.evaluate_code(@resource)
 
         @scope.class_scope(@type).parent.object_id.should == @scope.class_scope(@parent_type).object_id
@@ -528,7 +547,7 @@ describe Puppet::Resource::Type do
 
   describe "when creating a resource" do
     before do
-      @node = Puppet::Node.new("foo")
+      @node = Puppet::Node.new("foo", :environment => 'env')
       @compiler = Puppet::Parser::Compiler.new(@node)
       @scope = Puppet::Parser::Scope.new(:compiler => @compiler)
 
@@ -538,6 +557,8 @@ describe Puppet::Resource::Type do
       @code = Puppet::Resource::TypeCollection.new("env")
       @code.add @top
       @code.add @middle
+      
+      @node.environment.stubs(:known_resource_types).returns(@code)
     end
 
     it "should create a resource instance" do

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list