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

test branch puppet-dev at googlegroups.com
Wed Jul 14 10:31:39 UTC 2010


The following commit has been merged in the upstream branch:
commit 9f8e0c0516421b0250454d54c935c8517170a93f
Author: Luke Kanies <luke at reductivelabs.com>
Date:   Wed Jan 6 16:36:16 2010 -0800

    Using the RTC helper to find the known resource types
    
    We previously defined the method statically.
    
    This also renames the method to match how the environment
    thinks of them - known resource types, rather than resource
    type collection.
    
    Signed-off-by: Luke Kanies <luke at reductivelabs.com>

diff --git a/lib/puppet/parser/parser_support.rb b/lib/puppet/parser/parser_support.rb
index 3b0b191..ac26ca7 100644
--- a/lib/puppet/parser/parser_support.rb
+++ b/lib/puppet/parser/parser_support.rb
@@ -4,11 +4,14 @@ class Puppet::Parser::Parser
     require 'puppet/parser/functions'
     require 'puppet/parser/files'
     require 'puppet/parser/resource_type_collection'
+    require 'puppet/parser/resource_type_collection_helper'
     require 'puppet/parser/resource_type'
     require 'monitor'
 
     AST = Puppet::Parser::AST
 
+    include Puppet::Parser::ResourceTypeCollectionHelper
+
     attr_reader :version, :environment
     attr_accessor :files
 
@@ -91,7 +94,7 @@ class Puppet::Parser::Parser
                 raise Puppet::Error, "Could not find file %s" % file
             end
         end
-        raise Puppet::AlreadyImportedError, "Import loop detected" if resource_type_collection.watching_file?(file)
+        raise Puppet::AlreadyImportedError, "Import loop detected" if known_resource_types.watching_file?(file)
 
         watch_file(file)
         @lexer.file = file
@@ -99,7 +102,7 @@ class Puppet::Parser::Parser
 
     [:hostclass, :definition, :node, :nodes?].each do |method|
         define_method(method) do |*args|
-            resource_type_collection.send(method, *args)
+            known_resource_types.send(method, *args)
         end
     end
 
@@ -132,7 +135,7 @@ class Puppet::Parser::Parser
             names_to_try.compact!
         end
 
-        until (result = resource_type_collection.send(method, namespace, name)) or names_to_try.empty? do
+        until (result = known_resource_types.send(method, namespace, name)) or names_to_try.empty? do
             self.load(names_to_try.shift)
         end
         return result
@@ -252,7 +255,7 @@ class Puppet::Parser::Parser
         end
         # We don't know whether we're looking for a class or definition, so we have
         # to test for both.
-        return resource_type_collection.hostclass(classname) || resource_type_collection.definition(classname)
+        return known_resource_types.hostclass(classname) || known_resource_types.definition(classname)
     end
 
     # Try to load a class, since we could not find it.
@@ -277,12 +280,12 @@ class Puppet::Parser::Parser
 
     # Create a new class, or merge with an existing class.
     def newclass(name, options = {})
-        resource_type_collection.add Puppet::Parser::ResourceType.new(:hostclass, name, ast_context(true).merge(options))
+        known_resource_types.add Puppet::Parser::ResourceType.new(:hostclass, name, ast_context(true).merge(options))
     end
 
     # Create a new definition.
     def newdefine(name, options = {})
-        resource_type_collection.add Puppet::Parser::ResourceType.new(:definition, name, ast_context(true).merge(options))
+        known_resource_types.add Puppet::Parser::ResourceType.new(:definition, name, ast_context(true).merge(options))
     end
 
     # Create a new node.  Nodes are special, because they're stored in a global
@@ -291,7 +294,7 @@ class Puppet::Parser::Parser
         names = [names] unless names.instance_of?(Array)
         context = ast_context(true)
         names.collect do |name|
-            resource_type_collection.add(Puppet::Parser::ResourceType.new(:node, name, context.merge(options)))
+            known_resource_types.add(Puppet::Parser::ResourceType.new(:node, name, context.merge(options)))
         end
     end
 
@@ -355,7 +358,7 @@ class Puppet::Parser::Parser
             # Store the results as the top-level class.
             newclass("", :code => main)
         end
-        return resource_type_collection
+        return known_resource_types
     ensure
         @lexer.clear
     end
@@ -377,19 +380,15 @@ class Puppet::Parser::Parser
         @lexer.string = string
     end
 
-    def resource_type_collection
-        environment.known_resource_types
-    end
-
     def version
-        resource_type_collection.version
+        known_resource_types.version
     end
 
     # Add a new file to be checked when we're checking to see if we should be
     # reparsed.  This is basically only used by the TemplateWrapper to let the
     # parser know about templates that should be parsed.
     def watch_file(filename)
-        resource_type_collection.watch_file(filename)
+        known_resource_types.watch_file(filename)
     end
 
     private
diff --git a/spec/unit/parser/parser.rb b/spec/unit/parser/parser.rb
index 2933b2d..cb96e0c 100755
--- a/spec/unit/parser/parser.rb
+++ b/spec/unit/parser/parser.rb
@@ -7,9 +7,9 @@ describe Puppet::Parser do
     ast = Puppet::Parser::AST
 
     before :each do
-        @resource_type_collection = Puppet::Parser::ResourceTypeCollection.new("development")
+        @known_resource_types = Puppet::Parser::ResourceTypeCollection.new("development")
         @parser = Puppet::Parser::Parser.new "development"
-        @parser.stubs(:resource_type_collection).returns @resource_type_collection
+        @parser.stubs(:known_resource_types).returns @known_resource_types
         @true_ast = Puppet::Parser::AST::Boolean.new :value => true
     end
 
@@ -30,7 +30,7 @@ describe Puppet::Parser do
     it "should be able to look up the environment-specific resource type collection" do
         rtc = Puppet::Node::Environment.new("development").known_resource_types
         parser = Puppet::Parser::Parser.new "development"
-        parser.resource_type_collection.should equal(rtc)
+        parser.known_resource_types.should equal(rtc)
     end
 
     describe "when parsing files" do
@@ -296,8 +296,8 @@ describe Puppet::Parser do
     end
 
     describe "when retrieving a specific node" do
-        it "should delegate to the resource_type_collection node" do
-            @resource_type_collection.expects(:node).with("node")
+        it "should delegate to the known_resource_types node" do
+            @known_resource_types.expects(:node).with("node")
 
             @parser.node("node")
         end
@@ -305,7 +305,7 @@ describe Puppet::Parser do
 
     describe "when retrieving a specific class" do
         it "should delegate to the loaded code" do
-            @resource_type_collection.expects(:hostclass).with("class")
+            @known_resource_types.expects(:hostclass).with("class")
 
             @parser.hostclass("class")
         end
@@ -313,7 +313,7 @@ describe Puppet::Parser do
 
     describe "when retrieving a specific definitions" do
         it "should delegate to the loaded code" do
-            @resource_type_collection.expects(:definition).with("define")
+            @known_resource_types.expects(:definition).with("define")
 
             @parser.definition("define")
         end
@@ -321,7 +321,7 @@ describe Puppet::Parser do
 
     describe "when determining the configuration version" do
         it "should determine it from the resource type collection" do
-            @parser.resource_type_collection.expects(:version).returns "foo"
+            @parser.known_resource_types.expects(:version).returns "foo"
             @parser.version.should == "foo"
         end
     end
@@ -342,11 +342,11 @@ describe Puppet::Parser do
 
     describe "when looking up names" do
         before :each do
-            @resource_type_collection = mock 'loaded code'
-            @resource_type_collection.stubs(:find_my_type).with('loaded_namespace',  'loaded_name').returns(true)
-            @resource_type_collection.stubs(:find_my_type).with('bogus_namespace',   'bogus_name' ).returns(false)
+            @known_resource_types = mock 'loaded code'
+            @known_resource_types.stubs(:find_my_type).with('loaded_namespace',  'loaded_name').returns(true)
+            @known_resource_types.stubs(:find_my_type).with('bogus_namespace',   'bogus_name' ).returns(false)
             @parser = Puppet::Parser::Parser.new "development"
-            @parser.stubs(:resource_type_collection).returns @resource_type_collection
+            @parser.stubs(:known_resource_types).returns @known_resource_types
         end
 
         describe "that are already loaded" do
@@ -361,20 +361,20 @@ describe Puppet::Parser do
 
         describe "that aren't already loaded" do
             it "should first attempt to load them with the all lowercase fully qualified name" do
-                @resource_type_collection.stubs(:find_my_type).with("foo_namespace","foo_name").returns(false,true,true)
+                @known_resource_types.stubs(:find_my_type).with("foo_namespace","foo_name").returns(false,true,true)
                 @parser.expects(:load).with("foo_namespace::foo_name").returns(true).then.raises(Exception)
                 @parser.find_or_load("Foo_namespace","Foo_name",:my_type).should == true
             end
 
             it "should next attempt to load them with the all lowercase namespace" do
-                @resource_type_collection.stubs(:find_my_type).with("foo_namespace","foo_name").returns(false,false,true,true)
+                @known_resource_types.stubs(:find_my_type).with("foo_namespace","foo_name").returns(false,false,true,true)
                 @parser.expects(:load).with("foo_namespace::foo_name").returns(false).then.raises(Exception)
                 @parser.expects(:load).with("foo_namespace"          ).returns(true ).then.raises(Exception)
                 @parser.find_or_load("Foo_namespace","Foo_name",:my_type).should == true
             end
 
             it "should finally attempt to load them with the all lowercase unqualified name" do
-                @resource_type_collection.stubs(:find_my_type).with("foo_namespace","foo_name").returns(false,false,false,true,true)
+                @known_resource_types.stubs(:find_my_type).with("foo_namespace","foo_name").returns(false,false,false,true,true)
                 @parser.expects(:load).with("foo_namespace::foo_name").returns(false).then.raises(Exception)
                 @parser.expects(:load).with("foo_namespace"          ).returns(false).then.raises(Exception)
                 @parser.expects(:load).with(               "foo_name").returns(true ).then.raises(Exception)
@@ -387,7 +387,7 @@ describe Puppet::Parser do
             end
 
             it "should directly look for fully qualified classes" do
-                @resource_type_collection.stubs(:find_hostclass).with("foo_namespace","::foo_name").returns(false, true)
+                @known_resource_types.stubs(:find_hostclass).with("foo_namespace","::foo_name").returns(false, true)
                 @parser.expects(:load).with("foo_name").returns true
                 @parser.find_or_load("foo_namespace","::foo_name",:hostclass)
             end
@@ -396,9 +396,9 @@ describe Puppet::Parser do
 
     describe "when loading classnames" do
         before :each do
-            @resource_type_collection = mock 'loaded code'
+            @known_resource_types = mock 'loaded code'
             @parser = Puppet::Parser::Parser.new "development"
-            @parser.stubs(:resource_type_collection).returns @resource_type_collection
+            @parser.stubs(:known_resource_types).returns @known_resource_types
         end
 
         it "should just return false if the classname is empty" do

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list