summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorJesse Wolfe <jes5199@gmail.com>2010-06-22 14:01:31 -0700
committertest branch <puppet-dev@googlegroups.com>2010-02-17 06:50:53 -0800
commita7884b4707355ed2f4e052e7d760cce773442df1 (patch)
tree773814976710c5b0e81bcd6b8454615b8c6e1810 /lib/puppet
parentc75b2199ca57f4101f1a731fec603f69349c0d5a (diff)
downloadpuppet-a7884b4707355ed2f4e052e7d760cce773442df1.tar.gz
puppet-a7884b4707355ed2f4e052e7d760cce773442df1.tar.xz
puppet-a7884b4707355ed2f4e052e7d760cce773442df1.zip
[#3409] environment is not checked when nodes are in ldap
This is the patch as submitted by vichharaks ros <vichharaks.ros@hp.com>
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/indirector/node/ldap.rb62
1 files changed, 51 insertions, 11 deletions
diff --git a/lib/puppet/indirector/node/ldap.rb b/lib/puppet/indirector/node/ldap.rb
index 954bc8d78..2bb156e80 100644
--- a/lib/puppet/indirector/node/ldap.rb
+++ b/lib/puppet/indirector/node/ldap.rb
@@ -19,9 +19,30 @@ class Puppet::Node::Ldap < Puppet::Indirector::Ldap
# LAK:NOTE Unfortunately, the ldap support is too stupid to throw anything
# but LDAP::ResultError, even on bad connections, so we are rough handed
# with our error handling.
- def name2hash(name)
+ def name2hash(name,name_env,node_type)
info = nil
- ldapsearch(search_filter(name)) { |entry| info = entry2hash(entry) }
+ ldapsearch(search_filter(name)) {
+ |entry| info = entry2hash(entry)
+ if info[:environment]
+ if name_env == info[:environment]
+ return info
+ else
+ info = nil
+ end
+ else
+ info_env = "production"
+ if name_env == info[:environment]
+ return info
+ else
+ info = nil
+ end
+ end
+ }
+ if node_type == 'parent'
+ raise Puppet::Error.new("Could not find node '%s' with environment '%s'" % [name,name_env])
+ end
+
+ info = name2hash('default',name_env,'parent')
return info
end
@@ -35,9 +56,18 @@ class Puppet::Node::Ldap < Puppet::Indirector::Ldap
node = nil
names.each do |name|
- next unless info = name2hash(name)
+ facts = Puppet::Node::Facts.find(name)
+ if facts.values["environment"]
+ name_env = facts.values["environment"]
+ else
+ name_env = "production"
+ end
+ info = name2hash(name,name_env,'child')
+ next if info == nil
- break if node = info2node(request.key, info)
+ if info
+ break if node = info2node(request.key, info)
+ end
end
return node
@@ -173,19 +203,29 @@ class Puppet::Node::Ldap < Puppet::Indirector::Ldap
# Find information for our parent and merge it into the current info.
def find_and_merge_parent(parent, information)
- unless parent_info = name2hash(parent)
- raise Puppet::Error.new("Could not find parent node '%s'" % parent)
+
+ if information[:environment]
+ name_env = information[:environment]
+ else
+ name_env = production
end
- information[:classes] += parent_info[:classes]
- parent_info[:parameters].each do |param, value|
+
+ parent_info = name2hash(parent,name_env,'parent')
+ if parent_info
+ 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.
information[:parameters][param] = value unless information[:parameters].include?(param)
- end
+ end
- information[:environment] ||= parent_info[:environment]
+ information[:environment] ||= parent_info[:environment]
+ parent_info[:parent]
+ else
+ raise Puppet::Error.new("Could not find parent node '%s'" % parent)
+ nil
+ end
- parent_info[:parent]
end
# Take a name and a hash, and return a node instance.