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