[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:38 UTC 2010


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

    Moving Rails initialization to Compiler terminus
    
    It was previously handled by the Interpreter,
    but we're planning on getting of that.
    
    Signed-off-by: Luke Kanies <luke at reductivelabs.com>

diff --git a/lib/puppet/indirector/catalog/compiler.rb b/lib/puppet/indirector/catalog/compiler.rb
index 4f6b060..ecb1c74 100644
--- a/lib/puppet/indirector/catalog/compiler.rb
+++ b/lib/puppet/indirector/catalog/compiler.rb
@@ -49,6 +49,7 @@ class Puppet::Resource::Catalog::Compiler < Puppet::Indirector::Code
 
     def initialize
         set_server_facts
+        setup_database_backend if Puppet[:storeconfigs]
     end
 
     # Create/return our interpreter.
@@ -163,6 +164,11 @@ class Puppet::Resource::Catalog::Compiler < Puppet::Indirector::Code
         end
     end
 
+    def setup_database_backend
+        raise Puppet::Error, "Rails is missing; cannot store configurations" unless Puppet.features.rails?
+        Puppet::Rails.init
+    end
+
     # Mark that the node has checked in. LAK:FIXME this needs to be moved into
     # the Node class, or somewhere that's got abstract backends.
     def update_node_check(node)
diff --git a/lib/puppet/parser/interpreter.rb b/lib/puppet/parser/interpreter.rb
index bc0ae4f..1b15820 100644
--- a/lib/puppet/parser/interpreter.rb
+++ b/lib/puppet/parser/interpreter.rb
@@ -17,11 +17,6 @@ class Puppet::Parser::Interpreter
 
     include Puppet::Util::Errors
 
-    # Determine the configuration version for a given node's environment.
-    def configuration_version(node)
-        parser(node.environment).version
-    end
-
     # evaluate our whole tree
     def compile(node)
         raise Puppet::ParseError, "Could not parse configuration; cannot compile on node %s" % node.name unless env_parser = parser(node.environment)
@@ -35,15 +30,6 @@ class Puppet::Parser::Interpreter
 
     # create our interpreter
     def initialize
-        # The class won't always be defined during testing.
-        if Puppet[:storeconfigs]
-            if Puppet.features.rails?
-                Puppet::Rails.init
-            else
-                raise Puppet::Error, "Rails is missing; cannot store configurations"
-            end
-        end
-
         @parsers = {}
     end
 
@@ -61,7 +47,7 @@ class Puppet::Parser::Interpreter
     # Create a new parser object and pre-parse the configuration.
     def create_parser(environment)
         begin
-            parser = Puppet::Parser::Parser.new(:environment => environment)
+            parser = Puppet::Parser::Parser.new(environment)
             if code = Puppet.settings.uninterpolated_value(:code, environment) and code != ""
                 parser.string = code
             else
diff --git a/spec/unit/indirector/catalog/compiler.rb b/spec/unit/indirector/catalog/compiler.rb
index 84f5cdc..e2c18de 100755
--- a/spec/unit/indirector/catalog/compiler.rb
+++ b/spec/unit/indirector/catalog/compiler.rb
@@ -8,6 +8,12 @@ require File.dirname(__FILE__) + '/../../../spec_helper'
 require 'puppet/indirector/catalog/compiler'
 
 describe Puppet::Resource::Catalog::Compiler do
+    before do
+        Puppet::Rails.stubs(:init)
+        Facter.stubs(:to_hash).returns({})
+        Facter.stubs(:[]).returns(Facter::Util::Fact.new("something"))
+    end
+
     describe "when initializing" do
         before do
             Puppet.expects(:version).returns(1)
@@ -35,6 +41,24 @@ describe Puppet::Resource::Catalog::Compiler do
             compiler = Puppet::Resource::Catalog::Compiler.new
             compiler.should respond_to(:networked?)
         end
+
+        describe "and storeconfigs is enabled" do
+            before do
+                Puppet.settings[:storeconfigs] = true
+            end
+
+            it "should initialize Rails if it is available" do
+                Puppet.features.expects(:rails?).returns true
+                Puppet::Rails.expects(:init)
+                Puppet::Resource::Catalog::Compiler.new
+            end
+
+            it "should fail if Rails is unavailable" do
+                Puppet.features.expects(:rails?).returns false
+                Puppet::Rails.expects(:init).never
+                lambda { Puppet::Resource::Catalog::Compiler.new }.should raise_error(Puppet::Error)
+            end
+        end
     end
 
     describe "when creating the interpreter" do
@@ -68,6 +92,7 @@ describe Puppet::Resource::Catalog::Compiler do
             @name = "me"
             @node = Puppet::Node.new @name
             @node.stubs(:merge)
+            Puppet::Node.stubs(:find).returns @node
             @request = stub 'request', :key => "does not matter", :node => @name, :options => {}
         end
 
@@ -143,6 +168,7 @@ describe Puppet::Resource::Catalog::Compiler do
             @request = stub 'request', :options => {}
 
             @facts = stub 'facts', :save => nil
+            Facter.stubs(:value).returns "something"
         end
 
         it "should do nothing if no facts are provided" do
@@ -227,6 +253,7 @@ describe Puppet::Resource::Catalog::Compiler do
 
     describe "when filtering resources" do
         before :each do
+            Facter.stubs(:value)
             @compiler = Puppet::Resource::Catalog::Compiler.new
             @catalog = stub_everything 'catalog'
             @catalog.stubs(:respond_to?).with(:filter).returns(true)
diff --git a/spec/unit/parser/interpreter.rb b/spec/unit/parser/interpreter.rb
index 182f3da..56ad71a 100755
--- a/spec/unit/parser/interpreter.rb
+++ b/spec/unit/parser/interpreter.rb
@@ -13,7 +13,7 @@ describe Puppet::Parser::Interpreter do
             Puppet.settings.stubs(:uninterpolated_value).with(:code, :myenv).returns("mycode")
             @parser.expects(:string=).with("mycode")
             @parser.expects(:parse)
-            Puppet::Parser::Parser.expects(:new).with(:environment => :myenv).returns(@parser)
+            Puppet::Parser::Parser.expects(:new).with(:myenv).returns(@parser)
             @interp.send(:create_parser, :myenv).object_id.should equal(@parser.object_id)
         end
 
@@ -22,12 +22,12 @@ describe Puppet::Parser::Interpreter do
             Puppet.settings.stubs(:value).with(:manifest, :myenv).returns("/my/file")
             @parser.expects(:parse)
             @parser.expects(:file=).with("/my/file")
-            Puppet::Parser::Parser.expects(:new).with(:environment => :myenv).returns(@parser)
+            Puppet::Parser::Parser.expects(:new).with(:myenv).returns(@parser)
             @interp.send(:create_parser, :myenv).should equal(@parser)
         end
 
         it "should return nothing when new parsers fail" do
-            Puppet::Parser::Parser.expects(:new).with(:environment => :myenv).raises(ArgumentError)
+            Puppet::Parser::Parser.expects(:new).with(:myenv).raises(ArgumentError)
             proc { @interp.send(:create_parser, :myenv) }.should raise_error(Puppet::Error)
         end
 
@@ -40,13 +40,13 @@ describe Puppet::Parser::Interpreter do
             Puppet.settings.parse
 
             parser1 = mock 'parser1'
-            Puppet::Parser::Parser.expects(:new).with(:environment => :env1).returns(parser1)
+            Puppet::Parser::Parser.expects(:new).with(:env1).returns(parser1)
             parser1.expects(:file=).with("/t/env1.pp")
             parser1.expects(:parse)
             @interp.send(:create_parser, :env1)
 
             parser2 = mock 'parser2'
-            Puppet::Parser::Parser.expects(:new).with(:environment => :env2).returns(parser2)
+            Puppet::Parser::Parser.expects(:new).with(:env2).returns(parser2)
             parser2.expects(:file=).with("/t/env2.pp")
             parser2.expects(:parse)
             @interp.send(:create_parser, :env2)
@@ -133,15 +133,4 @@ describe Puppet::Parser::Interpreter do
             @interp.compile(@node).should == "my_resource_catalog"
         end
     end
-
-    describe "when returning catalog version" do
-        it "should ask the appropriate parser for the catalog version" do
-            node = mock 'node'
-            node.expects(:environment).returns(:myenv)
-            parser = mock 'parser'
-            parser.expects(:version).returns(:myvers)
-            @interp.expects(:parser).with(:myenv).returns(parser)
-            @interp.configuration_version(node).should equal(:myvers)
-        end
-    end
 end

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list