beaker 2.7.1 → 2.8.0

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.
Files changed (53) hide show
  1. checksums.yaml +8 -8
  2. data/HISTORY.md +121 -2
  3. data/lib/beaker/dsl.rb +2 -2
  4. data/lib/beaker/dsl/helpers.rb +13 -1429
  5. data/lib/beaker/dsl/helpers/facter_helpers.rb +48 -0
  6. data/lib/beaker/dsl/helpers/hiera_helpers.rb +71 -0
  7. data/lib/beaker/dsl/helpers/host_helpers.rb +506 -0
  8. data/lib/beaker/dsl/helpers/puppet_helpers.rb +698 -0
  9. data/lib/beaker/dsl/helpers/tk_helpers.rb +101 -0
  10. data/lib/beaker/dsl/helpers/web_helpers.rb +115 -0
  11. data/lib/beaker/dsl/install_utils.rb +8 -1570
  12. data/lib/beaker/dsl/install_utils/ezbake_utils.rb +256 -0
  13. data/lib/beaker/dsl/install_utils/module_utils.rb +237 -0
  14. data/lib/beaker/dsl/install_utils/pe_utils.rb +518 -0
  15. data/lib/beaker/dsl/install_utils/puppet_utils.rb +722 -0
  16. data/lib/beaker/dsl/outcomes.rb +0 -4
  17. data/lib/beaker/dsl/roles.rb +0 -3
  18. data/lib/beaker/dsl/structure.rb +127 -4
  19. data/lib/beaker/dsl/wrappers.rb +0 -4
  20. data/lib/beaker/host.rb +23 -0
  21. data/lib/beaker/host/unix/pkg.rb +4 -4
  22. data/lib/beaker/host_prebuilt_steps.rb +11 -5
  23. data/lib/beaker/hypervisor/vagrant.rb +1 -0
  24. data/lib/beaker/hypervisor/vmpooler.rb +38 -0
  25. data/lib/beaker/logger.rb +10 -4
  26. data/lib/beaker/network_manager.rb +5 -4
  27. data/lib/beaker/options/command_line_parser.rb +7 -0
  28. data/lib/beaker/shared.rb +2 -1
  29. data/lib/beaker/shared/semvar.rb +41 -0
  30. data/lib/beaker/test_suite.rb +20 -6
  31. data/lib/beaker/version.rb +1 -1
  32. data/spec/beaker/dsl/helpers/facter_helpers_spec.rb +59 -0
  33. data/spec/beaker/dsl/helpers/hiera_helpers_spec.rb +96 -0
  34. data/spec/beaker/dsl/helpers/host_helpers_spec.rb +413 -0
  35. data/spec/beaker/dsl/{helpers_spec.rb → helpers/puppet_helpers_spec.rb} +2 -611
  36. data/spec/beaker/dsl/helpers/tk_helpers_spec.rb +83 -0
  37. data/spec/beaker/dsl/helpers/web_helpers_spec.rb +60 -0
  38. data/spec/beaker/dsl/install_utils/module_utils_spec.rb +241 -0
  39. data/spec/beaker/dsl/install_utils/pe_utils_spec.rb +475 -0
  40. data/spec/beaker/dsl/install_utils/puppet_utils_spec.rb +523 -0
  41. data/spec/beaker/dsl/structure_spec.rb +108 -0
  42. data/spec/beaker/host_prebuilt_steps_spec.rb +44 -0
  43. data/spec/beaker/host_spec.rb +41 -0
  44. data/spec/beaker/hypervisor/vagrant_spec.rb +2 -1
  45. data/spec/beaker/logger_spec.rb +9 -2
  46. data/spec/beaker/network_manager_spec.rb +7 -1
  47. data/spec/beaker/options/command_line_parser_spec.rb +3 -2
  48. data/spec/beaker/shared/semvar_spec.rb +36 -0
  49. data/spec/beaker/test_suite_spec.rb +48 -0
  50. data/spec/mocks.rb +10 -0
  51. metadata +23 -5
  52. data/lib/beaker/dsl/ezbake_utils.rb +0 -259
  53. data/spec/beaker/dsl/install_utils_spec.rb +0 -1242
@@ -25,288 +25,6 @@ describe ClassMixedWithDSLHelpers do
25
25
  let( :db ) { make_host( 'db', :roles => %w( database agent ) ) }
26
26
  let( :hosts ) { [ master, agent, dash, db, custom ] }
27
27
 
28
- describe '#on' do
29
-
30
- before :each do
31
- result.stdout = 'stdout'
32
- result.stderr = 'stderr'
33
- result.exit_code = 0
34
- end
35
-
36
- it 'allows the environment the command is run within to be specified' do
37
- allow( subject ).to receive( :hosts ).and_return( hosts )
38
-
39
- expect( Beaker::Command ).to receive( :new ).
40
- with( 'ls ~/.bin', [], {'ENV' => { :HOME => '/tmp/test_home' }} )
41
-
42
- subject.on( host, 'ls ~/.bin', :environment => {:HOME => '/tmp/test_home' } )
43
- end
44
-
45
- it 'if the host is a String Object, finds the matching hosts with that String as role' do
46
- allow( subject ).to receive( :hosts ).and_return( hosts )
47
-
48
- expect( master ).to receive( :exec ).once
49
-
50
- subject.on( 'master', 'echo hello')
51
-
52
- end
53
-
54
- it 'if the host is a Symbol Object, finds the matching hsots with that Symbol as role' do
55
- allow( subject ).to receive( :hosts ).and_return( hosts )
56
-
57
- expect( master ).to receive( :exec ).once
58
-
59
- subject.on( :master, 'echo hello')
60
-
61
- end
62
-
63
- it 'delegates to itself for each host passed' do
64
- allow( subject ).to receive( :hosts ).and_return( hosts )
65
- expected = []
66
- hosts.each_with_index do |host, i|
67
- expected << i
68
- expect( host ).to receive( :exec ).and_return( i )
69
- end
70
-
71
- results = subject.on( hosts, command )
72
- expect( results ).to be == expected
73
- end
74
-
75
- context 'upon command completion' do
76
- before :each do
77
- allow( subject ).to receive( :hosts ).and_return( hosts )
78
- expect( host ).to receive( :exec ).and_return( result )
79
- @res = subject.on( host, command )
80
- end
81
-
82
- it 'returns the result of the action' do
83
- expect( @res ).to be == result
84
- end
85
-
86
- it 'provides access to stdout' do
87
- expect( @res.stdout ).to be == 'stdout'
88
- end
89
-
90
- it 'provides access to stderr' do
91
- expect( @res.stderr ).to be == 'stderr'
92
- end
93
-
94
- it 'provides access to exit_code' do
95
- expect( @res.exit_code ).to be == 0
96
- end
97
- end
98
-
99
- context 'when passed a block with arity of 1' do
100
- before :each do
101
- allow( subject ).to receive( :hosts ).and_return( hosts )
102
- expect( host ).to receive( :exec ).and_return( result )
103
- end
104
-
105
- it 'yields result' do
106
- subject.on host, command do |containing_class|
107
- expect( containing_class ).
108
- to be_an_instance_of( Beaker::Result )
109
- end
110
- end
111
-
112
- it 'provides access to stdout' do
113
- subject.on host, command do |containing_class|
114
- expect( containing_class.stdout ).to be == 'stdout'
115
- end
116
- end
117
-
118
- it 'provides access to stderr' do
119
- subject.on host, command do |containing_class|
120
- expect( containing_class.stderr ).to be == 'stderr'
121
- end
122
- end
123
-
124
- it 'provides access to exit_code' do
125
- subject.on host, command do |containing_class|
126
- expect( containing_class.exit_code ).to be == 0
127
- end
128
- end
129
- end
130
-
131
- context 'when passed a block with arity of 0' do
132
- before :each do
133
- allow( subject ).to receive( :hosts ).and_return( hosts )
134
- expect( host ).to receive( :exec ).and_return( result )
135
- end
136
-
137
- it 'yields self' do
138
- subject.on host, command do
139
- expect( subject ).
140
- to be_an_instance_of( ClassMixedWithDSLHelpers )
141
- end
142
- end
143
-
144
- it 'provides access to stdout' do
145
- subject.on host, command do
146
- expect( subject.stdout ).to be == 'stdout'
147
- end
148
- end
149
-
150
- it 'provides access to stderr' do
151
- subject.on host, command do
152
- expect( subject.stderr ).to be == 'stderr'
153
- end
154
- end
155
-
156
- it 'provides access to exit_code' do
157
- subject.on host, command do
158
- expect( subject.exit_code ).to be == 0
159
- end
160
- end
161
- end
162
-
163
- end
164
-
165
- describe "#retry_on" do
166
- it 'fails correctly when command never succeeds' do
167
- result.stdout = 'stdout'
168
- result.stderr = 'stderr'
169
- result.exit_code = 1
170
-
171
- retries = 5
172
-
173
- opts = {
174
- :max_retries => retries,
175
- :retry_interval => 0.0001,
176
- }
177
-
178
- allow( subject ).to receive(:on).and_return(result)
179
- expect( subject ).to receive(:on).exactly(retries+2)
180
- expect { subject.retry_on(host, command, opts) }.to raise_error(RuntimeError)
181
- end
182
-
183
- it 'will return success correctly if it succeeds the first time' do
184
- result.stdout = 'stdout'
185
- result.stderr = 'stderr'
186
- result.exit_code = 0
187
-
188
- opts = {
189
- :max_retries => 5,
190
- :retry_interval => 0.0001,
191
- }
192
-
193
- allow( subject ).to receive(:on).and_return(result)
194
- expect( subject ).to receive(:on).once
195
-
196
- result_given = subject.retry_on(host, command, opts)
197
- expect(result_given.exit_code).to be === 0
198
- end
199
-
200
- it 'will return success correctly if it succeeds after failing a few times' do
201
- result.stdout = 'stdout'
202
- result.stderr = 'stderr'
203
-
204
- opts = {
205
- :max_retries => 10,
206
- :retry_interval => 0.1,
207
- }
208
-
209
- reps_num = 4
210
- count = 0
211
- allow( subject ).to receive(:on) do
212
- result.exit_code = count > reps_num ? 0 : 1
213
- count += 1
214
- result
215
- end
216
- expect( subject ).to receive(:on).exactly(reps_num + 2)
217
-
218
- result_given = subject.retry_on(host, command, opts)
219
- expect(result_given.exit_code).to be === 0
220
- end
221
- end
222
-
223
- describe "shell" do
224
- it 'delegates to #on with the default host' do
225
- allow( subject ).to receive( :hosts ).and_return( hosts )
226
-
227
- expect( subject ).to receive( :on ).with( master, "echo hello", {}).once
228
-
229
- subject.shell( "echo hello" )
230
- end
231
- end
232
-
233
- describe '#scp_from' do
234
- it 'delegates to the host' do
235
- allow( subject ).to receive( :hosts ).and_return( hosts )
236
- expect( subject ).to receive( :logger ).exactly( hosts.length ).times
237
- expect( result ).to receive( :log ).exactly( hosts.length ).times
238
-
239
- hosts.each do |host|
240
- expect( host ).to receive( :do_scp_from ).and_return( result )
241
- end
242
-
243
- subject.scp_from( hosts, '/var/log/my.log', 'log/my.log' )
244
- end
245
- end
246
-
247
- describe '#scp_to' do
248
- it 'delegates to the host' do
249
- allow( subject ).to receive( :hosts ).and_return( hosts )
250
- expect( subject ).to receive( :logger ).exactly( hosts.length ).times
251
- expect( result ).to receive( :log ).exactly( hosts.length ).times
252
-
253
- hosts.each do |host|
254
- expect( host ).to receive( :do_scp_to ).and_return( result )
255
- end
256
-
257
- subject.scp_to( hosts, '/var/log/my.log', 'log/my.log' )
258
- end
259
- end
260
-
261
- describe '#rsync_to' do
262
- it 'delegates to the host' do
263
- allow( subject ).to receive( :hosts ).and_return( hosts )
264
-
265
- hosts.each do |host|
266
- expect( host ).to receive( :do_rsync_to ).and_return( result )
267
- end
268
-
269
- subject.rsync_to( hosts, '/var/log/my.log', 'log/my.log' )
270
- end
271
- end
272
-
273
- describe '#create_remote_file using scp' do
274
- it 'scps the contents passed in to the hosts' do
275
- my_opts = { :silent => true }
276
- tmpfile = double
277
-
278
- expect( tmpfile ).to receive( :path ).exactly( 2 ).times.
279
- and_return( '/local/path/to/blah' )
280
-
281
- expect( Tempfile ).to receive( :open ).and_yield( tmpfile )
282
-
283
- expect( File ).to receive( :open )
284
-
285
- expect( subject ).to receive( :scp_to ).
286
- with( hosts, '/local/path/to/blah', '/remote/path', my_opts )
287
-
288
- subject.create_remote_file( hosts, '/remote/path', 'blah', my_opts )
289
- end
290
- end
291
-
292
- describe '#create_remote_file using rsync' do
293
- it 'scps the contents passed in to the hosts' do
294
- my_opts = { :silent => true, :protocol => 'rsync' }
295
- tmpfile = double
296
-
297
- expect( tmpfile ).to receive( :path ).exactly( 2 ).times.
298
- and_return( '/local/path/to/blah' )
299
-
300
- expect( Tempfile ).to receive( :open ).and_yield( tmpfile )
301
-
302
- expect( File ).to receive( :open )
303
-
304
- expect( subject ).to receive( :rsync_to ).
305
- with( hosts, '/local/path/to/blah', '/remote/path', my_opts )
306
-
307
- subject.create_remote_file( hosts, '/remote/path', 'blah', my_opts )
308
- end
309
- end
310
28
 
311
29
  describe '#create_tmpdir_for_user' do
312
30
  let(:host) { {} }
@@ -337,9 +55,7 @@ describe ClassMixedWithDSLHelpers do
337
55
  cmd = "the command"
338
56
  expect(Beaker::Command).to receive(:new).with(/puppet master --configprint user/, [], {"ENV"=>{}, :cmdexe=>true}).and_return(cmd)
339
57
  expect(subject).to receive(:on).with(host, cmd).and_return(result)
340
- expect(subject).to receive(:on).with(host, /^getent passwd puppet/).and_return(result)
341
- expect(host).to receive(:tmpdir).with(/\/tmp\/beaker.*/)
342
- expect(subject).to receive(:on).with(host, /chown puppet.puppet.*/)
58
+ expect(subject).to receive(:create_tmpdir_on).with(host, /\/tmp\/beaker/, /puppet/)
343
59
  subject.create_tmpdir_for_user(host)
344
60
  end
345
61
  end
@@ -350,162 +66,15 @@ describe ClassMixedWithDSLHelpers do
350
66
  cmd = "the command"
351
67
  expect(Beaker::Command).to receive(:new).with(/puppet master --configprint user/, [], {"ENV"=>{}, :cmdexe=>true}).and_return(cmd)
352
68
  expect(subject).to receive(:on).with(host, cmd).and_return(result)
353
- expect(subject).to receive(:on).with(host, /^getent passwd puppet/).and_return(result)
354
- expect(host).to receive(:tmpdir).with(/\/tmp\/bogus.*/).and_return("/tmp/bogus")
355
- expect(subject).to receive(:on).with(host, /chown puppet.puppet \/tmp\/bogus.*/)
69
+ expect(subject).to receive(:create_tmpdir_on).with(host, /\/tmp\/bogus/, /puppet/)
356
70
  subject.create_tmpdir_for_user(host, "/tmp/bogus")
357
71
  end
358
72
  end
359
73
 
360
74
  end
361
75
 
362
- context 'with an invalid user argument' do
363
- it 'executes chown once' do
364
- allow(result).to receive(:stdout).and_return('curiousgeorge')
365
- expect(subject).to receive(:on).with(host, /^getent passwd curiousgeorge/).and_return(result)
366
- expect(host).to receive(:tmpdir).with(/\/tmp\/bogus.*/).and_return("/tmp/bogus")
367
- expect(subject).to receive(:on).with(host, /chown curiousgeorge.curiousgeorge \/tmp\/bogus.*/)
368
- subject.create_tmpdir_for_user(host, "/tmp/bogus", "curiousgeorge")
369
- end
370
- end
371
-
372
- context 'with a valid user argument' do
373
- it 'executes chown once' do
374
- allow(result).to receive(:exit_code).and_return(1)
375
- expect(subject).to receive(:on).with(host, /^getent passwd curiousgeorge/).and_return(result)
376
- expect{
377
- subject.create_tmpdir_for_user(host, "/tmp/bogus", "curiousgeorge")
378
- }.to raise_error(RuntimeError, /User curiousgeorge does not exist on/)
379
- end
380
- end
381
-
382
76
  end
383
77
 
384
- describe '#run_script_on' do
385
- it 'scps the script to a tmpdir and executes it on host(s)' do
386
- expect( subject ).to receive( :scp_to )
387
- expect( subject ).to receive( :on )
388
- subject.run_script_on( 'host', '~/.bin/make-enterprisy' )
389
- end
390
- end
391
-
392
- describe '#run_script' do
393
- it 'delegates to #run_script_on with the default host' do
394
- allow( subject ).to receive( :hosts ).and_return( hosts )
395
-
396
- expect( subject ).to receive( :run_script_on ).with( master, "/tmp/test.sh", {}).once
397
-
398
- subject.run_script( '/tmp/test.sh' )
399
- end
400
- end
401
-
402
- describe 'confine' do
403
- let(:logger) { double.as_null_object }
404
- before do
405
- allow( subject ).to receive( :logger ).and_return( logger )
406
- end
407
-
408
- it 'skips the test if there are no applicable hosts' do
409
- allow( subject ).to receive( :hosts ).and_return( [] )
410
- allow( subject ).to receive( :hosts= )
411
- expect( logger ).to receive( :warn )
412
- expect( subject ).to receive( :skip_test ).
413
- with( 'No suitable hosts found' )
414
-
415
- subject.confine( :to, {} )
416
- end
417
-
418
- it 'raises when given mode is not :to or :except' do
419
- allow( subject ).to receive( :hosts )
420
- allow( subject ).to receive( :hosts= )
421
-
422
- expect {
423
- subject.confine( :regardless, {:thing => 'value'} )
424
- }.to raise_error( 'Unknown option regardless' )
425
- end
426
-
427
- it 'rejects hosts that do not meet simple hash criteria' do
428
- hosts = [ {'thing' => 'foo'}, {'thing' => 'bar'} ]
429
-
430
- expect( subject ).to receive( :hosts ).and_return( hosts )
431
- expect( subject ).to receive( :hosts= ).
432
- with( [ {'thing' => 'foo'} ] )
433
-
434
- subject.confine :to, :thing => 'foo'
435
- end
436
-
437
- it 'rejects hosts that match a list of criteria' do
438
- hosts = [ {'thing' => 'foo'}, {'thing' => 'bar'}, {'thing' => 'baz'} ]
439
-
440
- expect( subject ).to receive( :hosts ).and_return( hosts )
441
- expect( subject ).to receive( :hosts= ).
442
- with( [ {'thing' => 'bar'} ] )
443
-
444
- subject.confine :except, :thing => ['foo', 'baz']
445
- end
446
-
447
- it 'rejects hosts when a passed block returns true' do
448
- host1 = {'platform' => 'solaris'}
449
- host2 = {'platform' => 'solaris'}
450
- host3 = {'platform' => 'windows'}
451
- ret1 = (Struct.new('Result1', :stdout)).new(':global')
452
- ret2 = (Struct.new('Result2', :stdout)).new('a_zone')
453
- hosts = [ host1, host2, host3 ]
454
-
455
- expect( subject ).to receive( :hosts ).and_return( hosts )
456
- expect( subject ).to receive( :on ).
457
- with( host1, '/sbin/zonename' ).
458
- and_return( ret1 )
459
- expect( subject ).to receive( :on ).
460
- with( host1, '/sbin/zonename' ).
461
- and_return( ret2 )
462
-
463
- expect( subject ).to receive( :hosts= ).with( [ host1 ] )
464
-
465
- subject.confine :to, :platform => 'solaris' do |host|
466
- subject.on( host, '/sbin/zonename' ).stdout =~ /:global/
467
- end
468
- end
469
- end
470
-
471
- describe '#select_hosts' do
472
- let(:logger) { double.as_null_object }
473
- before do
474
- allow( subject ).to receive( :logger ).and_return( logger )
475
- end
476
-
477
- it 'it returns an empty array if there are no applicable hosts' do
478
- hosts = [ {'thing' => 'foo'}, {'thing' => 'bar'} ]
479
-
480
- expect(subject.select_hosts( {'thing' => 'nope'}, hosts )).to be == []
481
- end
482
-
483
- it 'selects hosts that match a list of criteria' do
484
- hosts = [ {'thing' => 'foo'}, {'thing' => 'bar'}, {'thing' => 'baz'} ]
485
-
486
- expect(subject.select_hosts( {:thing => ['foo', 'baz']}, hosts )).to be == [ {'thing' => 'foo'}, {'thing' => 'baz'} ]
487
- end
488
-
489
- it 'selects hosts when a passed block returns true' do
490
- host1 = {'platform' => 'solaris1'}
491
- host2 = {'platform' => 'solaris2'}
492
- host3 = {'platform' => 'windows'}
493
- ret1 = double('result1')
494
- allow( ret1 ).to receive( :stdout ).and_return(':global')
495
- ret2 = double('result2')
496
- allow( ret2 ).to receive( :stdout ).and_return('a_zone')
497
- hosts = [ host1, host2, host3 ]
498
- expect( subject ).to receive( :hosts ).and_return( hosts )
499
-
500
- expect( subject ).to receive( :on ).with( host1, '/sbin/zonename' ).once.and_return( ret1 )
501
- expect( subject ).to receive( :on ).with( host2, '/sbin/zonename' ).once.and_return( ret2 )
502
-
503
- selected_hosts = subject.select_hosts 'platform' => 'solaris' do |host|
504
- subject.on(host, '/sbin/zonename').stdout =~ /:global/
505
- end
506
- expect( selected_hosts ).to be == [ host1 ]
507
- end
508
- end
509
78
 
510
79
  describe '#apply_manifest_on' do
511
80
  it 'calls puppet' do
@@ -783,33 +352,6 @@ describe ClassMixedWithDSLHelpers do
783
352
  end
784
353
  end
785
354
 
786
- describe 'version_is_less' do
787
-
788
- it 'reports 3.0.0-160-gac44cfb is not less than 3.0.0' do
789
- expect( subject.version_is_less( '3.0.0-160-gac44cfb', '3.0.0' ) ).to be === false
790
- end
791
-
792
- it 'reports 3.0.0-160-gac44cfb is not less than 2.8.2' do
793
- expect( subject.version_is_less( '3.0.0-160-gac44cfb', '2.8.2' ) ).to be === false
794
- end
795
-
796
- it 'reports 3.0.0 is less than 3.0.0-160-gac44cfb' do
797
- expect( subject.version_is_less( '3.0.0', '3.0.0-160-gac44cfb' ) ).to be === true
798
- end
799
-
800
- it 'reports 2.8.2 is less than 3.0.0-160-gac44cfb' do
801
- expect( subject.version_is_less( '2.8.2', '3.0.0-160-gac44cfb' ) ).to be === true
802
- end
803
-
804
- it 'reports 2.8 is less than 3.0.0-160-gac44cfb' do
805
- expect( subject.version_is_less( '2.8', '3.0.0-160-gac44cfb' ) ).to be === true
806
- end
807
-
808
- it 'reports 2.8 is less than 2.9' do
809
- expect( subject.version_is_less( '2.8', '2.9' ) ).to be === true
810
- end
811
- end
812
-
813
355
  describe "#stop_agent_on" do
814
356
  let( :result_fail ) { Beaker::Result.new( [], "" ) }
815
357
  let( :result_pass ) { Beaker::Result.new( [], "" ) }
@@ -1257,156 +799,5 @@ describe ClassMixedWithDSLHelpers do
1257
799
  end
1258
800
  end
1259
801
 
1260
- describe '#fact_on' do
1261
- it 'retrieves a fact on a single host' do
1262
- result.stdout = "family\n"
1263
- expect( subject ).to receive(:facter).with('osfamily',{}).once
1264
- expect( subject ).to receive(:on).and_return(result)
1265
-
1266
- expect( subject.fact_on('host','osfamily') ).to be === result.stdout.chomp
1267
- end
1268
-
1269
- it 'retrieves an array of facts from multiple hosts' do
1270
- allow( subject ).to receive( :hosts ).and_return( hosts )
1271
- times = hosts.length
1272
- result.stdout = "family\n"
1273
- hosts.each do |host|
1274
- expect( host ).to receive(:exec).and_return(result)
1275
- end
1276
-
1277
- expect( subject.fact_on(hosts,'osfamily') ).to be === [result.stdout.chomp] * hosts.length
1278
-
1279
- end
1280
- end
1281
-
1282
- describe '#fact' do
1283
- it 'delegates to #fact_on with the default host' do
1284
- allow( subject ).to receive(:hosts).and_return(hosts)
1285
- expect( subject ).to receive(:fact_on).with(master,"osfamily",{}).once
1286
-
1287
- subject.fact('osfamily')
1288
- end
1289
- end
1290
-
1291
- describe 'modify_tk_config' do
1292
- let(:host) { double.as_null_object }
1293
- let(:config_file_path) { 'existing-file-path'}
1294
- let(:invalid_config_file_path) { 'nonexisting-file-path'}
1295
- let(:options_hash) { {:key => 'value'} }
1296
- let(:replace) { true }
1297
-
1298
- shared_examples 'modify-tk-config-without-error' do
1299
- it 'dumps to the SUT config file path' do
1300
- allow( JSON ).to receive(:dump)
1301
- allow( subject ).to receive(:create_remote_file).with(host, config_file_path, anything())
1302
- subject.modify_tk_config(host, config_file_path, options_hash, replace)
1303
- end
1304
- end
1305
-
1306
- before do
1307
- allow( host ).to receive(:file_exist?).with(invalid_config_file_path).and_return(false)
1308
- allow( host ).to receive(:file_exist?).with(config_file_path).and_return(true)
1309
- end
1310
-
1311
- describe 'if file does not exist on SUT' do
1312
- it 'raises Runtime error' do
1313
- expect do
1314
- subject.modify_tk_config(host, invalid_config_file_path, options_hash)
1315
- end.to raise_error(RuntimeError, /.* does not exist on .*/)
1316
- end
1317
- end
1318
-
1319
- describe 'given an empty options hash' do
1320
- it 'returns nil' do
1321
- expect(subject.modify_tk_config(host, 'blahblah', {})).to eq(nil)
1322
- end
1323
- end
1324
-
1325
- describe 'given a non-empty options hash' do
1326
-
1327
- describe 'given a false value to its `replace` parameter' do
1328
- let(:replace) { false }
1329
- before do
1330
- expect( subject ).to receive(:read_tk_config_string).with(anything())
1331
- end
1332
- include_examples('modify-tk-config-without-error')
1333
- end
1334
-
1335
- describe 'given a true value to its `replace` parameter' do
1336
- before do
1337
- expect( JSON ).to receive(:dump)
1338
- expect( subject ).to receive(:create_remote_file).with(host, config_file_path, anything())
1339
- end
1340
- include_examples('modify-tk-config-without-error')
1341
- end
1342
- end
1343
- end
1344
-
1345
- describe "#write_hiera_config_on" do
1346
- let(:hierarchy) { [ 'nodes/%{::fqdn}', 'common' ] }
1347
- it 'on FOSS host' do
1348
- host = make_host('testhost', { :platform => 'ubuntu' } )
1349
- expect(subject).to receive(:create_remote_file).with(host, host.puppet['hiera_config'], /#{host[:hieradatadir]}/)
1350
- subject.write_hiera_config_on(host, hierarchy)
1351
- end
1352
-
1353
- it 'on PE host' do
1354
- host = make_host('testhost', { :platform => 'ubuntu', :type => 'pe' } )
1355
- expect(subject).to receive(:create_remote_file).with(host, host.puppet['hiera_config'], /#{host[:hieradatadir]}/)
1356
- subject.write_hiera_config_on(host, hierarchy)
1357
- end
1358
-
1359
- end
1360
-
1361
- describe "#write_hiera_config" do
1362
- let(:hierarchy) { [ 'nodes/%{::fqdn}', 'common' ] }
1363
- it 'delegates to #write_hiera_config_on with the default host' do
1364
- allow( subject ).to receive( :hosts ).and_return( hosts )
1365
- expect( subject ).to receive( :write_hiera_config_on ).with( master, hierarchy).once
1366
- subject.write_hiera_config( hierarchy )
1367
- end
1368
-
1369
- end
1370
-
1371
- describe "#copy_hiera_data_to" do
1372
- let(:path) { 'spec/fixtures/hieradata' }
1373
- it 'on FOSS host' do
1374
- host = make_host('testhost', { :platform => 'ubuntu' } )
1375
- expect(subject).to receive(:scp_to).with(host, File.expand_path(path), host[:hieradatadir])
1376
- subject.copy_hiera_data_to(host, path)
1377
- end
1378
-
1379
- it 'on PE host' do
1380
- host = make_host('testhost', { :platform => 'ubuntu', :type => 'pe' } )
1381
- expect(subject).to receive(:scp_to).with(host, File.expand_path(path), host[:hieradatadir])
1382
- subject.copy_hiera_data_to(host, path)
1383
- end
1384
- end
1385
-
1386
- describe "#copy_hiera_data" do
1387
- let(:path) { 'spec/fixtures/hieradata' }
1388
- it 'delegates to #copy_hiera_data_to with the default host' do
1389
- allow( subject ).to receive( :hosts ).and_return( hosts )
1390
- expect( subject ).to receive( :copy_hiera_data_to ).with( master, path).once
1391
- subject.copy_hiera_data( path )
1392
- end
1393
-
1394
- end
1395
-
1396
- describe '#hiera_datadir' do
1397
- it 'returns the codedir based hieradatadir for AIO' do
1398
- host = hosts[0]
1399
- host['type'] = :aio
1400
- correct_answer = File.join(host.puppet['codedir'], 'hieradata')
1401
- expect( subject.hiera_datadir(host) ).to be === correct_answer
1402
- end
1403
-
1404
- it 'returns the hieradata host value for anything not AIO (backwards compatible)' do
1405
- host_hieradatadir_value = '/home/fishing/man/pants'
1406
- host = hosts[0]
1407
- host[:hieradatadir] = host_hieradatadir_value
1408
- expect( subject.hiera_datadir(host) ).to be === host_hieradatadir_value
1409
- end
1410
- end
1411
802
 
1412
803
  end