diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-06-20 18:31:54 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-06-20 18:31:54 +0000 |
| commit | d812840a89092ccd04c2ad81a3bd80a6cc2f7882 (patch) | |
| tree | 20a0002e2e48f061a45663dc7557cc3c2badf707 | |
| parent | 46824cd8167e2d07ba1f1bdb0cc24789b3a565b1 (diff) | |
| download | puppet-d812840a89092ccd04c2ad81a3bd80a6cc2f7882.tar.gz puppet-d812840a89092ccd04c2ad81a3bd80a6cc2f7882.tar.xz puppet-d812840a89092ccd04c2ad81a3bd80a6cc2f7882.zip | |
Fixing #182. Added a retry section to try reconnecting to ldap. Only one reconnect is attempted in a given search, and LDAP produces bad enough error messages that we reconnect regardless of the error thrown.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1305 980ebf18-57e1-0310-9a29-db15c13687c0
| -rw-r--r-- | lib/puppet/parser/interpreter.rb | 10 | ||||
| -rwxr-xr-x | test/language/interpreter.rb | 43 |
2 files changed, 52 insertions, 1 deletions
diff --git a/lib/puppet/parser/interpreter.rb b/lib/puppet/parser/interpreter.rb index 04074d695..b383f7a90 100644 --- a/lib/puppet/parser/interpreter.rb +++ b/lib/puppet/parser/interpreter.rb @@ -214,6 +214,7 @@ module Puppet classes = [] found = false + count = 0 begin # We're always doing a sub here; oh well. @ldap.search(Puppet[:ldapbase], 2, filter, sattrs) do |entry| @@ -238,7 +239,14 @@ module Puppet } end rescue => detail - raise Puppet::Error, "LDAP Search failed: %s" % detail + if count == 0 + # Try reconnecting to ldap + @ldap = nil + setup_ldap() + retry + else + raise Puppet::Error, "LDAP Search failed: %s" % detail + end end classes.flatten! diff --git a/test/language/interpreter.rb b/test/language/interpreter.rb index 4ce35d48e..8dc3f0b83 100755 --- a/test/language/interpreter.rb +++ b/test/language/interpreter.rb @@ -18,6 +18,7 @@ require 'puppettest' class TestInterpreter < Test::Unit::TestCase include TestPuppet + include ServerTest AST = Puppet::Parser::AST # create a simple manifest that uses nodes to create a file @@ -207,6 +208,48 @@ class TestInterpreter < Test::Unit::TestCase assert(FileTest.exists?(cfile), "Did not make %s" % cfile) } end + + if Process.uid == 0 and Facter["hostname"].value == "culain" + def test_ldapreconnect + Puppet[:ldapbase] = "ou=hosts, dc=madstop, dc=com" + Puppet[:ldapnodes] = true + + interp = nil + assert_nothing_raised { + interp = Puppet::Parser::Interpreter.new( + :Manifest => mktestmanifest() + ) + } + hostname = "culain.madstop.com" + + # look for our host + assert_nothing_raised { + parent, classes = interp.nodesearch_ldap(hostname) + } + + # Now restart ldap + system("/etc/init.d/slapd restart 2>/dev/null >/dev/null") + sleep(1) + + # and look again + assert_nothing_raised { + parent, classes = interp.nodesearch_ldap(hostname) + } + + # Now stop ldap + system("/etc/init.d/slapd stop 2>/dev/null >/dev/null") + cleanup do + system("/etc/init.d/slapd start 2>/dev/null >/dev/null") + end + + # And make sure we actually fail here + assert_raise(Puppet::Error) { + parent, classes = interp.nodesearch_ldap(hostname) + } + end + else + $stderr.puts "Run as root for ldap reconnect tests" + end end else $stderr.puts "Not in madstop.com; skipping ldap tests" |
