summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-07-18 14:00:33 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-07-18 14:00:33 +0000
commitaba3d6522f83f86c4d04c864becee4e2bc31d95c (patch)
treefcf0a3a3727e280d5e76f6a6ca4c19d2d0686ef0
parent01c880869215288a269b1f607a7c3b4707a47abf (diff)
downloadpuppet-aba3d6522f83f86c4d04c864becee4e2bc31d95c.tar.gz
puppet-aba3d6522f83f86c4d04c864becee4e2bc31d95c.tar.xz
puppet-aba3d6522f83f86c4d04c864becee4e2bc31d95c.zip
Fixing bug in scope/interpreter where nodes found in ldap must have parent nodes. The problem was that the the scope was using the presence of a parent node to determine whether a node was found. Instead I added a flag in the arguments to "Scope#evaluate" to mark nodes as found.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1401 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r--lib/puppet/parser/interpreter.rb4
-rw-r--r--lib/puppet/parser/scope.rb2
-rwxr-xr-xtest/language/interpreter.rb56
3 files changed, 46 insertions, 16 deletions
diff --git a/lib/puppet/parser/interpreter.rb b/lib/puppet/parser/interpreter.rb
index 7a595872e..012d7a82a 100644
--- a/lib/puppet/parser/interpreter.rb
+++ b/lib/puppet/parser/interpreter.rb
@@ -312,6 +312,10 @@ module Puppet
args[:classes] += nodeclasses if nodeclasses
args[:parentnode] = parent if parent
+
+ if nodeclasses or parent
+ args[:searched] = true
+ end
end
begin
diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb
index 317776055..8d5937217 100644
--- a/lib/puppet/parser/scope.rb
+++ b/lib/puppet/parser/scope.rb
@@ -349,7 +349,7 @@ module Puppet::Parser
# If they've provided a name or a parent, we assume they're looking
# for nodes.
- if hash.include? :parentnode
+ if hash[:searched]
# Specifying a parent node takes precedence, because it is assumed
# that this node was found in a remote repository like ldap.
gennode(hash)
diff --git a/test/language/interpreter.rb b/test/language/interpreter.rb
index ba1067998..c22bb73ba 100755
--- a/test/language/interpreter.rb
+++ b/test/language/interpreter.rb
@@ -184,6 +184,16 @@ class TestInterpreter < Test::Unit::TestCase
assert_equal(dparent, parent, "Default parent node did not match")
assert_equal(dclasses, classes, "Default parent class list did not match")
+ # Look for a host we know doesn't have a parent
+ npparent, npclasses = ldaphost("noparent")
+ assert_nothing_raised {
+ #parent, classes = interp.nodesearch_ldap("noparent")
+ parent, classes = interp.nodesearch("noparent")
+ }
+
+ assert_equal(npparent, parent, "Parent node did not match")
+ assert_equal(npclasses, classes, "Class list did not match")
+
# Now look for our normal host
assert_nothing_raised {
parent, classes = interp.nodesearch_ldap(hostname)
@@ -259,35 +269,51 @@ class TestInterpreter < Test::Unit::TestCase
def test_nodesearch
# First create a fake nodesearch algorithm
i = 0
+ bucket = []
Puppet::Parser::Interpreter.send(:define_method, "nodesearch_fake") do |node|
return nil, nil if node == "default"
- i += 1
- case i
- when 1: return nil, nil
- when 2: return "#{node}parent", nil
- when 3: return nil, ["#{node}class"]
- when 4: return nil, ["#{node}class", "nother#{node}"]
- when 5: return "other#{node}parent", ["#{node}class", "nother#{node}"]
- else
- puts "huh: %s" % i
- end
+
+ return bucket[0], bucket[1]
end
+ text = %{
+node nodeparent {}
+node othernodeparent {}
+class nodeclass {}
+class nothernode {}
+}
+ manifest = tempfile()
+ File.open(manifest, "w") do |f| f.puts text end
interp = nil
assert_nothing_raised {
interp = Puppet::Parser::Interpreter.new(
- :Manifest => mktestmanifest(),
+ :Manifest => manifest,
:NodeSources => [:fake]
)
}
# Make sure it behaves correctly for all forms
- 5.times do |j|
+ [[nil, nil],
+ ["nodeparent", nil],
+ [nil, ["nodeclass"]],
+ [nil, ["nodeclass", "nothernode"]],
+ ["othernodeparent", ["nodeclass", "nothernode"]],].each do |ary|
+ # Set the return values
+ bucket = ary
+
+ # Look them back up
parent, classes = interp.nodesearch("mynode")
# Basically, just make sure that if we have either or both,
# we get a result back.
- unless i == 1
- assert(parent || classes,
- "Did not get node info on pass #{i}")
+ assert_equal(ary[0], parent,
+ "Parent is not %s" % parent)
+ assert_equal(ary[1], classes,
+ "Parent is not %s" % parent)
+
+ next if ary == [nil, nil]
+ # Now make sure we actually get the configuration. This will throw
+ # an exception if we don't.
+ assert_nothing_raised do
+ interp.run("mynode", {})
end
end
end