diff options
author | Luke Kanies <luke@madstop.com> | 2008-06-14 14:37:33 -0500 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2008-06-15 13:31:47 -0500 |
commit | 51e1ba8c02f1bd9085ef15138c4828accbb29dec (patch) | |
tree | 2c8aeaeb8ad6f9a398329b3a5fa5b896397fdda7 | |
parent | fb4e84321d47c5ebe31d257e1f7e0037a9ff34c1 (diff) | |
download | puppet-51e1ba8c02f1bd9085ef15138c4828accbb29dec.tar.gz puppet-51e1ba8c02f1bd9085ef15138c4828accbb29dec.tar.xz puppet-51e1ba8c02f1bd9085ef15138c4828accbb29dec.zip |
The LDAP Node terminus now searches for the fqdn, short name, and default.
This provides something like the multiple name
scenario previously used by the parser but now implemented
in each terminus.
-rw-r--r-- | lib/puppet/indirector/ldap.rb | 12 | ||||
-rw-r--r-- | lib/puppet/indirector/node/ldap.rb | 34 | ||||
-rwxr-xr-x | spec/unit/indirector/node/ldap.rb | 20 |
3 files changed, 51 insertions, 15 deletions
diff --git a/lib/puppet/indirector/ldap.rb b/lib/puppet/indirector/ldap.rb index 07ad38933..695d38a95 100644 --- a/lib/puppet/indirector/ldap.rb +++ b/lib/puppet/indirector/ldap.rb @@ -1,14 +1,16 @@ require 'puppet/indirector/terminus' class Puppet::Indirector::Ldap < Puppet::Indirector::Terminus - # Perform our ldap search and process the result. - def find(request) + # We split this apart so it's easy to call multiple times with different names. + def entry2hash(name) # We have to use 'yield' here because the LDAP::Entry objects # get destroyed outside the scope of the search, strangely. - ldapsearch(request.key) { |entry| return process(request.key, entry) } + ldapsearch(name) { |entry| return process(name, entry) } + end - # Return nil if we haven't found something. - return nil + # Perform our ldap search and process the result. + def find(request) + return entry2hash(request.key) || nil end # Process the found entry. We assume that we don't just want the diff --git a/lib/puppet/indirector/node/ldap.rb b/lib/puppet/indirector/node/ldap.rb index 5cf560e86..4ed053eff 100644 --- a/lib/puppet/indirector/node/ldap.rb +++ b/lib/puppet/indirector/node/ldap.rb @@ -3,7 +3,9 @@ require 'puppet/indirector/ldap' class Puppet::Node::Ldap < Puppet::Indirector::Ldap desc "Search in LDAP for node configuration information. See - the `LdapNodes`:trac: page for more information." + the `LdapNodes`:trac: page for more information. This will first + search for whatever the certificate name is, then (if that name + contains a '.') for the short name, then 'default'." # The attributes that Puppet class information is stored in. def class_attributes @@ -13,7 +15,17 @@ class Puppet::Node::Ldap < Puppet::Indirector::Ldap # Look for our node in ldap. def find(request) - return nil unless information = super + names = [request.key] + if request.key.include?(".") # we assume it's an fqdn + names << request.key.sub(/\..+/, '') + end + names << "default" + + information = nil + names.each do |name| + break if information = entry2hash(name) + end + return nil unless information name = request.key @@ -129,17 +141,21 @@ class Puppet::Node::Ldap < Puppet::Indirector::Ldap parent = find_and_merge_parent(parent, information) end - information[:stacked].each do |value| - param = value.split('=', 2) - information[:stacked_parameters][param[0]] = param[1] + if information[:stacked] + information[:stacked].each do |value| + param = value.split('=', 2) + information[:stacked_parameters][param[0]] = param[1] + end end - information[:stacked_parameters].each do |param, value| - information[:parameters][param] = value unless information[:parameters].include?(param) + if information[:stacked_parameters] + information[:stacked_parameters].each do |param, value| + information[:parameters][param] = value unless information[:parameters].include?(param) + end end - node.classes = information[:classes].uniq unless information[:classes].empty? - node.parameters = information[:parameters] unless information[:parameters].empty? + node.classes = information[:classes].uniq unless information[:classes].nil? or information[:classes].empty? + node.parameters = information[:parameters] unless information[:parameters].nil? or information[:parameters].empty? node.environment = information[:environment] if information[:environment] node.fact_merge end diff --git a/spec/unit/indirector/node/ldap.rb b/spec/unit/indirector/node/ldap.rb index 4508ad9c0..24b2dd759 100755 --- a/spec/unit/indirector/node/ldap.rb +++ b/spec/unit/indirector/node/ldap.rb @@ -21,7 +21,7 @@ describe Puppet::Node::Ldap do @searcher.stubs(:search_base).returns(:yay) @searcher.stubs(:search_filter).returns(:filter) - @name = "mynode" + @name = "mynode.domain.com" @node = stub 'node', :name => @name @node.stubs(:fact_merge) Puppet::Node.stubs(:new).with(@name).returns(@node) @@ -29,6 +29,24 @@ describe Puppet::Node::Ldap do @request = stub 'request', :key => @name end + it "should search first for the provided key" do + @searcher.expects(:entry2hash).with("mynode.domain.com").returns({}) + @searcher.find(@request) + end + + it "should search for the short version of the provided key if the key looks like a hostname and no results are found for the key itself" do + @searcher.expects(:entry2hash).with("mynode.domain.com").returns(nil) + @searcher.expects(:entry2hash).with("mynode").returns({}) + @searcher.find(@request) + end + + it "should search for default information if no information can be found for the key" do + @searcher.expects(:entry2hash).with("mynode.domain.com").returns(nil) + @searcher.expects(:entry2hash).with("mynode").returns(nil) + @searcher.expects(:entry2hash).with("default").returns({}) + @searcher.find(@request) + end + it "should return nil if no results are found in ldap" do @connection.stubs(:search) @searcher.find(@request).should be_nil |