diff options
-rw-r--r-- | lib/puppet/dsl.rb | 4 | ||||
-rw-r--r-- | lib/puppet/network/handler/configuration.rb | 5 | ||||
-rw-r--r-- | lib/puppet/util/config.rb | 2 | ||||
-rwxr-xr-x | spec/unit/util/config.rb | 13 | ||||
-rwxr-xr-x | test/util/config.rb | 23 |
5 files changed, 31 insertions, 16 deletions
diff --git a/lib/puppet/dsl.rb b/lib/puppet/dsl.rb index bd0fcbf96..793578bca 100644 --- a/lib/puppet/dsl.rb +++ b/lib/puppet/dsl.rb @@ -260,8 +260,8 @@ module Puppet @node = Puppet::Node.new(Facter.value(:hostname)) @node.parameters = Facter.to_hash @interp = Puppet::Parser::Interpreter.new :Code => "" - @config = Puppet::Parser::Configuration.new(@node, @interp.parser) - @scope = @config.topscope + @compile = Puppet::Parser::Compile.new(@node, @interp.send(:parser, Puppet[:environment])) + @scope = @compile.topscope end @scope end diff --git a/lib/puppet/network/handler/configuration.rb b/lib/puppet/network/handler/configuration.rb index b2b16d022..1dbb16370 100644 --- a/lib/puppet/network/handler/configuration.rb +++ b/lib/puppet/network/handler/configuration.rb @@ -22,6 +22,11 @@ class Puppet::Network::Handler # Compile a node's configuration. def configuration(key, client = nil, clientip = nil) + # If we want to use the cert name as our key + if Puppet[:node_name] == 'cert' and client + key = client + end + # Note that this is reasonable, because either their node source should actually # know about the node, or they should be using the ``none`` node source, which # will always return data. diff --git a/lib/puppet/util/config.rb b/lib/puppet/util/config.rb index fb1c01d56..f5cc4bcce 100644 --- a/lib/puppet/util/config.rb +++ b/lib/puppet/util/config.rb @@ -175,7 +175,7 @@ class Puppet::Util::Config # Handle a command-line argument. def handlearg(opt, value = nil) - clear(true) + @cache.clear value = munge_value(value) if value str = opt.sub(/^--/,'') bool = true diff --git a/spec/unit/util/config.rb b/spec/unit/util/config.rb index 0b3b65c28..348a54893 100755 --- a/spec/unit/util/config.rb +++ b/spec/unit/util/config.rb @@ -80,6 +80,19 @@ describe Puppet::Util::Config, " when setting values" do @config[:bool].should == true end + it "should clear the cache when setting getopt-specific values" do + @config.setdefaults :mysection, :one => ["whah", "yay"], :two => ["$one yay", "bah"] + @config[:two].should == "whah yay" + @config.handlearg("--one", "else") + @config[:two].should == "else yay" + end + + it "should not clear other values when setting getopt-specific values" do + @config[:myval] = "yay" + @config.handlearg("--no-bool") + @config[:myval].should == "yay" + end + it "should call passed blocks when values are set" do values = [] @config.setdefaults(:section, :hooker => {:default => "yay", :desc => "boo", :hook => lambda { |v| values << v }}) diff --git a/test/util/config.rb b/test/util/config.rb index 2e9105010..137c55d10 100755 --- a/test/util/config.rb +++ b/test/util/config.rb @@ -932,11 +932,10 @@ yay = /a/path config.setdefaults(:mysection, :clichange => ["clichange", "yay"]) config.setdefaults(:mysection, :filechange => ["filechange", "yay"]) - file = tempfile() - # Set one parameter in the file - File.open(file, "w") { |f| - f.puts %{[main]\nfilechange = filevalue} - } + config.stubs(:read_file).returns(%{[main]\nfilechange = filevalue\n}) + file = mock 'file' + file.stubs(:changed?).returns(true) + assert_nothing_raised { config.parse(file) } @@ -948,16 +947,14 @@ yay = /a/path # And leave the other unset assert_equal("default", config[:default]) - assert_equal("filevalue", config[:filechange]) + assert_equal("filevalue", config[:filechange], "Did not get value from file") assert_equal("clivalue", config[:clichange]) - # Now rewrite the file - File.open(file, "w") { |f| - f.puts %{[main]\nfilechange = newvalue} - } - - cfile = config.file - cfile.send("tstamp=".intern, Time.now - 50) + # Now reparse + config.stubs(:read_file).returns(%{[main]\nfilechange = newvalue\n}) + file = mock 'file' + file.stubs(:changed?).returns(true) + config.parse(file) # And check all of the values assert_equal("default", config[:default]) |