summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-10-05 20:47:20 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-10-05 20:47:20 +0000
commitb8920939ade4d9956a7f3b2ba3a2c77a3f788c58 (patch)
treec0a78d5c5610c94968d8ca3b92715e1bbc7a7f21
parent06a7d345bef7a41cb6320e14a1dd9476505fd65f (diff)
downloadpuppet-b8920939ade4d9956a7f3b2ba3a2c77a3f788c58.tar.gz
puppet-b8920939ade4d9956a7f3b2ba3a2c77a3f788c58.tar.xz
puppet-b8920939ade4d9956a7f3b2ba3a2c77a3f788c58.zip
Fixing weird case where the default node is in one node source and the real node is in a different one
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1734 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r--lib/puppet/parser/interpreter.rb22
-rwxr-xr-xtest/language/interpreter.rb35
2 files changed, 49 insertions, 8 deletions
diff --git a/lib/puppet/parser/interpreter.rb b/lib/puppet/parser/interpreter.rb
index 60e449db6..787fd8838 100644
--- a/lib/puppet/parser/interpreter.rb
+++ b/lib/puppet/parser/interpreter.rb
@@ -307,7 +307,7 @@ class Puppet::Parser::Interpreter
end
# By default, we only search for parsed nodes.
- @nodesources = [:code]
+ @nodesources = []
if Puppet[:ldapnodes]
# Nodes in the file override nodes in ldap.
@@ -327,6 +327,10 @@ class Puppet::Parser::Interpreter
end
end
+ unless @nodesources.include?(:code)
+ @nodesources << :code
+ end
+
@setup = false
initparsevars()
@@ -584,18 +588,20 @@ class Puppet::Parser::Interpreter
nsource = obj.file || source
Puppet.info "Found %s in %s" % [node, nsource]
return obj
- else
- # Look for a default node.
- if defobj = self.send(method, "default")
- Puppet.info "Found default node for %s in %s" %
- [node, source]
- return defobj
- end
end
end
end
end
+ # If they made it this far, we haven't found anything, so look for a
+ # default node.
+ unless nodes.include?("default")
+ if defobj = self.nodesearch("default")
+ Puppet.notice "Using default node for %s" % [nodes[0]]
+ return defobj
+ end
+ end
+
return nil
end
diff --git a/test/language/interpreter.rb b/test/language/interpreter.rb
index 755a07aa8..6f5b9cc68 100755
--- a/test/language/interpreter.rb
+++ b/test/language/interpreter.rb
@@ -249,13 +249,41 @@ class TestInterpreter < Test::Unit::TestCase
$stderr.puts "Not in madstop.com; skipping ldap tests"
end
+ # Test that node info and default node info in different sources isn't
+ # bad.
+ def test_multiple_nodesources
+
+ # Create another node source
+ Puppet::Parser::Interpreter.send(:define_method, :nodesearch_multi) do |*names|
+ if names[0] == "default"
+ gennode("default", {:facts => {}})
+ else
+ nil
+ end
+ end
+
+ interp = mkinterp :NodeSources => [:multi, :code]
+
+ interp.newnode(["node"])
+
+ obj = nil
+ assert_nothing_raised do
+ obj = interp.nodesearch("node")
+ end
+ assert(obj, "Did not find node")
+ assert_equal("node", obj.fqname)
+ end
+
# Make sure searchnode behaves as we expect.
def test_nodesearch
+ # We use two sources here to catch a weird bug where the default
+ # node is used if the host isn't in the first source.
interp = mkinterp
# Make some nodes
names = %w{node1 node2 node2.domain.com}
interp.newnode names
+ interp.newnode %w{default}
nodes = {}
# Make sure we can find them all, using the direct method
@@ -271,6 +299,13 @@ class TestInterpreter < Test::Unit::TestCase
assert(node, "Could not find #{name} via nodesearch")
end
+ # Make sure we find the default node when we search for nonexistent nodes
+ assert_nothing_raised do
+ default = interp.nodesearch("nosuchnode")
+ assert(default, "Did not find default node")
+ assert_equal("default", default.fqname)
+ end
+
# Now make sure the longest match always wins
node = interp.nodesearch(*%w{node2 node2.domain.com})