summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-09-22 01:24:04 -0500
committerLuke Kanies <luke@madstop.com>2007-09-22 01:24:04 -0500
commita66699596452f88d2bc467af4cff3f9a1aec3d1e (patch)
treef24e797d1709e27374692f079980167d5f136daf /lib
parentebe7290bf0c9119e268c9037c33da515e527aa5b (diff)
downloadpuppet-a66699596452f88d2bc467af4cff3f9a1aec3d1e.tar.gz
puppet-a66699596452f88d2bc467af4cff3f9a1aec3d1e.tar.xz
puppet-a66699596452f88d2bc467af4cff3f9a1aec3d1e.zip
Adding the last tests for the ldap node terminus. I managed
to forget the tests around the main find() method.
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/indirector/ldap.rb4
-rw-r--r--lib/puppet/indirector/ldap/node.rb62
2 files changed, 53 insertions, 13 deletions
diff --git a/lib/puppet/indirector/ldap.rb b/lib/puppet/indirector/ldap.rb
index 63848d10a..fb883def6 100644
--- a/lib/puppet/indirector/ldap.rb
+++ b/lib/puppet/indirector/ldap.rb
@@ -5,7 +5,7 @@ class Puppet::Indirector::Ldap < Puppet::Indirector::Terminus
def find(name)
# We have to use 'yield' here because the LDAP::Entry objects
# get destroyed outside the scope of the search, strangely.
- ldapsearch(name) { |entry| return process(entry) }
+ ldapsearch(name) { |entry| return process(name, entry) }
# Return nil if we haven't found something.
return nil
@@ -13,7 +13,7 @@ class Puppet::Indirector::Ldap < Puppet::Indirector::Terminus
# Process the found entry. We assume that we don't just want the
# ldap object.
- def process(entry)
+ def process(name, entry)
raise Puppet::DevError, "The 'process' method has not been overridden for the LDAP terminus for %s" % self.name
end
diff --git a/lib/puppet/indirector/ldap/node.rb b/lib/puppet/indirector/ldap/node.rb
index 187c74b94..6f35b575c 100644
--- a/lib/puppet/indirector/ldap/node.rb
+++ b/lib/puppet/indirector/ldap/node.rb
@@ -10,23 +10,34 @@ class Puppet::Indirector::Ldap::Node < Puppet::Indirector::Ldap
# Look for our node in ldap.
def find(name)
- unless ary = ldapsearch(name)
- return nil
- end
- parent, classes, parameters = ary
+ return nil unless information = super
+ node = Puppet::Node.new(name)
+ parent_info = nil
+ parent = information[:parent]
+ parents = [name]
while parent
- parent, tmpclasses, tmpparams = ldapsearch(parent)
- classes += tmpclasses if tmpclasses
- tmpparams.each do |param, value|
+ if parents.include?(parent)
+ raise ArgumentError, "Found loop in LDAP node parents; %s appears twice" % parent
+ end
+ parents << parent
+ ldapsearch(parent) do |entry|
+ parent_info = process(parent, entry)
+ end
+ information[:classes] += parent_info[:classes]
+ parent_info[:parameters].each do |param, value|
# Specifically test for whether it's set, so false values are handled
# correctly.
- parameters[param] = value unless parameters.include?(param)
+ information[:parameters][param] = value unless information[:parameters].include?(param)
end
+
+ parent = parent_info[:parent]
end
- node = Puppet::Node.new(name, :classes => classes, :source => "ldap", :parameters => parameters)
+ node.classes = information[:classes].uniq unless information[:classes].empty?
+ node.parameters = information[:parameters] unless information[:parameters].empty?
node.fact_merge
+
return node
end
@@ -41,8 +52,37 @@ class Puppet::Indirector::Ldap::Node < Puppet::Indirector::Ldap
# Process the found entry. We assume that we don't just want the
# ldap object.
- def process(entry)
- raise Puppet::DevError, "The 'process' method has not been overridden for the LDAP terminus for %s" % self.name
+ def process(name, entry)
+ result = {}
+ if pattr = parent_attribute
+ if values = entry.vals(pattr)
+ if values.length > 1
+ raise Puppet::Error,
+ "Node %s has more than one parent: %s" % [name, values.inspect]
+ end
+ unless values.empty?
+ result[:parent] = values.shift
+ end
+ end
+ end
+
+ result[:classes] = []
+ class_attributes.each { |attr|
+ if values = entry.vals(attr)
+ values.each do |v| result[:classes] << v end
+ end
+ }
+
+ result[:parameters] = entry.to_hash.inject({}) do |hash, ary|
+ if ary[1].length == 1
+ hash[ary[0]] = ary[1].shift
+ else
+ hash[ary[0]] = ary[1]
+ end
+ hash
+ end
+
+ return result
end
# Default to all attributes.