diff options
author | Luke Kanies <luke@madstop.com> | 2007-10-05 11:46:35 -0500 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2007-10-05 11:46:35 -0500 |
commit | 9c58c476c2ffcf9613f14e5881b1177f01d413a7 (patch) | |
tree | 8791274ce754f486f039ba942e3a5d3d9939df3e | |
parent | d35cd947c82ba9da8ec798100a3c710c34492521 (diff) | |
download | puppet-9c58c476c2ffcf9613f14e5881b1177f01d413a7.tar.gz puppet-9c58c476c2ffcf9613f14e5881b1177f01d413a7.tar.xz puppet-9c58c476c2ffcf9613f14e5881b1177f01d413a7.zip |
Adding a :code setting for specifying code to run
instead of a manifest, and removing all of the ambiguity
around whether an interpreter gets its own file specified
or uses the central setting.
Most of the changes are around fixing existing tests to use this new system.
-rwxr-xr-x | bin/puppet | 2 | ||||
-rw-r--r-- | lib/puppet/defaults.rb | 3 | ||||
-rw-r--r-- | lib/puppet/indirector/code/configuration.rb | 16 | ||||
-rw-r--r-- | lib/puppet/node.rb | 2 | ||||
-rw-r--r-- | lib/puppet/parser/interpreter.rb | 19 | ||||
-rwxr-xr-x | spec/unit/indirector/code/configuration.rb | 16 | ||||
-rwxr-xr-x | spec/unit/node/configuration.rb | 4 | ||||
-rwxr-xr-x | spec/unit/parser/interpreter.rb | 44 | ||||
-rwxr-xr-x | test/language/functions.rb | 10 | ||||
-rwxr-xr-x | test/language/parser.rb | 3 | ||||
-rwxr-xr-x | test/language/scope.rb | 11 | ||||
-rw-r--r-- | test/lib/puppettest/parsertesting.rb | 15 |
12 files changed, 35 insertions, 110 deletions
diff --git a/bin/puppet b/bin/puppet index a5aa030ac..b004111c9 100755 --- a/bin/puppet +++ b/bin/puppet @@ -166,7 +166,7 @@ Puppet.genmanifest # Set our code or file to use. if options[:code] or ARGV.length == 0 - Puppet::Node::Configuration.code = options[:code] || STDIN.read + Puppet[:code] = options[:code] || STDIN.read else Puppet[:manifest] = ARGV.shift end diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb index 6ea4eef4c..ce1411b62 100644 --- a/lib/puppet/defaults.rb +++ b/lib/puppet/defaults.rb @@ -292,6 +292,9 @@ module Puppet "Where puppetmasterd looks for its manifests."], :manifest => ["$manifestdir/site.pp", "The entry-point manifest for puppetmasterd."], + :code => ["", "Code to parse directly. This is essentially only used + by ``puppet`, and should only be set if you're writing your own Puppet + executable"], :masterlog => { :default => "$logdir/puppetmaster.log", :owner => "$user", :group => "$group", diff --git a/lib/puppet/indirector/code/configuration.rb b/lib/puppet/indirector/code/configuration.rb index b3a4c67dd..0d06cb029 100644 --- a/lib/puppet/indirector/code/configuration.rb +++ b/lib/puppet/indirector/code/configuration.rb @@ -91,21 +91,7 @@ class Puppet::Indirector::Code::Configuration < Puppet::Indirector::Code # Create our interpreter object. def create_interpreter - args = {} - - # Allow specification of a code snippet or of a file - if self.code - args[:Code] = self.code - end - - # LAK:FIXME This needs to be handled somehow. - #if options.include?(:UseNodes) - # args[:UseNodes] = options[:UseNodes] - #elsif @local - # args[:UseNodes] = false - #end - - return Puppet::Parser::Interpreter.new(args) + return Puppet::Parser::Interpreter.new end # Turn our host name into a node object. diff --git a/lib/puppet/node.rb b/lib/puppet/node.rb index d71bd507e..9758c895c 100644 --- a/lib/puppet/node.rb +++ b/lib/puppet/node.rb @@ -9,7 +9,7 @@ class Puppet::Node extend Puppet::Indirector # Use the node source as the indirection terminus. - indirects :node + indirects :node, :terminus_class => :null # Add the node-searching methods. This is what people will actually # interact with that will find the node with the list of names or diff --git a/lib/puppet/parser/interpreter.rb b/lib/puppet/parser/interpreter.rb index 8c727118c..87513cb18 100644 --- a/lib/puppet/parser/interpreter.rb +++ b/lib/puppet/parser/interpreter.rb @@ -14,7 +14,6 @@ class Puppet::Parser::Interpreter include Puppet::Util attr_accessor :usenodes - attr_accessor :code, :file include Puppet::Util::Errors @@ -30,17 +29,7 @@ class Puppet::Parser::Interpreter end # create our interpreter - def initialize(options = {}) - if @code = options[:Code] - elsif @file = options[:Manifest] - end - - if options.include?(:UseNodes) - @usenodes = options[:UseNodes] - else - @usenodes = true - end - + def initialize # The class won't always be defined during testing. if Puppet[:storeconfigs] if Puppet.features.rails? @@ -59,10 +48,8 @@ class Puppet::Parser::Interpreter def create_parser(environment) begin parser = Puppet::Parser::Parser.new(:environment => environment) - if self.code - parser.string = self.code - elsif self.file - parser.file = self.file + if code = Puppet.settings.value(:code, environment) and code != "" + parser.string = code else file = Puppet.settings.value(:manifest, environment) parser.file = file diff --git a/spec/unit/indirector/code/configuration.rb b/spec/unit/indirector/code/configuration.rb index 5e2aedc7b..bc54f4e1c 100755 --- a/spec/unit/indirector/code/configuration.rb +++ b/spec/unit/indirector/code/configuration.rb @@ -53,28 +53,16 @@ describe Puppet::Indirector::Code::Configuration, " when creating the interprete it "should not create the interpreter until it is asked for the first time" do interp = mock 'interp' - Puppet::Parser::Interpreter.expects(:new).with({}).returns(interp) + Puppet::Parser::Interpreter.expects(:new).with().returns(interp) @compiler.interpreter.should equal(interp) end it "should use the same interpreter for all compiles" do interp = mock 'interp' - Puppet::Parser::Interpreter.expects(:new).with({}).returns(interp) + Puppet::Parser::Interpreter.expects(:new).with().returns(interp) @compiler.interpreter.should equal(interp) @compiler.interpreter.should equal(interp) end - - it "should provide a mechanism for setting the code to pass to the interpreter" do - @compiler.should respond_to(:code=) - end - - it "should pass any specified code on to the interpreter when it is being initialized" do - code = "some code" - @compiler.code = code - interp = mock 'interp' - Puppet::Parser::Interpreter.expects(:new).with(:Code => code).returns(interp) - @compiler.send(:interpreter).should equal(interp) - end end describe Puppet::Indirector::Code::Configuration, " when finding nodes" do diff --git a/spec/unit/node/configuration.rb b/spec/unit/node/configuration.rb index c94f31380..153d0b182 100755 --- a/spec/unit/node/configuration.rb +++ b/spec/unit/node/configuration.rb @@ -52,6 +52,10 @@ describe Puppet::Node::Configuration, " when extracting" do end end +describe Puppet::Node::Configuration, " when extracting RAL resources" do + it "should support an extraction method for converting a parser configuration into a RAL configuration" +end + describe Puppet::Node::Configuration, " when extracting transobjects" do def mkscope diff --git a/spec/unit/parser/interpreter.rb b/spec/unit/parser/interpreter.rb index fbf3bdb23..782b30cc7 100755 --- a/spec/unit/parser/interpreter.rb +++ b/spec/unit/parser/interpreter.rb @@ -2,55 +2,25 @@ require File.dirname(__FILE__) + '/../../spec_helper' -describe Puppet::Parser::Interpreter, " when initializing" do - it "should default to neither code nor file" do - interp = Puppet::Parser::Interpreter.new - interp.code.should be_nil - interp.file.should be_nil - end - - it "should set the code to parse" do - interp = Puppet::Parser::Interpreter.new :Code => :code - interp.code.should equal(:code) - end - - it "should set the file to parse" do - interp = Puppet::Parser::Interpreter.new :Manifest => :file - interp.file.should equal(:file) - end - - it "should set code and ignore manifest when both are present" do - interp = Puppet::Parser::Interpreter.new :Code => :code, :Manifest => :file - interp.code.should equal(:code) - interp.file.should be_nil - end -end - describe Puppet::Parser::Interpreter, " when creating parser instances" do before do @interp = Puppet::Parser::Interpreter.new @parser = mock('parser') end - it "should create a parser with code passed in at initialization time" do - @interp.code = :some_code - @parser.expects(:string=).with(:some_code) + it "should create a parser with code if there is code defined in the :code setting" do + Puppet.settings.stubs(:value).with(:code, :myenv).returns("mycode") + @parser.expects(:string=).with("mycode") @parser.expects(:parse) Puppet::Parser::Parser.expects(:new).with(:environment => :myenv).returns(@parser) @interp.send(:create_parser, :myenv).object_id.should equal(@parser.object_id) end - it "should create a parser with a file passed in at initialization time" do - @interp.file = :a_file - @parser.expects(:file=).with(:a_file) - @parser.expects(:parse) - Puppet::Parser::Parser.expects(:new).with(:environment => :myenv).returns(@parser) - @interp.send(:create_parser, :myenv).should equal(@parser) - end - - it "should create a parser with the main manifest when passed neither code nor file" do + it "should create a parser with the main manifest when the code setting is an empty string" do + Puppet.settings.stubs(:value).with(:code, :myenv).returns("") + Puppet.settings.stubs(:value).with(:manifest, :myenv).returns("/my/file") @parser.expects(:parse) - @parser.expects(:file=).with(Puppet[:manifest]) + @parser.expects(:file=).with("/my/file") Puppet::Parser::Parser.expects(:new).with(:environment => :myenv).returns(@parser) @interp.send(:create_parser, :myenv).should equal(@parser) end diff --git a/test/language/functions.rb b/test/language/functions.rb index 2a392e01a..db107fd36 100755 --- a/test/language/functions.rb +++ b/test/language/functions.rb @@ -202,16 +202,10 @@ class TestLangFunctions < Test::Unit::TestCase f.puts "original text" end - manifest = tempfile() file = tempfile() - File.open(manifest, "w") do |f| - f.puts %{file { "#{file}": content => template("#{template}") }} - end - interp = Puppet::Parser::Interpreter.new( - :Manifest => manifest, - :UseNodes => false - ) + Puppet[:code] = %{file { "#{file}": content => template("#{template}") }} + interp = Puppet::Parser::Interpreter.new node = mknode node.stubs(:environment).returns("yay") diff --git a/test/language/parser.rb b/test/language/parser.rb index 9109686cb..1e7adb45e 100755 --- a/test/language/parser.rb +++ b/test/language/parser.rb @@ -618,7 +618,8 @@ file { "/tmp/yayness": f.puts "file { '#{file}': ensure => present }" end - interp = mkinterp :Manifest => top, :UseNodes => false + Puppet[:manifest] = top + interp = Puppet::Parser::Interpreter.new code = nil assert_nothing_raised do diff --git a/test/language/scope.rb b/test/language/scope.rb index b4db5ef40..22734a5fb 100755 --- a/test/language/scope.rb +++ b/test/language/scope.rb @@ -399,24 +399,17 @@ class TestScope < Test::Unit::TestCase Puppet::Rails.init sleep 1 children = [] - file = tempfile() - File.open(file, "w") { |f| - f.puts " + Puppet[:code] = " class yay { @@host { myhost: ip => \"192.168.0.2\" } } include yay @@host { puppet: ip => \"192.168.0.3\" } Host <<||>>" - } interp = nil assert_nothing_raised { - interp = Puppet::Parser::Interpreter.new( - :Manifest => file, - :UseNodes => false, - :ForkSave => false - ) + interp = Puppet::Parser::Interpreter.new } config = nil diff --git a/test/lib/puppettest/parsertesting.rb b/test/lib/puppettest/parsertesting.rb index 62fa7213e..3e3ce6cb9 100644 --- a/test/lib/puppettest/parsertesting.rb +++ b/test/lib/puppettest/parsertesting.rb @@ -54,10 +54,8 @@ module PuppetTest::ParserTesting Puppet::Node.new(name) end - def mkinterp(args = {}) - args[:Code] ||= "" unless args.include?(:Manifest) - args[:Local] ||= true - Puppet::Parser::Interpreter.new(args) + def mkinterp + Puppet::Parser::Interpreter.new end def mkparser @@ -301,11 +299,10 @@ module PuppetTest::ParserTesting # This assumes no nodes def assert_creates(manifest, *files) interp = nil + oldmanifest = Puppet[:manifest] + Puppet[:manifest] = manifest assert_nothing_raised { - interp = Puppet::Parser::Interpreter.new( - :Manifest => manifest, - :UseNodes => false - ) + interp = Puppet::Parser::Interpreter.new } trans = nil @@ -323,6 +320,8 @@ module PuppetTest::ParserTesting files.each do |file| assert(FileTest.exists?(file), "Did not create %s" % file) end + ensure + Puppet[:manifest] = oldmanifest end def mk_transobject(file = "/etc/passwd") |