diff options
author | Luke Kanies <luke@reductivelabs.com> | 2010-01-06 16:19:09 -0800 |
---|---|---|
committer | test branch <puppet-dev@googlegroups.com> | 2010-02-17 06:50:53 -0800 |
commit | 804105d925b526bcf209910172bc14bdeafaf4e7 (patch) | |
tree | c83327108bd8aa40d041a0ea239bc4f21519d8b4 | |
parent | 26b272b218b02115ce66edbc6dd4cffd231105ab (diff) | |
download | puppet-804105d925b526bcf209910172bc14bdeafaf4e7.tar.gz puppet-804105d925b526bcf209910172bc14bdeafaf4e7.tar.xz puppet-804105d925b526bcf209910172bc14bdeafaf4e7.zip |
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@reductivelabs.com>
-rw-r--r-- | lib/puppet/indirector/catalog/compiler.rb | 6 | ||||
-rw-r--r-- | lib/puppet/parser/interpreter.rb | 16 | ||||
-rwxr-xr-x | spec/unit/indirector/catalog/compiler.rb | 27 | ||||
-rwxr-xr-x | spec/unit/parser/interpreter.rb | 21 |
4 files changed, 39 insertions, 31 deletions
diff --git a/lib/puppet/indirector/catalog/compiler.rb b/lib/puppet/indirector/catalog/compiler.rb index 4f6b0602a..ecb1c74e1 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 bc0ae4fdf..1b158209d 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 84f5cdc56..e2c18de57 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 182f3dab3..56ad71a4a 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 |