Making a couple of small bugfixes in the configuration subsystem

This commit is contained in:
Luke Kanies 2007-08-27 17:38:39 -05:00
Родитель 1de5ae0da0
Коммит 2625eb1db7
5 изменённых файлов: 31 добавлений и 16 удалений

Просмотреть файл

@ -260,8 +260,8 @@ module Puppet
@node = Puppet::Node.new(Facter.value(:hostname)) @node = Puppet::Node.new(Facter.value(:hostname))
@node.parameters = Facter.to_hash @node.parameters = Facter.to_hash
@interp = Puppet::Parser::Interpreter.new :Code => "" @interp = Puppet::Parser::Interpreter.new :Code => ""
@config = Puppet::Parser::Configuration.new(@node, @interp.parser) @compile = Puppet::Parser::Compile.new(@node, @interp.send(:parser, Puppet[:environment]))
@scope = @config.topscope @scope = @compile.topscope
end end
@scope @scope
end end

Просмотреть файл

@ -22,6 +22,11 @@ class Puppet::Network::Handler
# Compile a node's configuration. # Compile a node's configuration.
def configuration(key, client = nil, clientip = nil) 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 # 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 # know about the node, or they should be using the ``none`` node source, which
# will always return data. # will always return data.

Просмотреть файл

@ -175,7 +175,7 @@ class Puppet::Util::Config
# Handle a command-line argument. # Handle a command-line argument.
def handlearg(opt, value = nil) def handlearg(opt, value = nil)
clear(true) @cache.clear
value = munge_value(value) if value value = munge_value(value) if value
str = opt.sub(/^--/,'') str = opt.sub(/^--/,'')
bool = true bool = true

Просмотреть файл

@ -80,6 +80,19 @@ describe Puppet::Util::Config, " when setting values" do
@config[:bool].should == true @config[:bool].should == true
end 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 it "should call passed blocks when values are set" do
values = [] values = []
@config.setdefaults(:section, :hooker => {:default => "yay", :desc => "boo", :hook => lambda { |v| values << v }}) @config.setdefaults(:section, :hooker => {:default => "yay", :desc => "boo", :hook => lambda { |v| values << v }})

Просмотреть файл

@ -932,11 +932,10 @@ yay = /a/path
config.setdefaults(:mysection, :clichange => ["clichange", "yay"]) config.setdefaults(:mysection, :clichange => ["clichange", "yay"])
config.setdefaults(:mysection, :filechange => ["filechange", "yay"]) config.setdefaults(:mysection, :filechange => ["filechange", "yay"])
file = tempfile() config.stubs(:read_file).returns(%{[main]\nfilechange = filevalue\n})
# Set one parameter in the file file = mock 'file'
File.open(file, "w") { |f| file.stubs(:changed?).returns(true)
f.puts %{[main]\nfilechange = filevalue}
}
assert_nothing_raised { assert_nothing_raised {
config.parse(file) config.parse(file)
} }
@ -948,16 +947,14 @@ yay = /a/path
# And leave the other unset # And leave the other unset
assert_equal("default", config[:default]) 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]) assert_equal("clivalue", config[:clichange])
# Now rewrite the file # Now reparse
File.open(file, "w") { |f| config.stubs(:read_file).returns(%{[main]\nfilechange = newvalue\n})
f.puts %{[main]\nfilechange = newvalue} file = mock 'file'
} file.stubs(:changed?).returns(true)
config.parse(file)
cfile = config.file
cfile.send("tstamp=".intern, Time.now - 50)
# And check all of the values # And check all of the values
assert_equal("default", config[:default]) assert_equal("default", config[:default])