beaker 1.12.2 → 1.13.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  module Beaker
2
2
  module Version
3
- STRING = '1.12.2'
3
+ STRING = '1.13.0'
4
4
  end
5
5
  end
@@ -210,6 +210,74 @@ describe ClassMixedWithDSLHelpers do
210
210
  end
211
211
  end
212
212
 
213
+ describe '#create_tmpdir_for_user' do
214
+ let(:host) { double.as_null_object }
215
+ let(:result) { double.as_null_object }
216
+
217
+ before :each do
218
+ allow(host).to receive(:result).and_return(result)
219
+ allow(result).to receive(:exit_code).and_return(0)
220
+ allow(result).to receive(:stdout).and_return('puppet')
221
+ end
222
+
223
+ context 'with no user argument' do
224
+
225
+ context 'with no path name argument' do
226
+ context 'without puppet installed on host' do
227
+ it 'raises an error' do
228
+ allow(host).to receive(:tmpdir).and_return("tmpdirname")
229
+ allow(result).to receive(:exit_code).and_return(1)
230
+ expect(subject).to receive(:on).with(host, /^puppet.*/).and_return(result)
231
+ expect{
232
+ subject.create_tmpdir_for_user host
233
+ }.to raise_error(RuntimeError, /`puppet master --configprint` failed,/)
234
+ end
235
+ end
236
+ context 'with puppet installed on host' do
237
+ it 'executes chown once' do
238
+ expect(subject).to receive(:on).with(host, /^puppet.*/).and_return(result)
239
+ expect(subject).to receive(:on).with(host, /^getent passwd puppet/).and_return(result)
240
+ expect(host).to receive(:tmpdir).with(/\/tmp\/beaker.*/)
241
+ expect(subject).to receive(:on).with(host, /chown puppet.puppet.*/)
242
+ subject.create_tmpdir_for_user(host)
243
+ end
244
+ end
245
+ end
246
+
247
+ context 'with path name argument' do
248
+ it 'executes chown once' do
249
+ expect(subject).to receive(:on).with(host, /^puppet.*/).and_return(result)
250
+ expect(subject).to receive(:on).with(host, /^getent passwd puppet/).and_return(result)
251
+ expect(host).to receive(:tmpdir).with(/\/tmp\/bogus.*/).and_return("/tmp/bogus")
252
+ expect(subject).to receive(:on).with(host, /chown puppet.puppet \/tmp\/bogus.*/)
253
+ subject.create_tmpdir_for_user(host, "/tmp/bogus")
254
+ end
255
+ end
256
+
257
+ end
258
+
259
+ context 'with an invalid user argument' do
260
+ it 'executes chown once' do
261
+ allow(result).to receive(:stdout).and_return('curiousgeorge')
262
+ expect(subject).to receive(:on).with(host, /^getent passwd curiousgeorge/).and_return(result)
263
+ expect(host).to receive(:tmpdir).with(/\/tmp\/bogus.*/).and_return("/tmp/bogus")
264
+ expect(subject).to receive(:on).with(host, /chown curiousgeorge.curiousgeorge \/tmp\/bogus.*/)
265
+ subject.create_tmpdir_for_user(host, "/tmp/bogus", "curiousgeorge")
266
+ end
267
+ end
268
+
269
+ context 'with a valid user argument' do
270
+ it 'executes chown once' do
271
+ allow(result).to receive(:exit_code).and_return(1)
272
+ expect(subject).to receive(:on).with(host, /^getent passwd curiousgeorge/).and_return(result)
273
+ expect{
274
+ subject.create_tmpdir_for_user(host, "/tmp/bogus", "curiousgeorge")
275
+ }.to raise_error(RuntimeError, /User curiousgeorge does not exist on/)
276
+ end
277
+ end
278
+
279
+ end
280
+
213
281
  describe '#run_script_on' do
214
282
  it 'scps the script to a tmpdir and executes it on host(s)' do
215
283
  subject.should_receive( :scp_to )
@@ -320,7 +388,7 @@ describe ClassMixedWithDSLHelpers do
320
388
  it 'calls puppet' do
321
389
  subject.should_receive( :create_remote_file ).and_return( true )
322
390
  subject.should_receive( :puppet ).
323
- with( 'apply', '--verbose', 'agent' ).
391
+ # with( 'apply', '--verbose', 'agent' ).
324
392
  and_return( 'puppet_command' )
325
393
 
326
394
  subject.should_receive( :on ).
@@ -336,22 +404,19 @@ describe ClassMixedWithDSLHelpers do
336
404
  subject.should_receive( :create_remote_file ).twice.and_return( true )
337
405
  the_hosts.each do |host|
338
406
  subject.should_receive( :puppet ).
339
- with( 'apply', '--verbose', host.to_s ).
340
407
  and_return( 'puppet_command' )
341
408
 
342
409
  subject.should_receive( :on ).
343
- with( host, 'puppet_command',
344
- :acceptable_exit_codes => [0, 1] ).ordered
410
+ with( host, 'puppet_command', :acceptable_exit_codes => [0] )
345
411
  end
346
412
 
347
- result = subject.apply_manifest_on( the_hosts, 'include foobar', :acceptable_exit_codes => [0,1] )
413
+ result = subject.apply_manifest_on( the_hosts, 'include foobar' )
348
414
  result.should(be_an(Array))
349
415
  end
350
416
 
351
417
  it 'adds acceptable exit codes with :catch_failures' do
352
418
  subject.should_receive( :create_remote_file ).and_return( true )
353
419
  subject.should_receive( :puppet ).
354
- with( 'apply', '--verbose', '--trace', '--detailed-exitcodes', 'agent' ).
355
420
  and_return( 'puppet_command' )
356
421
 
357
422
  subject.should_receive( :on ).
@@ -360,13 +425,11 @@ describe ClassMixedWithDSLHelpers do
360
425
 
361
426
  subject.apply_manifest_on( agent,
362
427
  'class { "boo": }',
363
- :trace => true,
364
428
  :catch_failures => true )
365
429
  end
366
430
  it 'allows acceptable exit codes through :catch_failures' do
367
431
  subject.should_receive( :create_remote_file ).and_return( true )
368
432
  subject.should_receive( :puppet ).
369
- with( 'apply', '--verbose', '--trace', '--detailed-exitcodes', 'agent' ).
370
433
  and_return( 'puppet_command' )
371
434
 
372
435
  subject.should_receive( :on ).
@@ -376,13 +439,11 @@ describe ClassMixedWithDSLHelpers do
376
439
  subject.apply_manifest_on( agent,
377
440
  'class { "boo": }',
378
441
  :acceptable_exit_codes => [4],
379
- :trace => true,
380
442
  :catch_failures => true )
381
443
  end
382
444
  it 'enforces a 0 exit code through :catch_changes' do
383
445
  subject.should_receive( :create_remote_file ).and_return( true )
384
446
  subject.should_receive( :puppet ).
385
- with( 'apply', '--verbose', '--trace', '--detailed-exitcodes', 'agent' ).
386
447
  and_return( 'puppet_command' )
387
448
 
388
449
  subject.should_receive( :on ).with(
@@ -394,14 +455,12 @@ describe ClassMixedWithDSLHelpers do
394
455
  subject.apply_manifest_on(
395
456
  agent,
396
457
  'class { "boo": }',
397
- :trace => true,
398
458
  :catch_changes => true
399
459
  )
400
460
  end
401
461
  it 'enforces a 2 exit code through :expect_changes' do
402
462
  subject.should_receive( :create_remote_file ).and_return( true )
403
463
  subject.should_receive( :puppet ).
404
- with( 'apply', '--verbose', '--trace', '--detailed-exitcodes', 'agent' ).
405
464
  and_return( 'puppet_command' )
406
465
 
407
466
  subject.should_receive( :on ).with(
@@ -413,14 +472,12 @@ describe ClassMixedWithDSLHelpers do
413
472
  subject.apply_manifest_on(
414
473
  agent,
415
474
  'class { "boo": }',
416
- :trace => true,
417
475
  :expect_changes => true
418
476
  )
419
477
  end
420
478
  it 'enforces exit codes through :expect_failures' do
421
479
  subject.should_receive( :create_remote_file ).and_return( true )
422
480
  subject.should_receive( :puppet ).
423
- with( 'apply', '--verbose', '--trace', '--detailed-exitcodes', 'agent' ).
424
481
  and_return( 'puppet_command' )
425
482
 
426
483
  subject.should_receive( :on ).with(
@@ -432,7 +489,6 @@ describe ClassMixedWithDSLHelpers do
432
489
  subject.apply_manifest_on(
433
490
  agent,
434
491
  'class { "boo": }',
435
- :trace => true,
436
492
  :expect_failures => true
437
493
  )
438
494
  end
@@ -441,7 +497,6 @@ describe ClassMixedWithDSLHelpers do
441
497
  subject.apply_manifest_on(
442
498
  agent,
443
499
  'class { "boo": }',
444
- :trace => true,
445
500
  :expect_failures => true,
446
501
  :catch_failures => true
447
502
  )
@@ -450,7 +505,6 @@ describe ClassMixedWithDSLHelpers do
450
505
  it 'enforces added exit codes through :expect_failures' do
451
506
  subject.should_receive( :create_remote_file ).and_return( true )
452
507
  subject.should_receive( :puppet ).
453
- with( 'apply', '--verbose', '--trace', '--detailed-exitcodes', 'agent' ).
454
508
  and_return( 'puppet_command' )
455
509
 
456
510
  subject.should_receive( :on ).with(
@@ -463,27 +517,46 @@ describe ClassMixedWithDSLHelpers do
463
517
  agent,
464
518
  'class { "boo": }',
465
519
  :acceptable_exit_codes => (1..5),
466
- :trace => true,
467
520
  :expect_failures => true
468
521
  )
469
522
  end
470
523
 
471
524
  it 'can set the --parser future flag' do
472
525
  subject.should_receive( :create_remote_file ).and_return( true )
473
- subject.should_receive( :puppet ).
474
- with( 'apply', '--verbose', '--parser future', '--detailed-exitcodes', 'agent' ).
475
- and_return( 'puppet_command' )
476
- subject.should_receive( :on ).with(
526
+
527
+ expect( subject ).to receive( :on ).with {|h, command, opts|
528
+ cmdline = command.cmd_line( h )
529
+ expect( h ).to be == agent
530
+ expect( cmdline ).to include('puppet apply')
531
+ expect( cmdline ).to include('--parser=future')
532
+ expect( cmdline ).to include('--detailed-exitcodes')
533
+ expect( cmdline ).to include('--verbose')
534
+ }
535
+
536
+ subject.apply_manifest_on(
477
537
  agent,
478
- 'puppet_command',
479
- :acceptable_exit_codes => [1,2,3,4,5,6]
538
+ 'class { "boo": }',
539
+ :acceptable_exit_codes => (1..5),
540
+ :future_parser => true,
541
+ :expect_failures => true
480
542
  )
543
+ end
481
544
 
545
+ it 'can set the --noops flag' do
546
+ subject.should_receive( :create_remote_file ).and_return( true )
547
+ expect( subject ).to receive( :on ).with {|h, command, opts|
548
+ cmdline = command.cmd_line( h )
549
+ expect( h ).to be == agent
550
+ expect( cmdline ).to include('puppet apply')
551
+ expect( cmdline ).to include('--detailed-exitcodes')
552
+ expect( cmdline ).to include('--verbose')
553
+ expect( cmdline ).to include('--noop')
554
+ }
482
555
  subject.apply_manifest_on(
483
556
  agent,
484
557
  'class { "boo": }',
485
558
  :acceptable_exit_codes => (1..5),
486
- :future_parser => true,
559
+ :noop => true,
487
560
  :expect_failures => true
488
561
  )
489
562
  end
@@ -297,6 +297,16 @@ describe ClassMixedWithDSLInstallUtils do
297
297
  expect(subject).to receive(:on).with(hosts[0], 'yum install -y puppet')
298
298
  subject.install_puppet
299
299
  end
300
+ it 'installs specific version of puppet when passed :version' do
301
+ expect(subject).to receive(:on).with(hosts[0], 'yum install -y puppet-3000')
302
+ subject.install_puppet( :version => '3000' )
303
+ end
304
+ it 'can install specific versions of puppets dependencies' do
305
+ expect(subject).to receive(:on).with(hosts[0], 'yum install -y puppet-3000')
306
+ expect(subject).to receive(:on).with(hosts[0], 'yum install -y hiera-2001')
307
+ expect(subject).to receive(:on).with(hosts[0], 'yum install -y facter-1999')
308
+ subject.install_puppet( :version => '3000', :facter_version => '1999', :hiera_version => '2001' )
309
+ end
300
310
  end
301
311
  context 'on el-5' do
302
312
  let(:platform) { "el-5-i386" }
@@ -316,30 +326,34 @@ describe ClassMixedWithDSLInstallUtils do
316
326
  end
317
327
  context 'on debian' do
318
328
  let(:platform) { "debian-7-amd64" }
319
- it 'installs' do
329
+ it 'installs latest if given no version info' do
320
330
  expect(subject).to receive(:on).with(hosts[0], /puppetlabs-release-\$\(lsb_release -c -s\)\.deb/)
321
331
  expect(subject).to receive(:on).with(hosts[0], 'dpkg -i puppetlabs-release-$(lsb_release -c -s).deb')
322
332
  expect(subject).to receive(:on).with(hosts[0], 'apt-get update')
323
333
  expect(subject).to receive(:on).with(hosts[0], 'apt-get install -y puppet')
324
334
  subject.install_puppet
325
335
  end
326
- end
327
- context 'on ubuntu' do
328
- let(:platform) { "ubuntu-12.04-amd64" }
329
- it 'installs' do
330
- expect(subject).to receive(:on).with(hosts[0], /puppetlabs-release-\$\(lsb_release -c -s\)\.deb/)
331
- expect(subject).to receive(:on).with(hosts[0], 'dpkg -i puppetlabs-release-$(lsb_release -c -s).deb')
332
- expect(subject).to receive(:on).with(hosts[0], 'apt-get update')
333
- expect(subject).to receive(:on).with(hosts[0], 'apt-get install -y puppet')
334
- subject.install_puppet
336
+ it 'installs specific version of puppet when passed :version' do
337
+ expect(subject).to receive(:on).with(hosts[0], 'apt-get install -y puppet=3000-1puppetlabs1')
338
+ subject.install_puppet( :version => '3000' )
339
+ end
340
+ it 'can install specific versions of puppets dependencies' do
341
+ expect(subject).to receive(:on).with(hosts[0], 'apt-get install -y puppet=3000-1puppetlabs1')
342
+ expect(subject).to receive(:on).with(hosts[0], 'apt-get install -y hiera=2001-1puppetlabs1')
343
+ expect(subject).to receive(:on).with(hosts[0], 'apt-get install -y facter=1999-1puppetlabs1')
344
+ subject.install_puppet( :version => '3000', :facter_version => '1999', :hiera_version => '2001' )
335
345
  end
336
346
  end
337
- context 'on solaris' do
347
+ describe 'on unsupported platforms' do
338
348
  let(:platform) { 'solaris-11-x86_64' }
339
- it 'raises an error' do
349
+ it 'by default raises an error' do
340
350
  expect(subject).to_not receive(:on)
341
351
  expect { subject.install_puppet }.to raise_error(/unsupported platform/)
342
352
  end
353
+ it 'falls back to installing from gem when given :default_action => "gem_install"' do
354
+ expect(subject).to receive(:on).with(hosts[0], /gem install/)
355
+ subject.install_puppet :default_action => 'gem_install'
356
+ end
343
357
  end
344
358
  end
345
359
 
@@ -0,0 +1,109 @@
1
+ require 'spec_helper'
2
+
3
+ module Beaker
4
+ describe Unix::Pkg do
5
+ class UnixPkgTest
6
+ include Unix::Pkg
7
+
8
+ def initialize(hash, logger)
9
+ @hash = hash
10
+ @logger = logger
11
+ end
12
+
13
+ def [](k)
14
+ @hash[k]
15
+ end
16
+
17
+ def to_s
18
+ "me"
19
+ end
20
+ end
21
+
22
+ let (:opts) { @opts || {} }
23
+ let (:logger) { double( 'logger' ).as_null_object }
24
+ let (:instance) { UnixPkgTest.new(opts, logger) }
25
+
26
+ context "check_for_package" do
27
+
28
+ it "runs the correctly on sles" do
29
+ @opts = {'platform' => 'sles-is-me'}
30
+ pkg = 'sles_package'
31
+ Beaker::Command.should_receive(:new).with("zypper se -i --match-exact #{pkg}").and_return('')
32
+ instance.should_receive(:exec).with('', :acceptable_exit_codes => (0...127)).and_return(generate_result("hello", {:exit_code => 0}))
33
+ expect( instance.check_for_package(pkg) ).to be === true
34
+ end
35
+
36
+ it "runs the correctly on fedora" do
37
+ @opts = {'platform' => 'fedora-is-me'}
38
+ pkg = 'fedora_package'
39
+ Beaker::Command.should_receive(:new).with("rpm -q #{pkg}").and_return('')
40
+ instance.should_receive(:exec).with('', :acceptable_exit_codes => (0...127)).and_return(generate_result("hello", {:exit_code => 0}))
41
+ expect( instance.check_for_package(pkg) ).to be === true
42
+ end
43
+
44
+ it "runs the correctly on centos" do
45
+ @opts = {'platform' => 'centos-is-me'}
46
+ pkg = 'centos_package'
47
+ Beaker::Command.should_receive(:new).with("rpm -q #{pkg}").and_return('')
48
+ instance.should_receive(:exec).with('', :acceptable_exit_codes => (0...127)).and_return(generate_result("hello", {:exit_code => 0}))
49
+ expect( instance.check_for_package(pkg) ).to be === true
50
+ end
51
+
52
+ it "runs the correctly on el-" do
53
+ @opts = {'platform' => 'el-is-me'}
54
+ pkg = 'el_package'
55
+ Beaker::Command.should_receive(:new).with("rpm -q #{pkg}").and_return('')
56
+ instance.should_receive(:exec).with('', :acceptable_exit_codes => (0...127)).and_return(generate_result("hello", {:exit_code => 0}))
57
+ expect( instance.check_for_package(pkg) ).to be === true
58
+ end
59
+
60
+ it "runs the correctly on debian" do
61
+ @opts = {'platform' => 'debian-is-me'}
62
+ pkg = 'debian_package'
63
+ Beaker::Command.should_receive(:new).with("dpkg -s #{pkg}").and_return('')
64
+ instance.should_receive(:exec).with('', :acceptable_exit_codes => (0...127)).and_return(generate_result("hello", {:exit_code => 0}))
65
+ expect( instance.check_for_package(pkg) ).to be === true
66
+ end
67
+
68
+ it "runs the correctly on ubuntu" do
69
+ @opts = {'platform' => 'ubuntu-is-me'}
70
+ pkg = 'ubuntu_package'
71
+ Beaker::Command.should_receive(:new).with("dpkg -s #{pkg}").and_return('')
72
+ instance.should_receive(:exec).with('', :acceptable_exit_codes => (0...127)).and_return(generate_result("hello", {:exit_code => 0}))
73
+ expect( instance.check_for_package(pkg) ).to be === true
74
+ end
75
+
76
+ it "runs the correctly on solaris-11" do
77
+ @opts = {'platform' => 'solaris-11-is-me'}
78
+ pkg = 'solaris-11_package'
79
+ Beaker::Command.should_receive(:new).with("pkg info #{pkg}").and_return('')
80
+ instance.should_receive(:exec).with('', :acceptable_exit_codes => (0...127)).and_return(generate_result("hello", {:exit_code => 0}))
81
+ expect( instance.check_for_package(pkg) ).to be === true
82
+ end
83
+
84
+ it "runs the correctly on solaris-10" do
85
+ @opts = {'platform' => 'solaris-10-is-me'}
86
+ pkg = 'solaris-10_package'
87
+ Beaker::Command.should_receive(:new).with("pkginfo #{pkg}").and_return('')
88
+ instance.should_receive(:exec).with('', :acceptable_exit_codes => (0...127)).and_return(generate_result("hello", {:exit_code => 0}))
89
+ expect( instance.check_for_package(pkg) ).to be === true
90
+ end
91
+
92
+ it "returns false for el-4" do
93
+ @opts = {'platform' => 'el-4-is-me'}
94
+ pkg = 'el-4_package'
95
+ expect( instance.check_for_package(pkg) ).to be === false
96
+ end
97
+
98
+ it "raises on unknown platform" do
99
+ @opts = {'platform' => 'nope-is-me'}
100
+ pkg = 'nope_package'
101
+ expect{ instance.check_for_package(pkg) }.to raise_error
102
+
103
+ end
104
+
105
+ end
106
+
107
+ end
108
+ end
109
+
@@ -6,7 +6,7 @@ describe Beaker do
6
6
  let( :apt_cfg ) { Beaker::HostPrebuiltSteps::APT_CFG }
7
7
  let( :ips_pkg_repo ) { Beaker::HostPrebuiltSteps::IPS_PKG_REPO }
8
8
  let( :sync_cmd ) { Beaker::HostPrebuiltSteps::ROOT_KEYS_SYNC_CMD }
9
- let( :pkgs ) { Beaker::HostPrebuiltSteps::PACKAGES }
9
+ let( :windows_pkgs ) { Beaker::HostPrebuiltSteps::WINDOWS_PACKAGES }
10
10
  let( :unix_only_pkgs ) { Beaker::HostPrebuiltSteps::UNIX_PACKAGES }
11
11
  let( :sles_only_pkgs ) { Beaker::HostPrebuiltSteps::SLES_PACKAGES }
12
12
  let( :platform ) { @platform || 'unix' }
@@ -310,10 +310,6 @@ describe Beaker do
310
310
  it "can validate unix hosts" do
311
311
 
312
312
  hosts.each do |host|
313
- pkgs.each do |pkg|
314
- host.should_receive( :check_for_package ).with( pkg ).once.and_return( false )
315
- host.should_receive( :install_package ).with( pkg ).once
316
- end
317
313
  unix_only_pkgs.each do |pkg|
318
314
  host.should_receive( :check_for_package ).with( pkg ).once.and_return( false )
319
315
  host.should_receive( :install_package ).with( pkg ).once
@@ -329,14 +325,10 @@ describe Beaker do
329
325
  @platform = 'windows'
330
326
 
331
327
  hosts.each do |host|
332
- pkgs.each do |pkg|
328
+ windows_pkgs.each do |pkg|
333
329
  host.should_receive( :check_for_package ).with( pkg ).once.and_return( false )
334
330
  host.should_receive( :install_package ).with( pkg ).once
335
331
  end
336
- unix_only_pkgs.each do |pkg|
337
- host.should_receive( :check_for_package).with( pkg ).never
338
- host.should_receive( :install_package ).with( pkg ).never
339
- end
340
332
  end
341
333
 
342
334
  subject.validate_host(hosts, logger)
@@ -347,14 +339,6 @@ describe Beaker do
347
339
  @platform = 'sles-13.1-x64'
348
340
 
349
341
  hosts.each do |host|
350
- pkgs.each do |pkg|
351
- host.should_receive( :check_for_package ).with( pkg ).once.and_return( false )
352
- host.should_receive( :install_package ).with( pkg ).once
353
- end
354
- unix_only_pkgs.each do |pkg|
355
- host.should_receive( :check_for_package).with( pkg ).never
356
- host.should_receive( :install_package ).with( pkg ).never
357
- end
358
342
  sles_only_pkgs.each do |pkg|
359
343
  host.should_receive( :check_for_package).with( pkg ).once.and_return( false )
360
344
  host.should_receive( :install_package ).with( pkg ).once