beaker 3.18.0 → 3.19.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 (45) hide show
  1. checksums.yaml +8 -8
  2. data/Rakefile +0 -23
  3. data/beaker.gemspec +1 -0
  4. data/lib/beaker/dsl/helpers.rb +3 -4
  5. data/lib/beaker/dsl/install_utils.rb +2 -7
  6. data/lib/beaker/dsl/wrappers.rb +0 -87
  7. data/lib/beaker/host/unix/pkg.rb +56 -17
  8. data/lib/beaker/hypervisor/docker.rb +26 -1
  9. data/lib/beaker/options/parser.rb +12 -5
  10. data/lib/beaker/options/subcommand_options_file_parser.rb +11 -4
  11. data/lib/beaker/ssh_connection.rb +6 -6
  12. data/lib/beaker/subcommand.rb +6 -0
  13. data/lib/beaker/version.rb +1 -1
  14. data/spec/beaker/host/unix/pkg_spec.rb +130 -0
  15. data/spec/beaker/hypervisor/docker_spec.rb +28 -1
  16. data/spec/beaker/options/parser_spec.rb +38 -18
  17. data/spec/beaker/options/subcommand_options_parser_spec.rb +28 -5
  18. data/spec/beaker/ssh_connection_spec.rb +17 -17
  19. metadata +16 -28
  20. data/acceptance/config/puppetgem/acceptance-options.rb +0 -9
  21. data/acceptance/config/puppetgit/acceptance-options.rb +0 -9
  22. data/acceptance/config/puppetpkg/acceptance-options.rb +0 -8
  23. data/acceptance/pre_suite/puppet_gem/install.rb +0 -8
  24. data/acceptance/pre_suite/puppet_git/install.rb +0 -98
  25. data/acceptance/pre_suite/puppet_pkg/install.rb +0 -9
  26. data/acceptance/tests/puppet/README.md +0 -3
  27. data/acceptance/tests/puppet/install_smoke_test.rb +0 -21
  28. data/acceptance/tests/puppet/stub_host.rb +0 -47
  29. data/acceptance/tests/puppet/web_helpers_test.rb +0 -55
  30. data/acceptance/tests/puppet/with_puppet_running_on.rb +0 -26
  31. data/lib/beaker/dsl/helpers/puppet_helpers.rb +0 -865
  32. data/lib/beaker/dsl/helpers/tk_helpers.rb +0 -89
  33. data/lib/beaker/dsl/install_utils/aio_defaults.rb +0 -93
  34. data/lib/beaker/dsl/install_utils/ezbake_utils.rb +0 -256
  35. data/lib/beaker/dsl/install_utils/foss_defaults.rb +0 -211
  36. data/lib/beaker/dsl/install_utils/foss_utils.rb +0 -1307
  37. data/lib/beaker/dsl/install_utils/module_utils.rb +0 -244
  38. data/lib/beaker/dsl/install_utils/puppet_utils.rb +0 -157
  39. data/lib/beaker/options/homedir_options_file_parser.rb +0 -0
  40. data/spec/beaker/dsl/helpers/facter_helpers_spec.rb +0 -59
  41. data/spec/beaker/dsl/helpers/puppet_helpers_spec.rb +0 -1179
  42. data/spec/beaker/dsl/helpers/tk_helpers_spec.rb +0 -83
  43. data/spec/beaker/dsl/install_utils/foss_utils_spec.rb +0 -1307
  44. data/spec/beaker/dsl/install_utils/module_utils_spec.rb +0 -261
  45. data/spec/beaker/dsl/install_utils/puppet_utils_spec.rb +0 -136
@@ -1,1179 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class ClassMixedWithDSLHelpers
4
- include Beaker::DSL::Helpers
5
- include Beaker::DSL::Wrappers
6
- include Beaker::DSL::Roles
7
- include Beaker::DSL::Patterns
8
- include Beaker::DSL::Outcomes
9
-
10
- def logger
11
- RSpec::Mocks::Double.new('logger').as_null_object
12
- end
13
-
14
- end
15
-
16
- describe ClassMixedWithDSLHelpers do
17
- let( :opts ) { Beaker::Options::Presets.env_vars }
18
- let( :command ){ 'ls' }
19
- let( :host ) { double.as_null_object }
20
- let( :result ) { Beaker::Result.new( host, command ) }
21
-
22
- let( :master ) { make_host( 'master', :roles => %w( master agent default) ) }
23
- let( :agent ) { make_host( 'agent', :roles => %w( agent ) ) }
24
- let( :custom ) { make_host( 'custom', :roles => %w( custom agent ) ) }
25
- let( :dash ) { make_host( 'console', :roles => %w( dashboard agent ) ) }
26
- let( :db ) { make_host( 'db', :roles => %w( database agent ) ) }
27
- let( :hosts ) { [ master, agent, dash, db, custom ] }
28
-
29
-
30
- describe '#create_tmpdir_for_user' do
31
- let(:host) { {} }
32
- let(:result) { double.as_null_object }
33
-
34
- before :each do
35
- allow(host).to receive(:result).and_return(result)
36
- allow(result).to receive(:exit_code).and_return(0)
37
- allow(result).to receive(:stdout).and_return('puppet')
38
- end
39
-
40
- context 'with no user argument' do
41
-
42
- context 'with no path name argument' do
43
- context 'without puppet installed on host' do
44
- it 'raises an error' do
45
- cmd = "the command"
46
- allow(result).to receive(:exit_code).and_return(1)
47
- expect(Beaker::Command).to receive(:new).with(/puppet master --configprint user/, [], {"ENV"=>{}, :cmdexe=>true}).and_return(cmd)
48
- expect(subject).to receive(:on).with(host, cmd).and_return(result)
49
- expect{
50
- subject.create_tmpdir_for_user host
51
- }.to raise_error(RuntimeError, /`puppet master --configprint` failed,/)
52
- end
53
- end
54
- context 'with puppet installed on host' do
55
- it 'executes chown once' do
56
- cmd = "the command"
57
- expect(Beaker::Command).to receive(:new).with(/puppet master --configprint user/, [], {"ENV"=>{}, :cmdexe=>true}).and_return(cmd)
58
- expect(subject).to receive(:on).with(host, cmd).and_return(result)
59
- expect(subject).to receive(:create_tmpdir_on).with(host, /\/tmp\/beaker/, /puppet/)
60
- subject.create_tmpdir_for_user(host)
61
- end
62
- end
63
- end
64
-
65
- context 'with path name argument' do
66
- it 'executes chown once' do
67
- cmd = "the command"
68
- expect(Beaker::Command).to receive(:new).with(/puppet master --configprint user/, [], {"ENV"=>{}, :cmdexe=>true}).and_return(cmd)
69
- expect(subject).to receive(:on).with(host, cmd).and_return(result)
70
- expect(subject).to receive(:create_tmpdir_on).with(host, /\/tmp\/bogus/, /puppet/)
71
- subject.create_tmpdir_for_user(host, "/tmp/bogus")
72
- end
73
- end
74
-
75
- end
76
-
77
- end
78
-
79
-
80
- describe '#apply_manifest_on' do
81
- it 'calls puppet' do
82
- allow( subject ).to receive( :hosts ).and_return( hosts )
83
- expect( subject ).to receive( :create_remote_file ).and_return( true )
84
- expect( subject ).to receive( :puppet ).
85
- # with( 'apply', '--verbose', 'agent' ).
86
- and_return( 'puppet_command' )
87
-
88
- expect( subject ).to receive( :on ).
89
- with( agent, 'puppet_command',
90
- :acceptable_exit_codes => [0] )
91
-
92
- subject.apply_manifest_on( agent, 'class { "boo": }')
93
- end
94
-
95
- it 'operates on an array of hosts' do
96
- allow( subject ).to receive( :hosts ).and_return( hosts )
97
- the_hosts = [master, agent]
98
-
99
- expect( subject ).to receive( :create_remote_file ).twice.and_return( true )
100
- the_hosts.each do |host|
101
- expect( subject ).to receive( :puppet ).
102
- and_return( 'puppet_command' )
103
-
104
- expect( subject ).to receive( :on ).
105
- with( host, 'puppet_command', :acceptable_exit_codes => [0] )
106
- end
107
-
108
- result = subject.apply_manifest_on( the_hosts, 'include foobar' )
109
- expect(result).to be_an(Array)
110
- end
111
-
112
- it 'operates on an array of hosts in parallel' do
113
- InParallel::InParallelExecutor.logger = logger
114
- FakeFS.deactivate!
115
- # This will only get hit if forking processes is supported and at least 2 items are being submitted to run in parallel
116
- expect( InParallel::InParallelExecutor ).to receive(:_execute_in_parallel).with(any_args).and_call_original.exactly(2).times
117
- allow( subject ).to receive( :hosts ).and_return( hosts )
118
- the_hosts = [master, agent]
119
-
120
- allow( subject ).to receive( :create_remote_file ).and_return( true )
121
- the_hosts.each do |host|
122
- allow( subject ).to receive( :puppet ).
123
- and_return( 'puppet_command' )
124
-
125
- allow( subject ).to receive( :on ).
126
- with( host, 'puppet_command', :acceptable_exit_codes => [0] )
127
- end
128
-
129
- result = nil
130
- result = subject.apply_manifest_on( the_hosts, 'include foobar', { :run_in_parallel => true } )
131
- expect(result).to be_an(Array)
132
- end
133
-
134
- it 'adds acceptable exit codes with :catch_failures' do
135
- allow( subject ).to receive( :hosts ).and_return( hosts )
136
- expect( subject ).to receive( :create_remote_file ).and_return( true )
137
- expect( subject ).to receive( :puppet ).
138
- and_return( 'puppet_command' )
139
-
140
- expect( subject ).to receive( :on ).
141
- with( agent, 'puppet_command',
142
- :acceptable_exit_codes => [0,2] )
143
-
144
- subject.apply_manifest_on( agent,
145
- 'class { "boo": }',
146
- :catch_failures => true )
147
- end
148
- it 'allows acceptable exit codes through :catch_failures' do
149
- allow( subject ).to receive( :hosts ).and_return( hosts )
150
- expect( subject ).to receive( :create_remote_file ).and_return( true )
151
- expect( subject ).to receive( :puppet ).
152
- and_return( 'puppet_command' )
153
-
154
- expect( subject ).to receive( :on ).
155
- with( agent, 'puppet_command',
156
- :acceptable_exit_codes => [4,0,2] )
157
-
158
- subject.apply_manifest_on( agent,
159
- 'class { "boo": }',
160
- :acceptable_exit_codes => [4],
161
- :catch_failures => true )
162
- end
163
- it 'enforces a 0 exit code through :catch_changes' do
164
- allow( subject ).to receive( :hosts ).and_return( hosts )
165
- expect( subject ).to receive( :create_remote_file ).and_return( true )
166
- expect( subject ).to receive( :puppet ).
167
- and_return( 'puppet_command' )
168
-
169
- expect( subject ).to receive( :on ).with(
170
- agent,
171
- 'puppet_command',
172
- :acceptable_exit_codes => [0]
173
- )
174
-
175
- subject.apply_manifest_on(
176
- agent,
177
- 'class { "boo": }',
178
- :catch_changes => true
179
- )
180
- end
181
- it 'enforces a 2 exit code through :expect_changes' do
182
- allow( subject ).to receive( :hosts ).and_return( hosts )
183
- expect( subject ).to receive( :create_remote_file ).and_return( true )
184
- expect( subject ).to receive( :puppet ).
185
- and_return( 'puppet_command' )
186
-
187
- expect( subject ).to receive( :on ).with(
188
- agent,
189
- 'puppet_command',
190
- :acceptable_exit_codes => [2]
191
- )
192
-
193
- subject.apply_manifest_on(
194
- agent,
195
- 'class { "boo": }',
196
- :expect_changes => true
197
- )
198
- end
199
- it 'enforces exit codes through :expect_failures' do
200
- allow( subject ).to receive( :hosts ).and_return( hosts )
201
- expect( subject ).to receive( :create_remote_file ).and_return( true )
202
- expect( subject ).to receive( :puppet ).
203
- and_return( 'puppet_command' )
204
-
205
- expect( subject ).to receive( :on ).with(
206
- agent,
207
- 'puppet_command',
208
- :acceptable_exit_codes => [1,4,6]
209
- )
210
-
211
- subject.apply_manifest_on(
212
- agent,
213
- 'class { "boo": }',
214
- :expect_failures => true
215
- )
216
- end
217
- it 'enforces exit codes through :expect_failures' do
218
- allow( subject ).to receive( :hosts ).and_return( hosts )
219
- expect {
220
- subject.apply_manifest_on(
221
- agent,
222
- 'class { "boo": }',
223
- :expect_failures => true,
224
- :catch_failures => true
225
- )
226
- }.to raise_error ArgumentError, /catch_failures.+expect_failures/
227
- end
228
- it 'enforces added exit codes through :expect_failures' do
229
- allow( subject ).to receive( :hosts ).and_return( hosts )
230
- expect( subject ).to receive( :create_remote_file ).and_return( true )
231
- expect( subject ).to receive( :puppet ).
232
- and_return( 'puppet_command' )
233
-
234
- expect( subject ).to receive( :on ).with(
235
- agent,
236
- 'puppet_command',
237
- :acceptable_exit_codes => [1,2,3,4,5,6]
238
- )
239
-
240
- subject.apply_manifest_on(
241
- agent,
242
- 'class { "boo": }',
243
- :acceptable_exit_codes => (1..5),
244
- :expect_failures => true
245
- )
246
- end
247
-
248
- it 'can set the --parser future flag' do
249
- allow( subject ).to receive( :hosts ).and_return( hosts )
250
- expect( subject ).to receive( :create_remote_file ).and_return( true )
251
-
252
- expect( subject ).to receive( :on ) do |h, command, opts|
253
- cmdline = command.cmd_line( h )
254
- expect( h ).to be == agent
255
- expect( cmdline ).to include('puppet apply')
256
- expect( cmdline ).to include('--parser=future')
257
- expect( cmdline ).to include('--detailed-exitcodes')
258
- expect( cmdline ).to include('--verbose')
259
- end
260
-
261
- subject.apply_manifest_on(
262
- agent,
263
- 'class { "boo": }',
264
- :acceptable_exit_codes => (1..5),
265
- :future_parser => true,
266
- :expect_failures => true
267
- )
268
- end
269
-
270
- it 'can set the --noops flag' do
271
- allow( subject ).to receive( :hosts ).and_return( hosts )
272
- expect( subject ).to receive( :create_remote_file ).and_return( true )
273
- expect( subject ).to receive( :on ) do |h, command, opts|
274
- cmdline = command.cmd_line( h )
275
- expect( h ).to be == agent
276
- expect( cmdline ).to include('puppet apply')
277
- expect( cmdline ).to include('--detailed-exitcodes')
278
- expect( cmdline ).to include('--verbose')
279
- expect( cmdline ).to include('--noop')
280
- end
281
- subject.apply_manifest_on(
282
- agent,
283
- 'class { "boo": }',
284
- :acceptable_exit_codes => (1..5),
285
- :noop => true,
286
- :expect_failures => true
287
- )
288
- end
289
- end
290
-
291
- it 'can set the --debug flag' do
292
- allow( subject ).to receive( :hosts ).and_return( hosts )
293
- allow( subject ).to receive( :create_remote_file ).and_return( true )
294
- expect( subject ).to receive( :on ) do |h, command, opts|
295
- cmdline = command.cmd_line( h )
296
- expect( h ).to be == agent
297
- expect( cmdline ).to include('puppet apply')
298
- expect( cmdline ).not_to include('--verbose')
299
- expect( cmdline ).to include('--debug')
300
- end
301
- subject.apply_manifest_on(
302
- agent,
303
- 'class { "boo": }',
304
- :debug => true,
305
- )
306
- end
307
-
308
- describe "#apply_manifest" do
309
- it "delegates to #apply_manifest_on with the default host" do
310
- allow( subject ).to receive( :hosts ).and_return( hosts )
311
-
312
- expect( subject ).to receive( :apply_manifest_on ).with( master, 'manifest', {:opt => 'value'}).once
313
-
314
- subject.apply_manifest( 'manifest', {:opt => 'value'} )
315
-
316
- end
317
- end
318
-
319
- describe '#stub_hosts_on' do
320
- it 'executes puppet on the host passed and ensures it is reverted' do
321
- test_host = make_host('my_host', {})
322
- allow( subject ).to receive( :hosts ).and_return( hosts )
323
- logger = double.as_null_object
324
-
325
- expect( subject ).to receive( :on ).once
326
- allow( subject ).to receive( :logger ).and_return( logger )
327
- expect( subject ).to receive( :teardown ).and_yield
328
- manifest =<<-EOS.gsub /^\s+/, ""
329
- host { 'puppetlabs.com':
330
- \tensure => present,
331
- \tip => '127.0.0.1',
332
- \thost_aliases => [],
333
- }
334
- EOS
335
- expect( subject ).to receive( :apply_manifest_on ).once.
336
- with( test_host, manifest )
337
- expect( subject ).to receive( :puppet ).once.
338
- with( 'resource', 'host',
339
- 'puppetlabs.com',
340
- 'ensure=absent' )
341
-
342
- subject.stub_hosts_on( test_host, {'puppetlabs.com' => '127.0.0.1'} )
343
- end
344
- it 'adds aliases to defined hostname' do
345
- test_host = make_host('my_host', {})
346
- allow( subject ).to receive( :hosts ).and_return( hosts )
347
- logger = double.as_null_object
348
-
349
- expect( subject ).to receive( :on ).once
350
- allow( subject ).to receive( :logger ).and_return( logger )
351
- expect( subject ).to receive( :teardown ).and_yield
352
- manifest =<<-EOS.gsub /^\s+/, ""
353
- host { 'puppetlabs.com':
354
- \tensure => present,
355
- \tip => '127.0.0.1',
356
- \thost_aliases => [\"foo\", \"bar\"],
357
- }
358
- EOS
359
- expect( subject ).to receive( :apply_manifest_on ).once.
360
- with( test_host, manifest )
361
-
362
- subject.stub_hosts_on( test_host, {'puppetlabs.com' => '127.0.0.1'}, {'puppetlabs.com' => ['foo','bar']} )
363
- end
364
- end
365
-
366
- describe "#stub_hosts" do
367
- it "delegates to stub_hosts_on with the default host" do
368
- allow( subject ).to receive( :hosts ).and_return( hosts )
369
-
370
- expect( subject ).to receive( :stub_hosts_on ).with( master, 'ipspec' ).once
371
-
372
- subject.stub_hosts( 'ipspec' )
373
-
374
- end
375
- end
376
-
377
- describe '#stub_forge_on' do
378
- it 'stubs forge.puppetlabs.com with the value of `forge`' do
379
- allow( subject ).to receive( :resolve_hostname_on ).and_return ( '127.0.0.1' )
380
- host = make_host('my_host', {})
381
- expect( subject ).to receive( :stub_hosts_on ).
382
- with( host, {'forge.puppetlabs.com' => '127.0.0.1'}, {'forge.puppetlabs.com' => ['forge.puppet.com','forgeapi.puppetlabs.com','forgeapi.puppet.com']} )
383
-
384
- subject.stub_forge_on( host, 'my_forge.example.com' )
385
- end
386
- end
387
-
388
- describe "#stub_forge" do
389
- it "delegates to stub_forge_on with the default host" do
390
- allow( subject ).to receive( :options ).and_return( {} )
391
- allow( subject ).to receive( :hosts ).and_return( hosts )
392
-
393
- expect( subject ).to receive( :stub_forge_on ).with( master, nil ).once
394
-
395
- subject.stub_forge( )
396
-
397
- end
398
- end
399
-
400
- describe "#stop_agent_on" do
401
- let( :result_fail ) { Beaker::Result.new( [], "" ) }
402
- let( :result_pass ) { Beaker::Result.new( [], "" ) }
403
- before :each do
404
- allow( subject ).to receive( :sleep ).and_return( true )
405
- end
406
-
407
- it 'runs the pe-puppet on a system without pe-puppet-agent' do
408
- vardir = '/var'
409
- deb_agent = make_host( 'deb', :platform => 'debian-7-amd64', :pe_ver => '3.7' )
410
- allow( deb_agent ).to receive( :puppet_configprint ).and_return( { 'vardir' => vardir } )
411
-
412
- expect( deb_agent ).to receive( :file_exist? ).with("/var/state/agent_catalog_run.lock").and_return(false)
413
- expect( deb_agent ).to receive( :file_exist? ).with("/etc/init.d/pe-puppet-agent").and_return(false)
414
-
415
- expect( subject ).to receive( :puppet_resource ).with( "service", "pe-puppet", "ensure=stopped").once
416
- expect( subject ).to receive( :on ).once
417
-
418
- subject.stop_agent_on( deb_agent )
419
-
420
- end
421
-
422
- it 'runs the pe-puppet-agent on a unix system with pe-puppet-agent' do
423
- vardir = '/var'
424
- el_agent = make_host( 'el', :platform => 'el-5-x86_64', :pe_ver => '3.7' )
425
- allow( el_agent ).to receive( :puppet_configprint ).and_return( { 'vardir' => vardir } )
426
-
427
- expect( el_agent ).to receive( :file_exist? ).with("/var/state/agent_catalog_run.lock").and_return(false)
428
- expect( el_agent ).to receive( :file_exist? ).with("/etc/init.d/pe-puppet-agent").and_return(true)
429
-
430
- expect( subject ).to receive( :puppet_resource ).with( "service", "pe-puppet-agent", "ensure=stopped").once
431
- expect( subject ).to receive( :on ).once
432
-
433
- subject.stop_agent_on( el_agent )
434
- end
435
-
436
- it 'runs puppet on a unix system 4.0 or newer' do
437
- vardir = '/var'
438
- el_agent = make_host( 'el', :platform => 'el-5-x86_64', :pe_ver => '4.0' )
439
- allow( el_agent ).to receive( :puppet_configprint ).and_return( { 'vardir' => vardir } )
440
-
441
- expect( el_agent ).to receive( :file_exist? ).with("/var/state/agent_catalog_run.lock").and_return(false)
442
-
443
- expect( subject ).to receive( :puppet_resource ).with( "service", "puppet", "ensure=stopped").once
444
- expect( subject ).to receive( :on ).once
445
-
446
- subject.stop_agent_on( el_agent )
447
- end
448
-
449
- it 'can run on an array of hosts' do
450
- vardir = '/var'
451
- el_agent = make_host( 'el', :platform => 'el-5-x86_64', :pe_ver => '4.0' )
452
- el_agent2 = make_host( 'el', :platform => 'el-5-x86_64', :pe_ver => '4.0' )
453
-
454
- allow( el_agent ).to receive( :puppet_configprint ).and_return( { 'vardir' => vardir } )
455
-
456
- expect( el_agent ).to receive( :file_exist? ).with("/var/state/agent_catalog_run.lock").and_return(false)
457
-
458
- allow( el_agent2 ).to receive( :puppet_configprint ).and_return( { 'vardir' => vardir } )
459
-
460
- expect( el_agent2 ).to receive( :file_exist? ).with("/var/state/agent_catalog_run.lock").and_return(false)
461
-
462
- expect( subject ).to receive( :puppet_resource ).with( "service", "puppet", "ensure=stopped").twice
463
- expect( subject ).to receive( :on ).twice
464
-
465
- subject.stop_agent_on( [el_agent, el_agent2] )
466
- end
467
-
468
- it 'runs in parallel with run_in_parallel=true' do
469
- InParallel::InParallelExecutor.logger = logger
470
- FakeFS.deactivate!
471
- vardir = '/var'
472
- el_agent = make_host( 'el', :platform => 'el-5-x86_64', :pe_ver => '4.0' )
473
- el_agent2 = make_host( 'el', :platform => 'el-5-x86_64', :pe_ver => '4.0' )
474
-
475
- allow( el_agent ).to receive( :puppet_configprint ).and_return( { 'vardir' => vardir } )
476
-
477
- allow( el_agent ).to receive( :file_exist? ).with("/var/state/agent_catalog_run.lock").and_return(false)
478
-
479
- allow( el_agent2 ).to receive( :puppet_configprint ).and_return( { 'vardir' => vardir } )
480
-
481
- allow( el_agent2 ).to receive( :file_exist? ).with("/var/state/agent_catalog_run.lock").and_return(false)
482
-
483
- # This will only get hit if forking processes is supported and at least 2 items are being submitted to run in parallel
484
- expect( InParallel::InParallelExecutor ).to receive(:_execute_in_parallel).with(any_args).and_call_original.exactly(2).times
485
-
486
- subject.stop_agent_on( [el_agent, el_agent2], { :run_in_parallel => true} )
487
- end
488
-
489
- end
490
-
491
- describe "#stop_agent" do
492
- it 'delegates to #stop_agent_on with default host' do
493
- allow( subject ).to receive( :hosts ).and_return( hosts )
494
-
495
- expect( subject ).to receive( :stop_agent_on ).with( master ).once
496
-
497
- subject.stop_agent( )
498
-
499
- end
500
- end
501
-
502
- describe "#sign_certificate_for" do
503
- it 'signs certs' do
504
- allow( subject ).to receive( :sleep ).and_return( true )
505
-
506
- result.stdout = "+ \"#{agent}\""
507
- allow( subject ).to receive( :hosts ).and_return( hosts )
508
-
509
- allow( subject ).to receive( :puppet ) do |arg|
510
- arg
511
- end
512
-
513
- expect( subject ).to receive( :on ).with( master, "cert --sign --all --allow-dns-alt-names", :acceptable_exit_codes => [0,24]).once
514
- expect( subject ).to receive( :on ).with( master, "cert --list --all").once.and_return( result )
515
-
516
- subject.sign_certificate_for( agent )
517
- end
518
-
519
- it 'retries 11 times before quitting' do
520
- allow( subject ).to receive( :sleep ).and_return( true )
521
-
522
- result.stdout = " \"#{agent}\""
523
- allow( subject ).to receive( :hosts ).and_return( hosts )
524
-
525
- allow( subject ).to receive( :puppet ) do |arg|
526
- arg
527
- end
528
-
529
- expect( subject ).to receive( :on ).with( master, "cert --sign --all --allow-dns-alt-names", :acceptable_exit_codes => [0,24]).exactly( 11 ).times
530
- expect( subject ).to receive( :on ).with( master, "cert --list --all").exactly( 11 ).times.and_return( result )
531
- expect( subject ).to receive( :fail_test ).once
532
-
533
- subject.sign_certificate_for( agent )
534
- end
535
-
536
- it 'accepts an array of hosts to validate' do
537
- allow( subject ).to receive( :sleep ).and_return( true )
538
-
539
- result.stdout = "+ \"#{agent}\" + \"#{custom}\""
540
- allow( subject ).to receive( :hosts ).and_return( hosts )
541
-
542
- allow( subject ).to receive( :puppet ) do |arg|
543
- arg
544
- end
545
- expect( subject ).to receive( :on ).with( master, "agent -t", :acceptable_exit_codes => [0, 1, 2]).once
546
- expect( subject ).to receive( :on ).with( master, "cert --allow-dns-alt-names sign master", :acceptable_exit_codes => [0, 24]).once
547
- expect( subject ).to receive( :on ).with( master, "cert --sign --all --allow-dns-alt-names", :acceptable_exit_codes => [0,24]).once
548
- expect( subject ).to receive( :on ).with( master, "cert --list --all").once.and_return( result )
549
-
550
- subject.sign_certificate_for( [master, agent, custom] )
551
- end
552
- end
553
-
554
- describe "#sign_certificate" do
555
- it 'delegates to #sign_certificate_for with the default host' do
556
- allow( subject ).to receive( :hosts ).and_return( hosts )
557
-
558
- expect( subject ).to receive( :sign_certificate_for ).with( master ).once
559
-
560
- subject.sign_certificate( )
561
- end
562
- end
563
-
564
- describe '#with_puppet_running_on' do
565
- let(:test_case_path) { 'testcase/path' }
566
- let(:tmpdir_path) { '/tmp/tmpdir' }
567
- let(:is_pe) { false }
568
- let(:use_service) { false }
569
- let(:platform) { 'redhat' }
570
- let(:host) do
571
- FakeHost.create('fakevm', "#{platform}-version-arch",
572
- 'type' => is_pe ? 'pe': 'git',
573
- 'use-service' => use_service
574
- )
575
- end
576
-
577
- def stub_host_and_subject_to_allow_the_default_testdir_argument_to_be_created
578
- subject.instance_variable_set(:@path, test_case_path)
579
- allow( host ).to receive(:tmpdir).and_return(tmpdir_path)
580
- allow( host ).to receive(:file_exist?).and_return(true)
581
- allow( subject ).to receive( :options ).and_return( {} )
582
- end
583
-
584
- before do
585
- stub_host_and_subject_to_allow_the_default_testdir_argument_to_be_created
586
- allow( subject ).to receive(:curl_with_retries)
587
- end
588
-
589
- it "raises an ArgumentError if you try to submit a String instead of a Hash of options" do
590
- expect { subject.with_puppet_running_on(host, '--foo --bar') }.to raise_error(ArgumentError, /conf_opts must be a Hash. You provided a String: '--foo --bar'/)
591
- end
592
-
593
- it 'raises the early_exception if backup_the_file fails' do
594
- expect( subject ).to receive(:backup_the_file).and_raise(RuntimeError.new('puppet conf backup failed'))
595
- expect {
596
- subject.with_puppet_running_on(host, {})
597
- }.to raise_error(RuntimeError, /puppet conf backup failed/)
598
- end
599
-
600
- it 'receives a Minitest::Assertion and fails the test correctly' do
601
- allow( subject ).to receive( :backup_the_file ).and_raise( Minitest::Assertion.new('assertion failed!') )
602
- expect( subject ).to receive( :fail_test )
603
- subject.with_puppet_running_on(host, {})
604
- end
605
-
606
- context 'with test flow exceptions' do
607
- it 'can pass_test' do
608
- expect( subject ).to receive(:backup_the_file).and_raise(Beaker::DSL::Outcomes::PassTest)
609
- expect {
610
- subject.with_puppet_running_on(host, {}).to receive(:pass_test)
611
- }.to raise_error(Beaker::DSL::Outcomes::PassTest)
612
- end
613
- it 'can fail_test' do
614
- expect( subject ).to receive(:backup_the_file).and_raise(Beaker::DSL::Outcomes::FailTest)
615
- expect {
616
- subject.with_puppet_running_on(host, {}).to receive(:fail_test)
617
- }.to raise_error(Beaker::DSL::Outcomes::FailTest)
618
- end
619
- it 'can skip_test' do
620
- expect( subject ).to receive(:backup_the_file).and_raise(Beaker::DSL::Outcomes::SkipTest)
621
- expect {
622
- subject.with_puppet_running_on(host, {}).to receive(:skip_test)
623
- }.to raise_error(Beaker::DSL::Outcomes::SkipTest)
624
- end
625
- it 'can pending_test' do
626
- expect( subject ).to receive(:backup_the_file).and_raise(Beaker::DSL::Outcomes::PendingTest)
627
- expect {
628
- subject.with_puppet_running_on(host, {}).to receive(:pending_test)
629
- }.to raise_error(Beaker::DSL::Outcomes::PendingTest)
630
- end
631
- end
632
-
633
- describe 'with puppet-server' do
634
- let(:default_confdir) { "/etc/puppet" }
635
- let(:default_vardir) { "/var/lib/puppet" }
636
-
637
- let(:custom_confdir) { "/tmp/etc/puppet" }
638
- let(:custom_vardir) { "/tmp/var/lib/puppet" }
639
-
640
- let(:command_line_args) {"--vardir=#{custom_vardir} --confdir=#{custom_confdir}"}
641
- let(:conf_opts) { {:__commandline_args__ => command_line_args,
642
- :is_puppetserver => true}}
643
-
644
- let(:default_puppetserver_opts) {{ "jruby-puppet" => {
645
- "master-conf-dir" => default_confdir,
646
- "master-var-dir" => default_vardir,
647
- }}}
648
-
649
- let(:custom_puppetserver_opts) {{ "jruby-puppet" => {
650
- "master-conf-dir" => custom_confdir,
651
- "master-var-dir" => custom_vardir,
652
- }}}
653
-
654
- let(:puppetserver_conf) { "/etc/puppetserver/conf.d/puppetserver.conf" }
655
- let(:logger) { double }
656
-
657
- def stub_post_setup
658
- allow( subject ).to receive( :restore_puppet_conf_from_backup)
659
- allow( subject ).to receive( :bounce_service)
660
- allow( subject ).to receive( :stop_puppet_from_source_on)
661
- allow( subject ).to receive( :dump_puppet_log)
662
- allow( subject ).to receive( :restore_puppet_conf_from_backup)
663
- allow( subject ).to receive( :puppet_master_started)
664
- allow( subject ).to receive( :start_puppet_from_source_on!)
665
- allow( subject ).to receive( :lay_down_new_puppet_conf)
666
- allow( subject ).to receive( :logger) .and_return( logger )
667
- allow( logger ).to receive( :error)
668
- allow( logger ).to receive( :debug)
669
- end
670
-
671
- before do
672
- stub_post_setup
673
- allow( subject ).to receive( :options) .and_return( {:is_puppetserver => true})
674
- allow( subject ).to receive( :modify_tk_config)
675
- allow( host ).to receive(:puppet).with( any_args ).and_return({
676
- 'confdir' => default_confdir,
677
- 'vardir' => default_vardir,
678
- 'config' => "#{default_confdir}/puppet.conf"
679
- })
680
- end
681
-
682
- describe 'when the global option for :is_puppetserver is false' do
683
- it 'checks the option for the host object' do
684
- allow( subject ).to receive( :options) .and_return( {:is_puppetserver => false})
685
- host[:is_puppetserver] = true
686
- expect( subject ).to receive( :modify_tk_config)
687
- subject.with_puppet_running_on(host, conf_opts)
688
- end
689
- end
690
-
691
- describe 'and command line args passed' do
692
- it 'modifies SUT trapperkeeper configuration w/ command line args' do
693
- host['puppetserver-confdir'] = '/etc/puppetserver/conf.d'
694
- expect( subject ).to receive( :modify_tk_config).with(host, puppetserver_conf,
695
- custom_puppetserver_opts)
696
- subject.with_puppet_running_on(host, conf_opts)
697
- end
698
- end
699
-
700
- describe 'and no command line args passed' do
701
- let(:command_line_args) { nil }
702
- it 'modifies SUT trapperkeeper configuration w/ puppet defaults' do
703
- host['puppetserver-confdir'] = '/etc/puppetserver/conf.d'
704
- expect( subject ).to receive( :modify_tk_config).with(host, puppetserver_conf,
705
- default_puppetserver_opts)
706
- subject.with_puppet_running_on(host, conf_opts)
707
- end
708
- end
709
- end
710
-
711
- describe "with valid arguments" do
712
- before do
713
- expect( Tempfile ).to receive(:open).with('beaker')
714
- end
715
-
716
- context 'for pe hosts' do
717
- let(:is_pe) { true }
718
- let(:service_restart) { true }
719
-
720
- it 'bounces puppet twice' do
721
- subject.with_puppet_running_on(host, {})
722
- expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=running/).exactly(2).times
723
- expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=stopped/).exactly(2).times
724
- end
725
-
726
- it 'yields to a block in between bouncing service calls' do
727
- execution = 0
728
- allow( subject ).to receive(:curl_with_retries)
729
- expect do
730
- subject.with_puppet_running_on(host, {}) do
731
- expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=running/).exactly(1).times
732
- expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=stopped/).exactly(1).times
733
- execution += 1
734
- end
735
- end.to change { execution }.by(1)
736
- expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=running/).exactly(2).times
737
- expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=stopped/).exactly(2).times
738
- end
739
-
740
- context ':restart_when_done flag set false' do
741
- it 'starts puppet once, stops it twice' do
742
- subject.with_puppet_running_on(host, { :restart_when_done => false })
743
- expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=running/).once
744
- expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=stopped/).exactly(2).times
745
- end
746
-
747
- it 'can be set globally in options' do
748
- host[:restart_when_done] = false
749
-
750
- subject.with_puppet_running_on(host, {})
751
-
752
- expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=running/).once
753
- expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=stopped/).exactly(2).times
754
- end
755
-
756
- it 'yields to a block after bouncing service' do
757
- execution = 0
758
- allow( subject ).to receive(:curl_with_retries)
759
- expect do
760
- subject.with_puppet_running_on(host, { :restart_when_done => false }) do
761
- expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=running/).exactly(1).times
762
- expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=stopped/).exactly(1).times
763
- execution += 1
764
- end
765
- end.to change { execution }.by(1)
766
- expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=stopped/).exactly(2).times
767
- end
768
- end
769
- end
770
-
771
- context 'for foss packaged hosts using passenger' do
772
- before(:each) do
773
- host.uses_passenger!
774
- end
775
- it 'bounces puppet twice' do
776
- allow( subject ).to receive(:curl_with_retries)
777
- subject.with_puppet_running_on(host, {})
778
- expect(host).to execute_commands_matching(/apachectl graceful/).exactly(2).times
779
- end
780
-
781
- it 'gracefully restarts using apache2ctl' do
782
- allow(host).to receive( :check_for_command ).and_return( true )
783
- allow( subject ).to receive(:curl_with_retries)
784
- subject.with_puppet_running_on(host, {})
785
- expect(host).to execute_commands_matching(/apache2ctl graceful/).exactly(2).times
786
- end
787
-
788
- it 'gracefully restarts using apachectl' do
789
- allow(host).to receive( :check_for_command ).and_return( false )
790
- allow( subject ).to receive(:curl_with_retries)
791
- subject.with_puppet_running_on(host, {})
792
- expect(host).to execute_commands_matching(/apachectl graceful/).exactly(2).times
793
- end
794
-
795
- it 'yields to a block after bouncing service' do
796
- execution = 0
797
- allow( subject ).to receive(:curl_with_retries)
798
- expect do
799
- subject.with_puppet_running_on(host, {}) do
800
- expect(host).to execute_commands_matching(/apachectl graceful/).once
801
- execution += 1
802
- end
803
- end.to change { execution }.by(1)
804
- expect(host).to execute_commands_matching(/apachectl graceful/).exactly(2).times
805
- end
806
-
807
- context ':restart_when_done flag set false' do
808
- it 'bounces puppet once' do
809
- allow( subject ).to receive(:curl_with_retries)
810
- subject.with_puppet_running_on(host, { :restart_when_done => false })
811
- expect(host).to execute_commands_matching(/apachectl graceful/).once
812
- end
813
-
814
- it 'yields to a block after bouncing service' do
815
- execution = 0
816
- allow( subject ).to receive(:curl_with_retries)
817
- expect do
818
- subject.with_puppet_running_on(host, { :restart_when_done => false }) do
819
- expect(host).to execute_commands_matching(/apachectl graceful/).once
820
- execution += 1
821
- end
822
- end.to change { execution }.by(1)
823
- end
824
- end
825
- end
826
-
827
- context 'for foss packaged hosts using webrick' do
828
- let(:use_service) { true }
829
-
830
- it 'stops and starts master using service scripts twice' do
831
- allow( subject ).to receive(:curl_with_retries)
832
- subject.with_puppet_running_on(host, {})
833
- expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=running/).exactly(2).times
834
- expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=stopped/).exactly(2).times
835
- end
836
-
837
- it 'yields to a block in between bounce calls for the service' do
838
- execution = 0
839
- expect do
840
- subject.with_puppet_running_on(host, {}) do
841
- expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=running/).once
842
- expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=stopped/).once
843
- execution += 1
844
- end
845
- end.to change { execution }.by(1)
846
- expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=running/).exactly(2).times
847
- expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=stopped/).exactly(2).times
848
- end
849
-
850
- context ':restart_when_done flag set false' do
851
- it 'stops (twice) and starts (once) master using service scripts' do
852
- allow( subject ).to receive(:curl_with_retries)
853
- subject.with_puppet_running_on(host, { :restart_when_done => false })
854
- expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=running/).once
855
- expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=stopped/).exactly(2).times
856
- end
857
-
858
- it 'yields to a block after stopping and starting service' do
859
- execution = 0
860
- expect do
861
- subject.with_puppet_running_on(host, { :restart_when_done => false }) do
862
- expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=running/).once
863
- expect(host).to execute_commands_matching(/puppet resource service #{host['puppetservice']}.*ensure=stopped/).once
864
- execution += 1
865
- end
866
- end.to change { execution }.by(1)
867
- end
868
- end
869
- end
870
-
871
- context 'running from source' do
872
- let('use-service') { false }
873
-
874
- it 'does not try to stop if not started' do
875
- expect( subject ).to receive(:start_puppet_from_source_on!).and_return false
876
- expect( subject ).to_not receive(:stop_puppet_from_source_on)
877
-
878
- subject.with_puppet_running_on(host, {})
879
- end
880
-
881
- context 'successfully' do
882
- before do
883
- expect( host ).to receive(:port_open?).with(8140).and_return(true)
884
- end
885
-
886
- it 'starts puppet from source' do
887
- subject.with_puppet_running_on(host, {})
888
- end
889
-
890
- it 'stops puppet from source' do
891
- subject.with_puppet_running_on(host, {})
892
- expect(host).to execute_commands_matching(/^kill [^-]/).once
893
- expect(host).to execute_commands_matching(/^kill -0/).once
894
- end
895
-
896
- it 'yields between starting and stopping' do
897
- execution = 0
898
- expect do
899
- subject.with_puppet_running_on(host, {}) do
900
- expect(host).to execute_commands_matching(/^puppet master/).exactly(4).times
901
- execution += 1
902
- end
903
- end.to change { execution }.by(1)
904
- expect(host).to execute_commands_matching(/^kill [^-]/).once
905
- expect(host).to execute_commands_matching(/^kill -0/).once
906
- end
907
-
908
- it 'passes on commandline args' do
909
- subject.with_puppet_running_on(host, {:__commandline_args__ => '--with arg'})
910
- expect(host).to execute_commands_matching(/^puppet master --with arg/).once
911
- end
912
-
913
- it 'is not affected by the :restart_when_done flag' do
914
- execution = 0
915
- expect do
916
- subject.with_puppet_running_on(host, { :restart_when_done => true }) do
917
- expect(host).to execute_commands_matching(/^puppet master/).exactly(4).times
918
- execution += 1
919
- end
920
- end.to change { execution }.by(1)
921
- expect(host).to execute_commands_matching(/^kill [^-]/).once
922
- expect(host).to execute_commands_matching(/^kill -0/).once
923
- end
924
- end
925
- end
926
-
927
- describe 'backup and restore of puppet.conf' do
928
- before :each do
929
- mock_puppetconf_reader = Object.new
930
- allow( mock_puppetconf_reader ).to receive( :[] ).with( 'config' ).and_return( '/root/mock/puppet.conf' )
931
- allow( mock_puppetconf_reader ).to receive( :[] ).with( 'confdir' ).and_return( '/root/mock' )
932
- allow( host ).to receive( :puppet ).with( any_args ).and_return( mock_puppetconf_reader )
933
- end
934
-
935
- let(:original_location) { host.puppet['config'] }
936
- let(:backup_location) {
937
- filename = File.basename(host.puppet['config'])
938
- File.join(tmpdir_path, "#{filename}.bak")
939
- }
940
- let(:new_location) {
941
- filename = File.basename(host.puppet['config'])
942
- File.join(tmpdir_path, filename)
943
- }
944
-
945
- context 'when a puppetservice is used' do
946
- let(:use_service) { true }
947
-
948
- it 'backs up puppet.conf' do
949
- subject.with_puppet_running_on(host, {})
950
- expect(host).to execute_commands_matching(/cp #{original_location} #{backup_location}/).once
951
- expect(host).to execute_commands_matching(/cat #{new_location} > #{original_location}/).once
952
- end
953
-
954
- it 'restores puppet.conf before restarting' do
955
- subject.with_puppet_running_on(host, { :restart_when_done => true })
956
- expect(host).to execute_commands_matching_in_order(/cat '#{backup_location}' > '#{original_location}'/,
957
- /ensure=stopped/,
958
- /ensure=running/)
959
- end
960
- end
961
-
962
- context 'when a puppetservice is not used' do
963
- before do
964
- expect( host ).to receive(:port_open?).with(8140).and_return(true)
965
- end
966
-
967
- it 'backs up puppet.conf' do
968
- subject.with_puppet_running_on(host, {})
969
- expect(host).to execute_commands_matching(/cp #{original_location} #{backup_location}/).once
970
- expect(host).to execute_commands_matching(/cat #{new_location} > #{original_location}/).once
971
- end
972
-
973
- it 'restores puppet.conf after restarting when a puppetservice is not used' do
974
- subject.with_puppet_running_on(host, {})
975
- expect(host).to execute_commands_matching_in_order(/kill [^-]/,
976
- /cat '#{backup_location}' > '#{original_location}'/m)
977
- end
978
-
979
- it "doesn't restore a non-existent file" do
980
- allow( subject ).to receive(:backup_the_file)
981
- subject.with_puppet_running_on(host, {})
982
- expect(host).to execute_commands_matching(/rm -f '#{original_location}'/)
983
- end
984
- end
985
- end
986
-
987
- let(:logger) { double.as_null_object }
988
- describe 'handling failures' do
989
-
990
- before do
991
- allow( subject ).to receive( :logger ).and_return( logger )
992
- expect( subject ).to receive(:stop_puppet_from_source_on).and_raise(RuntimeError.new('Also failed in teardown.'))
993
- expect( host ).to receive(:port_open?).with(8140).and_return(true)
994
- end
995
-
996
- it 'does not swallow an exception raised from within test block if ensure block also fails' do
997
- expect( subject.logger ).to receive(:error).with(/Raised during attempt to teardown.*Also failed in teardown/)
998
-
999
- expect do
1000
- subject.with_puppet_running_on(host, {}) { raise 'Failed while yielding.' }
1001
- end.to raise_error(RuntimeError, /failed.*because.*Failed while yielding./)
1002
- end
1003
-
1004
- it 'dumps the puppet logs if there is an error in the teardown' do
1005
- expect( subject.logger ).to receive(:notify).with(/Dumping master log/)
1006
-
1007
- expect do
1008
- subject.with_puppet_running_on(host, {})
1009
- end.to raise_error(RuntimeError, /Also failed in teardown/)
1010
- end
1011
-
1012
- it 'does not mask the teardown error with an error from dumping the logs' do
1013
- expect( subject.logger ).to receive(:notify).with(/Dumping master log/).and_raise("Error from dumping logs")
1014
-
1015
- expect do
1016
- subject.with_puppet_running_on(host, {})
1017
- end.to raise_error(RuntimeError, /Also failed in teardown/)
1018
- end
1019
-
1020
- it 'does not swallow a teardown exception if no earlier exception was raised' do
1021
- expect( subject.logger).to_not receive(:error)
1022
- expect do
1023
- subject.with_puppet_running_on(host, {})
1024
- end.to raise_error(RuntimeError, 'Also failed in teardown.')
1025
- end
1026
-
1027
- end
1028
-
1029
- end
1030
- end
1031
-
1032
- describe '#with_puppet_running' do
1033
- it 'delegates to #with_puppet_running_on with the default host' do
1034
- allow( subject ).to receive( :hosts ).and_return( hosts )
1035
-
1036
- expect( subject ).to receive( :with_puppet_running_on ).with( master, {:opt => 'value'}, '/dir' ).once
1037
-
1038
- subject.with_puppet_running( {:opt => 'value'}, '/dir' )
1039
-
1040
-
1041
- end
1042
- end
1043
-
1044
- describe '#bounce_service' do
1045
- let( :options ) { Beaker::Options::Presets.new.presets }
1046
- let( :result ) { double.as_null_object }
1047
- before :each do
1048
- allow( subject ).to receive( :options ) { options }
1049
- end
1050
-
1051
- it 'requests a reload but not a restart if the reload is successful' do
1052
- host = FakeHost.create
1053
- allow( result ).to receive( :exit_code ).and_return( 0 )
1054
- allow( host ).to receive( :any_exec_result ).and_return( result )
1055
- subject.bounce_service( host, 'not_real_service')
1056
- expect( host ).to execute_commands_matching(/service not_real_service reload/).exactly( 1 ).times
1057
- expect( host ).to execute_commands_matching(/puppet resource service not_real_service ensure=stopped/).exactly( 0 ).times
1058
- expect( host ).to execute_commands_matching(/puppet resource service not_real_service ensure=started/).exactly( 0 ).times
1059
- end
1060
-
1061
- it 'requests a restart if the reload fails' do
1062
- host = FakeHost.create
1063
- allow( result ).to receive( :exit_code ).and_return( 1 )
1064
- allow( host ).to receive( :any_exec_result ).and_return( result )
1065
- expect( subject ).to receive( :curl_with_retries ).with( anything(), anything(), /8140/, anything(), anything() )
1066
- subject.bounce_service( host, 'not_real_service')
1067
- expect( host ).to execute_commands_matching(/service not_real_service reload/).exactly( 1 ).times
1068
- expect( host ).to execute_commands_matching(/puppet resource service not_real_service ensure=stopped/).exactly( 1 ).times
1069
- expect( host ).to execute_commands_matching(/puppet resource service not_real_service ensure=running/).exactly( 1 ).times
1070
- end
1071
-
1072
- it 'uses the default port argument if none given' do
1073
- host = hosts[0]
1074
- expect( host ).to receive( :graceful_restarts? ).and_return( false )
1075
- allow( result ).to receive( :exit_code ).and_return( 1 )
1076
- expect( host ).to receive( :exec ).and_return( result )
1077
- expect( subject ).to receive( :curl_with_retries ).with( anything(), anything(), /8140/, anything(), anything() )
1078
- subject.bounce_service( host, 'not_real_service')
1079
- end
1080
-
1081
- it 'takes the port argument' do
1082
- host = hosts[0]
1083
- expect( host ).to receive( :graceful_restarts? ).and_return( false )
1084
- allow( result ).to receive( :exit_code ).and_return( 1 )
1085
- expect( host ).to receive( :exec ).and_return( result )
1086
- expect( subject ).to receive( :curl_with_retries ).with( anything(), anything(), /8000/, anything(), anything() )
1087
- subject.bounce_service( host, 'not_real_service', nil, 8000)
1088
- end
1089
- end
1090
-
1091
- describe '#sleep_until_puppetdb_started' do
1092
- let( :options ) { Beaker::Options::Presets.new.presets }
1093
- before :each do
1094
- allow( subject ).to receive( :options ) { options }
1095
- end
1096
-
1097
- it 'uses the default ports if none given' do
1098
- host = hosts[0]
1099
- expect( subject ).to receive( :retry_on ).with( anything(), /8080/, anything() ).once.ordered
1100
- expect( subject ).to receive( :curl_with_retries ).with( anything(), anything(), /8081/, anything() ).once.ordered
1101
- subject.sleep_until_puppetdb_started( host )
1102
- end
1103
-
1104
- it 'allows setting the nonssl_port' do
1105
- host = hosts[0]
1106
- expect( subject ).to receive( :retry_on ).with( anything(), /8084/, anything() ).once.ordered
1107
- expect( subject ).to receive( :curl_with_retries ).with( anything(), anything(), /8081/, anything() ).once.ordered
1108
- subject.sleep_until_puppetdb_started( host, 8084 )
1109
-
1110
- end
1111
-
1112
- it 'allows setting the ssl_port' do
1113
- host = hosts[0]
1114
- expect( subject ).to receive( :retry_on ).with( anything(), /8080/, anything() ).once.ordered
1115
- expect( subject ).to receive( :curl_with_retries ).with( anything(), anything(), /8085/, anything() ).once.ordered
1116
- subject.sleep_until_puppetdb_started( host, nil, 8085 )
1117
- end
1118
-
1119
- context 'when pe_ver is less than 2016.1.0' do
1120
- it 'uses the version endpoint' do
1121
- host = hosts[0]
1122
- host['pe_ver'] = '2015.3.3'
1123
- expect( subject ).to receive( :retry_on ).with( anything(), /pdb\/meta\/v1\/version/, anything() ).once.ordered
1124
- expect( subject ).to receive( :curl_with_retries ).with( anything(), anything(), /8081/, anything() ).once.ordered
1125
- subject.sleep_until_puppetdb_started( host )
1126
- end
1127
- end
1128
-
1129
- context 'when pe_ver is greater than 2015.9.9' do
1130
- it 'uses the status endpoint' do
1131
- host = hosts[0]
1132
- host['pe_ver'] = '2016.1.0'
1133
- expect( subject ).to receive( :retry_on ).with( anything(), /status\/v1\/services\/puppetdb-status/, anything() ).once.ordered
1134
- expect( subject ).to receive( :curl_with_retries ).with( anything(), anything(), /8081/, anything() ).once.ordered
1135
- subject.sleep_until_puppetdb_started( host )
1136
- end
1137
- end
1138
-
1139
- end
1140
-
1141
- describe '#sleep_until_puppetserver_started' do
1142
- let( :options ) { Beaker::Options::Presets.new.presets }
1143
- before :each do
1144
- allow( subject ).to receive( :options ) { options }
1145
- end
1146
-
1147
- it 'uses the default port if none given' do
1148
- host = hosts[0]
1149
- expect( subject ).to receive( :curl_with_retries ).with( anything(), anything(), /8140/, anything() ).once.ordered
1150
- subject.sleep_until_puppetserver_started( host )
1151
- end
1152
-
1153
- it 'allows setting the port' do
1154
- host = hosts[0]
1155
- expect( subject ).to receive( :curl_with_retries ).with( anything(), anything(), /8147/, anything() ).once.ordered
1156
- subject.sleep_until_puppetserver_started( host, 8147 )
1157
- end
1158
- end
1159
-
1160
- describe '#sleep_until_nc_started' do
1161
- let( :options ) { Beaker::Options::Presets.new.presets }
1162
- before :each do
1163
- allow( subject ).to receive( :options ) { options }
1164
- end
1165
-
1166
- it 'uses the default port if none given' do
1167
- host = hosts[0]
1168
- expect( subject ).to receive( :curl_with_retries ).with( anything(), anything(), /4433/, anything() ).once.ordered
1169
- subject.sleep_until_nc_started( host )
1170
- end
1171
-
1172
- it 'allows setting the port' do
1173
- host = hosts[0]
1174
- expect( subject ).to receive( :curl_with_retries ).with( anything(), anything(), /4435/, anything() ).once.ordered
1175
- subject.sleep_until_nc_started( host, 4435 )
1176
- end
1177
- end
1178
-
1179
- end