public
Description: Server automation framework and application
Homepage: http://reductivelabs.com/trac/puppet/
Clone URL: git://github.com/lak/puppet.git
Click here to lend your support to: puppet and make a donation at www.pledgie.com !
Added the ability to add arbitrary attributes to ldap.

This fixes #1179.
wrobel (author)
Wed May 14 23:27:07 -0700 2008
lak (committer)
Thu May 15 08:39:12 -0700 2008
commit  158d3df805ebe28f52db5ced928dda7129aeec1b
tree    f0a76a332e9c392a686f8a841b44063ec93408e9
parent  e972a3bcf0c95eaf7797d15734257d189ff8c3bf
...
17
18
19
 
 
 
 
 
20
21
22
 
...
17
18
19
20
21
22
23
24
25
26
 
27
0
@@ -17,6 +17,11 @@ attributetype ( 1.1.3.11 NAME 'environment'
0
   EQUALITY caseIgnoreIA5Match
0
   SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )
0
 
0
+attributetype ( 1.1.3.12 NAME 'puppetvar'
0
+  DESC 'A variable setting for puppet'
0
+  EQUALITY caseIgnoreIA5Match
0
+  SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )
0
+
0
 objectclass ( 1.1.1.2 NAME 'puppetClient' SUP top AUXILIARY
0
   DESC 'Puppet Client objectclass'
0
-  MAY ( puppetclass $ parentnode $ environment ))
0
+  MAY ( puppetclass $ parentnode $ environment $ puppetvar ))
...
622
623
624
 
 
 
 
625
626
627
...
622
623
624
625
626
627
628
629
630
631
0
@@ -622,6 +622,10 @@ module Puppet
0
         :ldapclassattrs => ["puppetclass",
0
             "The LDAP attributes to use to define Puppet classes.  Values
0
             should be comma-separated."],
0
+        :ldapstackedattrs => ["puppetvar",
0
+            "The LDAP attributes that should be stacked to arrays by adding
0
+            the values in all hierarchy elements of the tree.  Values
0
+            should be comma-separated."],
0
         :ldapattrs => ["all",
0
             "The LDAP attributes to include when querying LDAP for nodes.  All
0
             returned attributes are set as variables in the top-level scope.
...
19
20
21
 
 
22
23
24
...
34
35
36
 
 
 
 
37
38
39
...
45
46
47
 
 
 
 
 
 
 
 
 
48
49
50
...
62
63
64
 
 
 
 
 
 
65
66
67
...
85
86
87
 
 
 
 
 
 
 
 
88
89
90
...
19
20
21
22
23
24
25
26
...
36
37
38
39
40
41
42
43
44
45
...
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
...
77
78
79
80
81
82
83
84
85
86
87
88
...
106
107
108
109
110
111
112
113
114
115
116
117
118
119
0
@@ -19,6 +19,8 @@ class Puppet::Node::Ldap < Puppet::Indirector::Ldap
0
 
0
         node = Puppet::Node.new(name)
0
 
0
+        information[:stacked_parameters] = {}
0
+
0
         parent_info = nil
0
         parent = information[:parent]
0
         parents = [name]
0
@@ -34,6 +36,10 @@ class Puppet::Node::Ldap < Puppet::Indirector::Ldap
0
                 raise Puppet::Error.new("Could not find parent node '%s'" % parent)
0
             end
0
             information[:classes] += parent_info[:classes]
0
+            parent_info[:stacked].each do |value|
0
+                param = value.split('=', 2)
0
+                information[:stacked_parameters][param[0]] = param[1]
0
+            end
0
             parent_info[:parameters].each do |param, value|
0
                 # Specifically test for whether it's set, so false values are handled
0
                 # correctly.
0
@@ -45,6 +51,15 @@ class Puppet::Node::Ldap < Puppet::Indirector::Ldap
0
             parent = parent_info[:parent]
0
         end
0
 
0
+        information[:stacked].each do |value|
0
+            param = value.split('=', 2)
0
+            information[:stacked_parameters][param[0]] = param[1]
0
+        end
0
+
0
+        information[:stacked_parameters].each do |param, value|
0
+            information[:parameters][param] = value unless information[:parameters].include?(param)
0
+        end
0
+
0
         node.classes = information[:classes].uniq unless information[:classes].empty?
0
         node.parameters = information[:parameters] unless information[:parameters].empty?
0
         node.environment = information[:environment] if information[:environment]
0
@@ -62,6 +77,12 @@ class Puppet::Node::Ldap < Puppet::Indirector::Ldap
0
         end
0
     end
0
 
0
+    # The attributes that Puppet will stack as array over the full
0
+    # hierarchy.
0
+    def stacked_attributes
0
+        Puppet[:ldapstackedattrs].split(/\s*,\s*/)
0
+    end
0
+
0
     # Process the found entry.  We assume that we don't just want the
0
     # ldap object.
0
     def process(name, entry)
0
@@ -85,6 +106,14 @@ class Puppet::Node::Ldap < Puppet::Indirector::Ldap
0
             end
0
         }
0
 
0
+        result[:stacked] = []
0
+        stacked_attributes.each { |attr|
0
+            if values = entry.vals(attr)
0
+                result[:stacked] = result[:stacked] + values
0
+            end
0
+        }
0
+        
0
+
0
         result[:parameters] = entry.to_hash.inject({}) do |hash, ary|
0
             if ary[1].length == 1
0
                 hash[ary[0]] = ary[1].shift
...
17
18
19
 
20
21
22
...
195
196
197
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
198
199
200
...
17
18
19
20
21
22
23
...
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
0
@@ -17,6 +17,7 @@ describe Puppet::Node::Ldap do
0
             @searcher.stubs(:connection).returns(@connection)
0
             @searcher.stubs(:class_attributes).returns([])
0
             @searcher.stubs(:parent_attribute).returns(nil)
0
+            @searcher.stubs(:stacked_attributes).returns([])
0
             @searcher.stubs(:search_base).returns(:yay)
0
             @searcher.stubs(:search_filter).returns(:filter)
0
 
0
@@ -195,6 +196,96 @@ describe Puppet::Node::Ldap do
0
                 proc { @searcher.find(@request) }.should raise_error(ArgumentError)
0
             end
0
         end
0
+
0
+        describe "and a puppet variable is specified" do
0
+            before do
0
+                @searcher.stubs(:stacked_attributes).returns(['puppetvar'])
0
+            end
0
+
0
+            it "should add the variable to the node parameters" do
0
+                @entry.stubs(:vals).with("puppetvar").returns(%w{one=two})
0
+                @entry.stubs(:to_hash).returns({})
0
+                @node.expects(:parameters=).with("one" => "two")
0
+                @searcher.find(@request)
0
+            end
0
+
0
+            it "should not overwrite node parameters specified as ldap object attribute" do
0
+                @entry.stubs(:vals).with("puppetvar").returns(%w{one=two})
0
+                @entry.stubs(:to_hash).returns("one" => "three")
0
+                @node.expects(:parameters=).with("one" => "three")
0
+                @searcher.find(@request)
0
+            end
0
+
0
+            it "should set entries without an equal sign to nil" do
0
+                @entry.stubs(:vals).with("puppetvar").returns(%w{one})
0
+                @entry.stubs(:to_hash).returns({})
0
+                @node.expects(:parameters=).with("one" => nil)
0
+                @searcher.find(@request)
0
+            end
0
+
0
+            it "should ignore empty entries" do
0
+                @entry.stubs(:vals).with("puppetvar").returns(%w{})
0
+                @entry.stubs(:to_hash).returns({})
0
+                @searcher.find(@request)
0
+            end
0
+        end
0
+        describe "and a puppet variable as well as a parent node are specified" do
0
+            before do
0
+                @parent = mock 'parent'
0
+
0
+                @searcher.meta_def(:search_filter) do |name|
0
+                    return name
0
+                end
0
+                @connection.stubs(:search).with { |*args| args[2] == @name              }.yields(@entry)
0
+                @connection.stubs(:search).with { |*args| args[2] == 'parent'           }.yields(@parent)
0
+
0
+                @searcher.stubs(:stacked_attributes).returns(['puppetvar'])
0
+                @searcher.stubs(:parent_attribute).returns(:parent)
0
+            end
0
+
0
+            it "should add parent node variables to the child node parameters" do
0
+                @parent.stubs(:to_hash).returns({})
0
+                @parent.stubs(:vals).with("puppetvar").returns(%w{one=two})
0
+                @parent.stubs(:vals).with(:parent).returns(nil)
0
+
0
+                @entry.stubs(:to_hash).returns({})
0
+                @entry.stubs(:vals).with("puppetvar").returns(%w{})
0
+                @entry.stubs(:vals).with(:parent).returns(%w{parent})
0
+
0
+                @node.expects(:parameters=).with("one" => "two")
0
+
0
+                @searcher.find(@request)
0
+            end
0
+
0
+            it "should overwrite parent node variables with child node parameters" do
0
+                @parent.stubs(:to_hash).returns({})
0
+                @parent.stubs(:vals).with("puppetvar").returns(%w{one=two})
0
+                @parent.stubs(:vals).with(:parent).returns(nil)
0
+
0
+                @entry.stubs(:to_hash).returns({})
0
+                @entry.stubs(:vals).with("puppetvar").returns(%w{one=three})
0
+                @entry.stubs(:vals).with(:parent).returns(%w{parent})
0
+
0
+                @node.expects(:parameters=).with("one" => "three")
0
+
0
+                @searcher.find(@request)
0
+            end
0
+
0
+            it "should not overwrite parent node parameters specified as ldap object attribute" do
0
+                @parent.stubs(:to_hash).returns("one" => "three")
0
+                @parent.stubs(:vals).with("puppetvar").returns(%w{})
0
+                @parent.stubs(:vals).with(:parent).returns(nil)
0
+
0
+                @entry.stubs(:vals).with("puppetvar").returns(%w{one=two})
0
+                @entry.stubs(:to_hash).returns({})
0
+                @entry.stubs(:vals).with(:parent).returns(%w{parent})
0
+
0
+                @node.expects(:parameters=).with("one" => "three")
0
+
0
+                @searcher.find(@request)
0
+            end
0
+
0
+        end
0
     end
0
 end
0
 

Comments