Refactoring a small part of the interface between the configuration handler and the interpreter.

This commit is contained in:
Luke Kanies 2007-08-15 16:56:05 -05:00
Родитель 901ae687eb
Коммит 297dabb637
2 изменённых файлов: 30 добавлений и 6 удалений

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

@ -55,12 +55,14 @@ class Puppet::Network::Handler
# Return the configuration version.
def version(client = nil, clientip = nil)
v = interpreter.configuration_version
# If we can find the node, then store the fact that the node
# has checked in.
if node = node_handler.search(client)
update_node_freshness(client)
if node = node_handler.details(client)
update_node_check(node)
end
interpreter.parsedate
return v
end
private
@ -187,7 +189,7 @@ class Puppet::Network::Handler
# Mark that the node has checked in. FIXME this needs to be moved into
# the SimpleNode class, or somewhere that's got abstract backends.
def update_node_freshness(node)
def update_node_check(node)
if Puppet.features.rails? and Puppet[:storeconfigs]
Puppet::Rails.connect

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

@ -143,7 +143,7 @@ class TestHandlerConfiguration < Test::Unit::TestCase
end
# Check that we're storing the node freshness into the rails db. Hackilicious.
def test_update_node_freshness
def test_update_node_check
# This is stupid.
config = Config.new
node = Object.new
@ -160,8 +160,30 @@ class TestHandlerConfiguration < Test::Unit::TestCase
Puppet::Rails.expects(:connect)
Puppet::Rails::Host.expects(:find_or_create_by_name).with(:hostname).returns(host)
config.send(:update_node_freshness, node)
config.send(:update_node_check, node)
end
def test_version
# First try the case where we can't look up the node
config = Config.new
handler = Object.new
handler.expects(:details).with(:client).returns(false)
config.expects(:node_handler).returns(handler)
interp = Object.new
interp.expects(:configuration_version).returns(:version)
config.expects(:interpreter).returns(interp)
assert_equal(:version, config.version(:client), "Did not return configuration version")
# And then when we find the node.
config = Config.new
node = Object.new
handler = Object.new
handler.expects(:details).with(:client).returns(node)
config.expects(:update_node_check).with(node)
config.expects(:node_handler).returns(handler)
interp = Object.new
interp.expects(:configuration_version).returns(:version)
config.expects(:interpreter).returns(interp)
assert_equal(:version, config.version(:client), "Did not return configuration version")
end
end