clc-cheffish 0.8.clc → 0.8.3.clc
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/chef/provider/chef_data_bag_item.rb +1 -1
- data/lib/chef/provider/chef_mirror.rb +29 -3
- data/lib/chef/resource/chef_mirror.rb +2 -1
- data/lib/cheffish.rb +1 -1
- data/lib/cheffish/chef_provider_base.rb +23 -11
- data/lib/cheffish/recipe_dsl.rb +11 -3
- data/lib/cheffish/version.rb +1 -1
- data/spec/integration/chef_client_spec.rb +1 -1
- data/spec/integration/chef_container_spec.rb +1 -1
- data/spec/integration/chef_group_spec.rb +1 -1
- data/spec/integration/chef_mirror_spec.rb +333 -58
- data/spec/integration/chef_node_spec.rb +658 -56
- data/spec/integration/chef_organization_spec.rb +1 -1
- data/spec/integration/chef_user_spec.rb +1 -1
- data/spec/support/spec_support.rb +6 -0
- metadata +2 -2
@@ -5,7 +5,7 @@ require 'chef/provider/chef_node'
|
|
5
5
|
describe Chef::Resource::ChefNode do
|
6
6
|
extend SpecSupport
|
7
7
|
|
8
|
-
|
8
|
+
when_the_chef_12_server 'is in multi-org mode' do
|
9
9
|
organization 'foo'
|
10
10
|
|
11
11
|
before :each do
|
@@ -109,88 +109,690 @@ describe Chef::Resource::ChefNode do
|
|
109
109
|
end
|
110
110
|
end
|
111
111
|
|
112
|
-
|
113
|
-
node
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
112
|
+
describe '#complete' do
|
113
|
+
context 'when the Chef server has a node named "blah" with everything in it' do
|
114
|
+
node 'blah', {
|
115
|
+
'chef_environment' => 'blah',
|
116
|
+
'run_list' => [ 'recipe[bjork]' ],
|
117
|
+
'normal' => { 'foo' => 'bar', 'tags' => [ 'a', 'b' ] },
|
118
|
+
'default' => { 'foo2' => 'bar2' },
|
119
|
+
'automatic' => { 'foo3' => 'bar3' },
|
120
|
+
'override' => { 'foo4' => 'bar4' }
|
121
|
+
}
|
122
|
+
|
123
|
+
it 'chef_node with no attributes modifies nothing' do
|
124
|
+
run_recipe do
|
125
|
+
chef_node 'blah'
|
126
|
+
end
|
127
|
+
expect(get('nodes/blah')).to include(
|
128
|
+
'name' => 'blah',
|
129
|
+
'chef_environment' => 'blah',
|
130
|
+
'run_list' => [ 'recipe[bjork]' ],
|
131
|
+
'normal' => { 'foo' => 'bar', 'tags' => [ 'a', 'b' ] },
|
132
|
+
'default' => { 'foo2' => 'bar2' },
|
133
|
+
'automatic' => { 'foo3' => 'bar3' },
|
134
|
+
'override' => { 'foo4' => 'bar4' }
|
135
|
+
)
|
136
|
+
end
|
121
137
|
|
122
|
-
|
123
|
-
|
124
|
-
|
138
|
+
it 'chef_node with complete true removes everything except default, automatic and override' do
|
139
|
+
run_recipe do
|
140
|
+
chef_node 'blah' do
|
141
|
+
complete true
|
142
|
+
end
|
143
|
+
end
|
144
|
+
expect(get('nodes/blah')).to include(
|
145
|
+
'name' => 'blah',
|
146
|
+
'chef_environment' => '_default',
|
147
|
+
'run_list' => [ ],
|
148
|
+
'normal' => { 'tags' => [ 'a', 'b' ] },
|
149
|
+
'default' => { 'foo2' => 'bar2' },
|
150
|
+
'automatic' => { 'foo3' => 'bar3' },
|
151
|
+
'override' => { 'foo4' => 'bar4' }
|
152
|
+
)
|
125
153
|
end
|
126
154
|
|
127
|
-
it '
|
128
|
-
|
155
|
+
it 'chef_node with complete true sets the given attributes' do
|
156
|
+
run_recipe do
|
157
|
+
chef_node 'blah' do
|
158
|
+
chef_environment 'x'
|
159
|
+
run_list [ 'recipe[y]' ]
|
160
|
+
attributes 'a' => 'b'
|
161
|
+
tags 'c', 'd'
|
162
|
+
complete true
|
163
|
+
end
|
164
|
+
end
|
165
|
+
expect(get('nodes/blah')).to include(
|
166
|
+
'name' => 'blah',
|
167
|
+
'chef_environment' => 'x',
|
168
|
+
'run_list' => [ 'recipe[y]' ],
|
169
|
+
'normal' => { 'a' => 'b', 'tags' => [ 'c', 'd' ] },
|
170
|
+
'default' => { 'foo2' => 'bar2' },
|
171
|
+
'automatic' => { 'foo3' => 'bar3' },
|
172
|
+
'override' => { 'foo4' => 'bar4' }
|
173
|
+
)
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'chef_node with complete true and partial attributes sets the given attributes' do
|
177
|
+
run_recipe do
|
178
|
+
chef_node 'blah' do
|
179
|
+
chef_environment 'x'
|
180
|
+
recipe 'y'
|
181
|
+
attribute 'a', 'b'
|
182
|
+
tags 'c', 'd'
|
183
|
+
complete true
|
184
|
+
end
|
185
|
+
end
|
186
|
+
expect(get('nodes/blah')).to include(
|
187
|
+
'name' => 'blah',
|
188
|
+
'chef_environment' => 'x',
|
189
|
+
'run_list' => [ 'recipe[y]' ],
|
190
|
+
'normal' => { 'a' => 'b', 'tags' => [ 'c', 'd' ] },
|
191
|
+
'default' => { 'foo2' => 'bar2' },
|
192
|
+
'automatic' => { 'foo3' => 'bar3' },
|
193
|
+
'override' => { 'foo4' => 'bar4' }
|
194
|
+
)
|
129
195
|
end
|
130
196
|
end
|
197
|
+
end
|
131
198
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
199
|
+
describe '#attributes' do
|
200
|
+
context 'with a node with normal attributes a => b and c => { d => e }' do
|
201
|
+
node 'blah', {
|
202
|
+
'normal' => {
|
203
|
+
'a' => 'b',
|
204
|
+
'c' => { 'd' => 'e' },
|
205
|
+
'tags' => [ 'a', 'b' ]
|
206
|
+
},
|
207
|
+
'automatic' => {
|
208
|
+
'x' => 'y'
|
209
|
+
},
|
210
|
+
'chef_environment' => 'desert'
|
211
|
+
}
|
212
|
+
|
213
|
+
it 'chef_node with attributes {} removes all normal attributes but leaves tags, automatic and environment alone' do
|
214
|
+
run_recipe do
|
215
|
+
chef_node 'blah' do
|
216
|
+
attributes({})
|
217
|
+
end
|
136
218
|
end
|
219
|
+
expect(chef_run).to have_updated('chef_node[blah]', :create)
|
220
|
+
expect(get('nodes/blah')).to include(
|
221
|
+
'normal' => { 'tags' => [ 'a', 'b' ] },
|
222
|
+
'automatic' => { 'x' => 'y' },
|
223
|
+
'chef_environment' => 'desert'
|
224
|
+
)
|
137
225
|
end
|
138
226
|
|
139
|
-
it '
|
140
|
-
|
141
|
-
|
142
|
-
|
227
|
+
it 'chef_node with attributes { c => d } replaces normal but not tags/automatic/environment' do
|
228
|
+
run_recipe do
|
229
|
+
chef_node 'blah' do
|
230
|
+
attributes 'c' => 'd'
|
231
|
+
end
|
232
|
+
end
|
233
|
+
expect(chef_run).to have_updated('chef_node[blah]', :create)
|
234
|
+
expect(get('nodes/blah')).to include(
|
235
|
+
'normal' => { 'c' => 'd', 'tags' => [ 'a', 'b' ] },
|
236
|
+
'automatic' => { 'x' => 'y' },
|
237
|
+
'chef_environment' => 'desert'
|
238
|
+
)
|
143
239
|
end
|
144
|
-
end
|
145
240
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
241
|
+
it 'chef_node with attributes { c => f => g, y => z } replaces normal but not tags/automatic/environment' do
|
242
|
+
run_recipe do
|
243
|
+
chef_node 'blah' do
|
244
|
+
attributes 'c' => { 'f' => 'g' }, 'y' => 'z'
|
245
|
+
end
|
150
246
|
end
|
247
|
+
expect(chef_run).to have_updated('chef_node[blah]', :create)
|
248
|
+
expect(get('nodes/blah')).to include(
|
249
|
+
'normal' => { 'c' => { 'f' => 'g' }, 'y' => 'z', 'tags' => [ 'a', 'b' ] },
|
250
|
+
'automatic' => { 'x' => 'y' },
|
251
|
+
'chef_environment' => 'desert'
|
252
|
+
)
|
151
253
|
end
|
152
254
|
|
153
|
-
it '
|
154
|
-
|
155
|
-
|
156
|
-
|
255
|
+
it 'chef_node with attributes { tags => [ "x" ] } replaces normal and tags but not automatic/environment' do
|
256
|
+
run_recipe do
|
257
|
+
chef_node 'blah' do
|
258
|
+
attributes 'tags' => [ 'x' ]
|
259
|
+
end
|
260
|
+
end
|
261
|
+
expect(chef_run).to have_updated('chef_node[blah]', :create)
|
262
|
+
expect(get('nodes/blah')).to include(
|
263
|
+
'normal' => { 'tags' => [ 'x' ] },
|
264
|
+
'automatic' => { 'x' => 'y' },
|
265
|
+
'chef_environment' => 'desert'
|
266
|
+
)
|
267
|
+
end
|
268
|
+
|
269
|
+
it 'chef_node with tags "x" and attributes { "tags" => [ "y" ] } sets tags to "x"' do
|
270
|
+
run_recipe do
|
271
|
+
chef_node 'blah' do
|
272
|
+
tags 'x'
|
273
|
+
attributes 'tags' => [ 'y' ]
|
274
|
+
end
|
275
|
+
end
|
276
|
+
expect(chef_run).to have_updated('chef_node[blah]', :create)
|
277
|
+
expect(get('nodes/blah')).to include(
|
278
|
+
'normal' => {
|
279
|
+
'tags' => [ 'x' ]
|
280
|
+
},
|
281
|
+
'automatic' => { 'x' => 'y' },
|
282
|
+
'chef_environment' => 'desert'
|
283
|
+
)
|
157
284
|
end
|
158
285
|
end
|
286
|
+
end
|
159
287
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
288
|
+
describe '#attribute' do
|
289
|
+
context 'with a node with normal attributes a => b and c => { d => e }' do
|
290
|
+
node 'blah', {
|
291
|
+
'normal' => {
|
292
|
+
'a' => 'b',
|
293
|
+
'c' => { 'd' => 'e' },
|
294
|
+
'tags' => [ 'a', 'b' ]
|
295
|
+
},
|
296
|
+
'automatic' => {
|
297
|
+
'x' => 'y'
|
298
|
+
},
|
299
|
+
'chef_environment' => 'desert'
|
300
|
+
}
|
301
|
+
|
302
|
+
context 'basic scenarios' do
|
303
|
+
it 'chef_node with no attributes, leaves it alone' do
|
304
|
+
run_recipe do
|
305
|
+
chef_node 'blah'
|
306
|
+
end
|
307
|
+
expect(chef_run).not_to have_updated('chef_node[blah]', :create)
|
308
|
+
expect(get('nodes/blah')).to include(
|
309
|
+
'normal' => {
|
310
|
+
'a' => 'b',
|
311
|
+
'c' => { 'd' => 'e' },
|
312
|
+
'tags' => [ 'a', 'b' ]
|
313
|
+
},
|
314
|
+
'automatic' => { 'x' => 'y' },
|
315
|
+
'chef_environment' => 'desert'
|
316
|
+
)
|
317
|
+
end
|
318
|
+
|
319
|
+
it 'chef_node with attribute d, e adds the attribute' do
|
320
|
+
run_recipe do
|
321
|
+
chef_node 'blah' do
|
322
|
+
attribute 'd', 'e'
|
323
|
+
end
|
324
|
+
end
|
325
|
+
expect(chef_run).to have_updated('chef_node[blah]', :create)
|
326
|
+
expect(get('nodes/blah')).to include(
|
327
|
+
'normal' => {
|
328
|
+
'a' => 'b',
|
329
|
+
'c' => { 'd' => 'e' },
|
330
|
+
'd' => 'e',
|
331
|
+
'tags' => [ 'a', 'b' ]
|
332
|
+
},
|
333
|
+
'automatic' => { 'x' => 'y' },
|
334
|
+
'chef_environment' => 'desert'
|
335
|
+
)
|
336
|
+
end
|
337
|
+
|
338
|
+
it 'chef_node with attribute tags, [ "x" ] replaces tags' do
|
339
|
+
run_recipe do
|
340
|
+
chef_node 'blah' do
|
341
|
+
attribute 'tags', [ 'x' ]
|
342
|
+
end
|
343
|
+
end
|
344
|
+
expect(chef_run).to have_updated('chef_node[blah]', :create)
|
345
|
+
expect(get('nodes/blah')).to include(
|
346
|
+
'normal' => {
|
347
|
+
'a' => 'b',
|
348
|
+
'c' => { 'd' => 'e' },
|
349
|
+
'tags' => [ 'x' ]
|
350
|
+
},
|
351
|
+
'automatic' => { 'x' => 'y' },
|
352
|
+
'chef_environment' => 'desert'
|
353
|
+
)
|
354
|
+
end
|
355
|
+
|
356
|
+
it 'chef_node with attribute c, x replaces the attribute' do
|
357
|
+
run_recipe do
|
358
|
+
chef_node 'blah' do
|
359
|
+
attribute 'c', 'x'
|
360
|
+
end
|
361
|
+
end
|
362
|
+
expect(chef_run).to have_updated('chef_node[blah]', :create)
|
363
|
+
expect(get('nodes/blah')).to include(
|
364
|
+
'normal' => {
|
365
|
+
'a' => 'b',
|
366
|
+
'c' => 'x',
|
367
|
+
'tags' => [ 'a', 'b' ]
|
368
|
+
},
|
369
|
+
'automatic' => { 'x' => 'y' },
|
370
|
+
'chef_environment' => 'desert'
|
371
|
+
)
|
372
|
+
end
|
373
|
+
|
374
|
+
it 'chef_node with attribute c, { d => x } replaces the attribute' do
|
375
|
+
run_recipe do
|
376
|
+
chef_node 'blah' do
|
377
|
+
attribute 'c', { 'd' => 'x' }
|
378
|
+
end
|
379
|
+
end
|
380
|
+
expect(chef_run).to have_updated('chef_node[blah]', :create)
|
381
|
+
expect(get('nodes/blah')).to include(
|
382
|
+
'normal' => {
|
383
|
+
'a' => 'b',
|
384
|
+
'c' => { 'd' => 'x' },
|
385
|
+
'tags' => [ 'a', 'b' ]
|
386
|
+
},
|
387
|
+
'automatic' => { 'x' => 'y' },
|
388
|
+
'chef_environment' => 'desert'
|
389
|
+
)
|
390
|
+
end
|
391
|
+
|
392
|
+
it 'chef_node with attribute [ c, d ], x replaces the attribute' do
|
393
|
+
run_recipe do
|
394
|
+
chef_node 'blah' do
|
395
|
+
attribute [ 'c', 'd' ], 'x'
|
396
|
+
end
|
397
|
+
end
|
398
|
+
expect(chef_run).to have_updated('chef_node[blah]', :create)
|
399
|
+
expect(get('nodes/blah')).to include(
|
400
|
+
'normal' => {
|
401
|
+
'a' => 'b',
|
402
|
+
'c' => { 'd' => 'x' },
|
403
|
+
'tags' => [ 'a', 'b' ]
|
404
|
+
},
|
405
|
+
'automatic' => { 'x' => 'y' },
|
406
|
+
'chef_environment' => 'desert'
|
407
|
+
)
|
408
|
+
end
|
409
|
+
|
410
|
+
it 'chef_node with attribute [ a, b ], x raises an error' do
|
411
|
+
expect do
|
412
|
+
run_recipe do
|
413
|
+
chef_node 'blah' do
|
414
|
+
attribute [ 'a', 'b' ], 'x'
|
415
|
+
end
|
416
|
+
end
|
417
|
+
end.to raise_error /Attempt to set \["a", "b"\] to x when \["a"\] is not a hash/
|
418
|
+
end
|
419
|
+
|
420
|
+
it 'chef_node with attribute [ a, b, c ], x raises an error' do
|
421
|
+
expect do
|
422
|
+
run_recipe do
|
423
|
+
chef_node 'blah' do
|
424
|
+
attribute [ 'a', 'b', 'c' ], 'x'
|
425
|
+
end
|
426
|
+
end
|
427
|
+
end.to raise_error /Attempt to set \["a", "b", "c"\] to x when \["a"\] is not a hash/
|
428
|
+
end
|
429
|
+
|
430
|
+
it 'chef_node with attribute [ x, y ], z adds a new attribute' do
|
431
|
+
run_recipe do
|
432
|
+
chef_node 'blah' do
|
433
|
+
attribute [ 'x', 'y' ], 'z'
|
434
|
+
end
|
435
|
+
end
|
436
|
+
expect(chef_run).to have_updated('chef_node[blah]', :create)
|
437
|
+
expect(get('nodes/blah')).to include(
|
438
|
+
'normal' => {
|
439
|
+
'a' => 'b',
|
440
|
+
'c' => { 'd' => 'e' },
|
441
|
+
'x' => { 'y' => 'z' },
|
442
|
+
'tags' => [ 'a', 'b' ]
|
443
|
+
},
|
444
|
+
'automatic' => { 'x' => 'y' },
|
445
|
+
'chef_environment' => 'desert'
|
446
|
+
)
|
447
|
+
end
|
448
|
+
|
449
|
+
it 'chef_node with attribute [], {} clears all attributes' do
|
450
|
+
run_recipe do
|
451
|
+
chef_node 'blah' do
|
452
|
+
attribute([], {})
|
453
|
+
end
|
454
|
+
end
|
455
|
+
expect(chef_run).to have_updated('chef_node[blah]', :create)
|
456
|
+
expect(get('nodes/blah')).to include(
|
457
|
+
'normal' => { },
|
458
|
+
'automatic' => { 'x' => 'y' },
|
459
|
+
'chef_environment' => 'desert'
|
460
|
+
)
|
164
461
|
end
|
165
462
|
end
|
166
463
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
464
|
+
context 'delete' do
|
465
|
+
it 'chef_node with attribute a, :delete deletes the attribute' do
|
466
|
+
run_recipe do
|
467
|
+
chef_node 'blah' do
|
468
|
+
attribute 'a', :delete
|
469
|
+
end
|
470
|
+
end
|
471
|
+
expect(chef_run).to have_updated('chef_node[blah]', :create)
|
472
|
+
expect(get('nodes/blah')).to include(
|
473
|
+
'normal' => {
|
474
|
+
'c' => { 'd' => 'e' },
|
475
|
+
'tags' => [ 'a', 'b' ]
|
476
|
+
},
|
477
|
+
'automatic' => { 'x' => 'y' },
|
478
|
+
'chef_environment' => 'desert'
|
479
|
+
)
|
480
|
+
end
|
481
|
+
|
482
|
+
it 'chef_node with attribute c, :delete deletes the attribute' do
|
483
|
+
run_recipe do
|
484
|
+
chef_node 'blah' do
|
485
|
+
attribute 'c', :delete
|
486
|
+
end
|
487
|
+
end
|
488
|
+
expect(chef_run).to have_updated('chef_node[blah]', :create)
|
489
|
+
expect(get('nodes/blah')).to include(
|
490
|
+
'normal' => {
|
491
|
+
'a' => 'b',
|
492
|
+
'tags' => [ 'a', 'b' ]
|
493
|
+
},
|
494
|
+
'automatic' => { 'x' => 'y' },
|
495
|
+
'chef_environment' => 'desert'
|
496
|
+
)
|
497
|
+
end
|
498
|
+
|
499
|
+
it 'chef_node with attribute [ c, d ], :delete deletes the attribute' do
|
500
|
+
run_recipe do
|
501
|
+
chef_node 'blah' do
|
502
|
+
attribute [ 'c', 'd' ], :delete
|
503
|
+
end
|
504
|
+
end
|
505
|
+
expect(chef_run).to have_updated('chef_node[blah]', :create)
|
506
|
+
expect(get('nodes/blah')).to include(
|
507
|
+
'normal' => {
|
508
|
+
'a' => 'b',
|
509
|
+
'c' => {},
|
510
|
+
'tags' => [ 'a', 'b' ]
|
511
|
+
},
|
512
|
+
'automatic' => { 'x' => 'y' },
|
513
|
+
'chef_environment' => 'desert'
|
514
|
+
)
|
515
|
+
end
|
516
|
+
|
517
|
+
it 'chef_node with attribute xyz, :delete does nothing' do
|
518
|
+
run_recipe do
|
519
|
+
chef_node 'blah' do
|
520
|
+
attribute 'xyz', :delete
|
521
|
+
end
|
522
|
+
end
|
523
|
+
expect(chef_run).not_to have_updated('chef_node[blah]', :create)
|
524
|
+
expect(get('nodes/blah')).to include(
|
525
|
+
'normal' => {
|
526
|
+
'a' => 'b',
|
527
|
+
'c' => { 'd' => 'e' },
|
528
|
+
'tags' => [ 'a', 'b' ]
|
529
|
+
},
|
530
|
+
'automatic' => { 'x' => 'y' },
|
531
|
+
'chef_environment' => 'desert'
|
532
|
+
)
|
533
|
+
end
|
534
|
+
|
535
|
+
it 'chef_node with attribute [ c, x ], :delete does nothing' do
|
536
|
+
run_recipe do
|
537
|
+
chef_node 'blah' do
|
538
|
+
attribute [ 'c', 'x' ], :delete
|
539
|
+
end
|
540
|
+
end
|
541
|
+
expect(chef_run).not_to have_updated('chef_node[blah]', :create)
|
542
|
+
expect(get('nodes/blah')).to include(
|
543
|
+
'normal' => {
|
544
|
+
'a' => 'b',
|
545
|
+
'c' => { 'd' => 'e' },
|
546
|
+
'tags' => [ 'a', 'b' ]
|
547
|
+
},
|
548
|
+
'automatic' => { 'x' => 'y' },
|
549
|
+
'chef_environment' => 'desert'
|
550
|
+
)
|
551
|
+
end
|
176
552
|
end
|
177
|
-
end
|
178
553
|
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
554
|
+
context 'types' do
|
555
|
+
it 'chef_node with attribute a, true sets a to true' do
|
556
|
+
run_recipe do
|
557
|
+
chef_node 'blah' do
|
558
|
+
attribute 'a', true
|
559
|
+
end
|
560
|
+
end
|
561
|
+
expect(get('nodes/blah')).to include(
|
562
|
+
'normal' => {
|
563
|
+
'a' => true,
|
564
|
+
'c' => { 'd' => 'e' },
|
565
|
+
'tags' => [ 'a', 'b' ]
|
566
|
+
},
|
567
|
+
'automatic' => { 'x' => 'y' },
|
568
|
+
'chef_environment' => 'desert'
|
569
|
+
)
|
570
|
+
end
|
571
|
+
|
572
|
+
it 'chef_node with attribute a, 1 sets a to 1' do
|
573
|
+
run_recipe do
|
574
|
+
chef_node 'blah' do
|
575
|
+
attribute 'a', 1
|
576
|
+
end
|
577
|
+
end
|
578
|
+
expect(get('nodes/blah')).to include(
|
579
|
+
'normal' => {
|
580
|
+
'a' => 1,
|
581
|
+
'c' => { 'd' => 'e' },
|
582
|
+
'tags' => [ 'a', 'b' ]
|
583
|
+
},
|
584
|
+
'automatic' => { 'x' => 'y' },
|
585
|
+
'chef_environment' => 'desert'
|
586
|
+
)
|
587
|
+
end
|
588
|
+
|
589
|
+
it 'chef_node with attribute a, "1" sets a to "1"' do
|
590
|
+
run_recipe do
|
591
|
+
chef_node 'blah' do
|
592
|
+
attribute 'a', "1"
|
593
|
+
end
|
594
|
+
end
|
595
|
+
expect(get('nodes/blah')).to include(
|
596
|
+
'normal' => {
|
597
|
+
'a' => "1",
|
598
|
+
'c' => { 'd' => 'e' },
|
599
|
+
'tags' => [ 'a', 'b' ]
|
600
|
+
},
|
601
|
+
'automatic' => { 'x' => 'y' },
|
602
|
+
'chef_environment' => 'desert'
|
603
|
+
)
|
604
|
+
end
|
605
|
+
|
606
|
+
it 'chef_node with attribute a, "" sets a to ""' do
|
607
|
+
run_recipe do
|
608
|
+
chef_node 'blah' do
|
609
|
+
attribute 'a', ""
|
610
|
+
end
|
611
|
+
end
|
612
|
+
expect(get('nodes/blah')).to include(
|
613
|
+
'normal' => {
|
614
|
+
'a' => "",
|
615
|
+
'c' => { 'd' => 'e' },
|
616
|
+
'tags' => [ 'a', 'b' ]
|
617
|
+
},
|
618
|
+
'automatic' => { 'x' => 'y' },
|
619
|
+
'chef_environment' => 'desert'
|
620
|
+
)
|
621
|
+
end
|
622
|
+
|
623
|
+
it 'chef_node with attribute a, nil sets a to nil' do
|
624
|
+
run_recipe do
|
625
|
+
chef_node 'blah' do
|
626
|
+
attribute 'a', nil
|
627
|
+
end
|
628
|
+
end
|
629
|
+
expect(get('nodes/blah')).to include(
|
630
|
+
'normal' => {
|
631
|
+
'a' => nil,
|
632
|
+
'c' => { 'd' => 'e' },
|
633
|
+
'tags' => [ 'a', 'b' ]
|
634
|
+
},
|
635
|
+
'automatic' => { 'x' => 'y' },
|
636
|
+
'chef_environment' => 'desert'
|
637
|
+
)
|
184
638
|
end
|
185
639
|
end
|
186
640
|
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
641
|
+
context 'multiple attribute definitions' do
|
642
|
+
it 'chef_node with attribute a, x and c, y replaces both attributes' do
|
643
|
+
run_recipe do
|
644
|
+
chef_node 'blah' do
|
645
|
+
attribute 'a', 'x'
|
646
|
+
attribute 'c', 'y'
|
647
|
+
end
|
648
|
+
end
|
649
|
+
expect(get('nodes/blah')).to include(
|
650
|
+
'normal' => {
|
651
|
+
'a' => 'x',
|
652
|
+
'c' => 'y',
|
653
|
+
'tags' => [ 'a', 'b' ]
|
654
|
+
},
|
655
|
+
'automatic' => { 'x' => 'y' },
|
656
|
+
'chef_environment' => 'desert'
|
657
|
+
)
|
658
|
+
end
|
659
|
+
|
660
|
+
it 'chef_node with attribute m, x and n, y adds both attributes' do
|
661
|
+
run_recipe do
|
662
|
+
chef_node 'blah' do
|
663
|
+
attribute 'm', 'x'
|
664
|
+
attribute 'n', 'y'
|
665
|
+
end
|
666
|
+
end
|
667
|
+
expect(get('nodes/blah')).to include(
|
668
|
+
'normal' => {
|
669
|
+
'a' => 'b',
|
670
|
+
'c' => { 'd' => 'e' },
|
671
|
+
'm' => 'x',
|
672
|
+
'n' => 'y',
|
673
|
+
'tags' => [ 'a', 'b' ]
|
674
|
+
},
|
675
|
+
'automatic' => { 'x' => 'y' },
|
676
|
+
'chef_environment' => 'desert'
|
677
|
+
)
|
678
|
+
end
|
679
|
+
|
680
|
+
it 'chef_node with attribute [x, y], z and [x, yy], zz adds both attributes' do
|
681
|
+
run_recipe do
|
682
|
+
chef_node 'blah' do
|
683
|
+
attribute [ 'x', 'y' ], 'z'
|
684
|
+
attribute [ 'x', 'yy' ], 'zz'
|
685
|
+
end
|
686
|
+
end
|
687
|
+
expect(get('nodes/blah')).to include(
|
688
|
+
'normal' => {
|
689
|
+
'a' => 'b',
|
690
|
+
'c' => { 'd' => 'e' },
|
691
|
+
'x' => {
|
692
|
+
'y' => 'z',
|
693
|
+
'yy' => 'zz'
|
694
|
+
},
|
695
|
+
'tags' => [ 'a', 'b' ]
|
696
|
+
},
|
697
|
+
'automatic' => { 'x' => 'y' },
|
698
|
+
'chef_environment' => 'desert'
|
699
|
+
)
|
700
|
+
end
|
701
|
+
|
702
|
+
describe 'precedence' do
|
703
|
+
it 'chef_node with attribute a, 1 and a, 2 sets a to 2' do
|
704
|
+
run_recipe do
|
705
|
+
chef_node 'blah' do
|
706
|
+
attribute 'a', 1
|
707
|
+
attribute 'a', 2
|
708
|
+
end
|
709
|
+
end
|
710
|
+
expect(get('nodes/blah')).to include(
|
711
|
+
'normal' => {
|
712
|
+
'a' => 2,
|
713
|
+
'c' => { 'd' => 'e' },
|
714
|
+
'tags' => [ 'a', 'b' ]
|
715
|
+
},
|
716
|
+
'automatic' => { 'x' => 'y' },
|
717
|
+
'chef_environment' => 'desert'
|
718
|
+
)
|
719
|
+
end
|
720
|
+
|
721
|
+
it 'chef_node with attribute [ x, y ], 1 and [ x, y ], 2 sets [ x, y ], 2' do
|
722
|
+
run_recipe do
|
723
|
+
chef_node 'blah' do
|
724
|
+
attribute [ 'x', 'y' ], 1
|
725
|
+
attribute [ 'x', 'y' ], 2
|
726
|
+
end
|
727
|
+
end
|
728
|
+
expect(get('nodes/blah')).to include(
|
729
|
+
'normal' => {
|
730
|
+
'a' => 'b',
|
731
|
+
'c' => { 'd' => 'e' },
|
732
|
+
'x' => { 'y' => 2 },
|
733
|
+
'tags' => [ 'a', 'b' ]
|
734
|
+
},
|
735
|
+
'automatic' => { 'x' => 'y' },
|
736
|
+
'chef_environment' => 'desert'
|
737
|
+
)
|
738
|
+
end
|
739
|
+
|
740
|
+
it 'chef_node with attribute [ c, e ], { a => 1 }, [ c, e ], { b => 2 } sets b only' do
|
741
|
+
run_recipe do
|
742
|
+
chef_node 'blah' do
|
743
|
+
attribute [ 'c', 'e' ], { 'a' => 1 }
|
744
|
+
attribute [ 'c', 'e' ], { 'b' => 2 }
|
745
|
+
end
|
746
|
+
end
|
747
|
+
expect(get('nodes/blah')).to include(
|
748
|
+
'normal' => {
|
749
|
+
'a' => 'b',
|
750
|
+
'c' => { 'd' => 'e', 'e' => { 'b' => 2 } },
|
751
|
+
'tags' => [ 'a', 'b' ]
|
752
|
+
},
|
753
|
+
'automatic' => { 'x' => 'y' },
|
754
|
+
'chef_environment' => 'desert'
|
755
|
+
)
|
756
|
+
end
|
757
|
+
|
758
|
+
it 'chef_node with attribute [ c, e ], { a => 1 }, [ c, e, b ], 2 sets both' do
|
759
|
+
run_recipe do
|
760
|
+
chef_node 'blah' do
|
761
|
+
attribute [ 'c', 'e' ], { 'a' => 1 }
|
762
|
+
attribute [ 'c', 'e', 'b' ], 2
|
763
|
+
end
|
764
|
+
end
|
765
|
+
expect(get('nodes/blah')).to include(
|
766
|
+
'normal' => {
|
767
|
+
'a' => 'b',
|
768
|
+
'c' => { 'd' => 'e', 'e' => { 'a' => 1, 'b' => 2 } },
|
769
|
+
'tags' => [ 'a', 'b' ]
|
770
|
+
},
|
771
|
+
'automatic' => { 'x' => 'y' },
|
772
|
+
'chef_environment' => 'desert'
|
773
|
+
)
|
774
|
+
end
|
775
|
+
|
776
|
+
it 'chef_node with attribute [ c, e, b ], 2, [ c, e ], { a => 1 } sets a only' do
|
777
|
+
run_recipe do
|
778
|
+
chef_node 'blah' do
|
779
|
+
attribute [ 'c', 'e', 'b' ], 2
|
780
|
+
attribute [ 'c', 'e' ], { 'a' => 1 }
|
781
|
+
end
|
782
|
+
end
|
783
|
+
expect(get('nodes/blah')).to include(
|
784
|
+
'normal' => {
|
785
|
+
'a' => 'b',
|
786
|
+
'c' => { 'd' => 'e', 'e' => { 'a' => 1 } },
|
787
|
+
'tags' => [ 'a', 'b' ]
|
788
|
+
},
|
789
|
+
'automatic' => { 'x' => 'y' },
|
790
|
+
'chef_environment' => 'desert'
|
791
|
+
)
|
792
|
+
end
|
793
|
+
end
|
191
794
|
end
|
192
795
|
end
|
193
|
-
|
194
796
|
end
|
195
797
|
end
|
196
798
|
|