beaker 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -812,6 +812,86 @@ describe ClassMixedWithDSLInstallUtils do
812
812
 
813
813
  end
814
814
 
815
+ describe '#install_puppetagent_dev_repo' do
816
+
817
+ it 'raises an exception when host platform is unsupported' do
818
+ platform = Object.new()
819
+ allow(platform).to receive(:to_array) { ['ptan', '5', 'x4']}
820
+ host = basic_hosts.first
821
+ host['platform'] = platform
822
+ opts = { :version => '0.1.0' }
823
+ allow( subject ).to receive( :options ).and_return( {} )
824
+
825
+ expect{
826
+ subject.install_puppetagent_dev_repo( host, opts )
827
+ }.to raise_error(RuntimeError, /No repository installation step for/)
828
+ end
829
+
830
+ it 'runs the correct install for el-based platforms' do
831
+ platform = Object.new()
832
+ allow(platform).to receive(:to_array) { ['el', '5', 'x4']}
833
+ host = basic_hosts.first
834
+ host['platform'] = platform
835
+ opts = { :version => '0.1.0' }
836
+ allow( subject ).to receive( :options ).and_return( {} )
837
+
838
+ expect(subject).to receive(:fetch_http_file).once.with(/\/el\//, /-agent-/, /el/)
839
+ expect(subject).to receive(:scp_to).once.with(host, /-agent-/, "/root")
840
+ expect(subject).to receive(:on).once.with(host, /rpm\ -ivh/)
841
+
842
+ subject.install_puppetagent_dev_repo( host, opts )
843
+ end
844
+
845
+ it 'runs the correct install for debian-based platforms' do
846
+ platform = Object.new()
847
+ allow(platform).to receive(:to_array) { ['debian', '5', 'x4']}
848
+ host = basic_hosts.first
849
+ host['platform'] = platform
850
+ opts = { :version => '0.1.0' }
851
+ allow( subject ).to receive( :options ).and_return( {} )
852
+
853
+ expect(subject).to receive(:fetch_http_file).once.with(/\/deb\//, /-agent_/, /deb/)
854
+ expect(subject).to receive(:scp_to).once.with(host, /-agent_/, "/root")
855
+ expect(subject).to receive(:on).ordered.with(host, /dpkg\ -i\ --force-all/)
856
+ expect(subject).to receive(:on).ordered.with(host, /apt-get\ update/)
857
+
858
+ subject.install_puppetagent_dev_repo( host, opts )
859
+ end
860
+
861
+ it 'allows you to override the local copy directory' do
862
+ platform = Object.new()
863
+ allow(platform).to receive(:to_array) { ['debian', '5', 'x4']}
864
+ host = basic_hosts.first
865
+ host['platform'] = platform
866
+ opts = { :version => '0.1.0', :copy_base_local => 'face' }
867
+ allow( subject ).to receive( :options ).and_return( {} )
868
+
869
+ expect(subject).to receive(:fetch_http_file).once.with(/\/deb\//, /-agent_/, /face/)
870
+ expect(subject).to receive(:scp_to).once.with(host, /face/, "/root")
871
+ expect(subject).to receive(:on).ordered.with(host, /dpkg\ -i\ --force-all/)
872
+ expect(subject).to receive(:on).ordered.with(host, /apt-get\ update/)
873
+
874
+ subject.install_puppetagent_dev_repo( host, opts )
875
+ end
876
+
877
+ it 'allows you to override the external copy directory' do
878
+ platform = Object.new()
879
+ allow(platform).to receive(:to_array) { ['debian', '5', 'x4']}
880
+ host = basic_hosts.first
881
+ host['platform'] = platform
882
+ opts = { :version => '0.1.0', :copy_dir_external => 'muppetsB' }
883
+ allow( subject ).to receive( :options ).and_return( {} )
884
+
885
+ expect(subject).to receive(:fetch_http_file).once.with(/\/deb\//, /-agent_/, /deb/)
886
+ expect(subject).to receive(:scp_to).once.with(host, /-agent_/, /muppetsB/)
887
+ expect(subject).to receive(:on).ordered.with(host, /dpkg\ -i\ --force-all/)
888
+ expect(subject).to receive(:on).ordered.with(host, /apt-get\ update/)
889
+
890
+ subject.install_puppetagent_dev_repo( host, opts )
891
+ end
892
+
893
+ end
894
+
815
895
  describe '#install_dev_puppet_module_on' do
816
896
  context 'having set allow( a ).to receive forge' do
817
897
  it 'stubs the forge on the host' do
@@ -292,21 +292,10 @@ describe Beaker do
292
292
  context "sync_root_keys" do
293
293
  subject { dummy_class.new }
294
294
 
295
- it "can sync keys on a solaris host" do
295
+ it "can sync keys on a solaris/eos host" do
296
296
  @platform = 'solaris'
297
297
 
298
- expect( Beaker::Command ).to receive( :new ).with( sync_cmd % "| bash" ).exactly( 3 ).times
299
-
300
- subject.sync_root_keys( hosts, options )
301
-
302
- end
303
-
304
- it "can sync keys on an eos host" do
305
- @platform = 'eos'
306
-
307
- expect( Beaker::Command ).to receive( :new ).with( sync_cmd % "> manage_root_authorized_keys" ).exactly( 3 ).times
308
- expect( Beaker::Command ).to receive( :new ).with( "sed -i 's|mv -f $SSH_HOME/authorized_keys.tmp $SSH_HOME/authorized_keys|cp -f $SSH_HOME/authorized_keys.tmp $SSH_HOME/authorized_keys|' manage_root_authorized_keys" ).exactly( 3 ).times
309
- expect( Beaker::Command ).to receive( :new ).with( "bash manage_root_authorized_keys" ).exactly( 3 ).times
298
+ expect( Beaker::Command ).to receive( :new ).with( sync_cmd % "bash" ).exactly( 3 ).times
310
299
 
311
300
  subject.sync_root_keys( hosts, options )
312
301
 
@@ -314,7 +303,7 @@ describe Beaker do
314
303
 
315
304
  it "can sync keys on a non-solaris host" do
316
305
 
317
- expect( Beaker::Command ).to receive( :new ).with( sync_cmd % "| env PATH=/usr/gnu/bin:$PATH bash" ).exactly( 3 ).times
306
+ expect( Beaker::Command ).to receive( :new ).with( sync_cmd % "env PATH=/usr/gnu/bin:$PATH bash" ).exactly( 3 ).times
318
307
 
319
308
  subject.sync_root_keys( hosts, options )
320
309
 
@@ -449,7 +438,7 @@ describe Beaker do
449
438
 
450
439
  it "can set the environment on a windows host" do
451
440
  commands = [
452
- "echo 'PermitUserEnvironment yes\n' >> /etc/sshd_config",
441
+ "echo '\nPermitUserEnvironment yes' >> /etc/sshd_config",
453
442
  "cygrunsrv -E sshd",
454
443
  "cygrunsrv -S sshd"
455
444
  ]
@@ -458,7 +447,7 @@ describe Beaker do
458
447
 
459
448
  it "can set the environment on an OS X host" do
460
449
  commands = [
461
- "echo 'PermitUserEnvironment yes\n' >> /etc/sshd_config",
450
+ "echo '\nPermitUserEnvironment yes' >> /etc/sshd_config",
462
451
  "launchctl unload /System/Library/LaunchDaemons/ssh.plist",
463
452
  "launchctl load /System/Library/LaunchDaemons/ssh.plist"
464
453
  ]
@@ -467,7 +456,7 @@ describe Beaker do
467
456
 
468
457
  it "can set the environment on an ssh-based linux host" do
469
458
  commands = [
470
- "echo 'PermitUserEnvironment yes\n' >> /etc/ssh/sshd_config",
459
+ "echo '\nPermitUserEnvironment yes' >> /etc/ssh/sshd_config",
471
460
  "service ssh restart"
472
461
  ]
473
462
  set_env_helper('ubuntu', commands)
@@ -475,15 +464,15 @@ describe Beaker do
475
464
 
476
465
  it "can set the environment on an sshd-based linux host" do
477
466
  commands = [
478
- "echo 'PermitUserEnvironment yes\n' >> /etc/ssh/sshd_config",
479
- "service sshd restart"
467
+ "echo '\nPermitUserEnvironment yes' >> /etc/ssh/sshd_config",
468
+ "/sbin/service sshd restart"
480
469
  ]
481
470
  set_env_helper('eos', commands)
482
471
  end
483
472
 
484
473
  it "can set the environment on an sles host" do
485
474
  commands = [
486
- "echo 'PermitUserEnvironment yes\n' >> /etc/ssh/sshd_config",
475
+ "echo '\nPermitUserEnvironment yes' >> /etc/ssh/sshd_config",
487
476
  "rcsshd restart"
488
477
  ]
489
478
  set_env_helper('sles', commands)
@@ -491,7 +480,7 @@ describe Beaker do
491
480
 
492
481
  it "can set the environment on a solaris host" do
493
482
  commands = [
494
- "echo 'PermitUserEnvironment yes\n' >> /etc/ssh/sshd_config",
483
+ "echo '\nPermitUserEnvironment yes' >> /etc/ssh/sshd_config",
495
484
  "svcadm restart svc:/network/ssh:default"
496
485
  ]
497
486
  set_env_helper('solaris', commands)
@@ -499,7 +488,7 @@ describe Beaker do
499
488
 
500
489
  it "can set the environment on an aix host" do
501
490
  commands = [
502
- "echo 'PermitUserEnvironment yes\n' >> /etc/ssh/sshd_config",
491
+ "echo '\nPermitUserEnvironment yes' >> /etc/ssh/sshd_config",
503
492
  "stopsrc -g ssh",
504
493
  "startsrc -g ssh"
505
494
  ]
@@ -520,6 +509,9 @@ describe Beaker do
520
509
  host_specific_commands_array.each do |command|
521
510
  expect( Beaker::Command ).to receive( :new ).with( command ).once
522
511
  end
512
+
513
+ expect( Beaker::Command ).to receive( :new ).with( "mkdir -p #{Pathname.new(host[:ssh_env_file]).dirname}" ).once
514
+ expect( Beaker::Command ).to receive( :new ).with( "chmod 0600 #{Pathname.new(host[:ssh_env_file]).dirname}" ).once
523
515
  expect( Beaker::Command ).to receive( :new ).with( "touch #{host[:ssh_env_file]}" ).once
524
516
  expect( host ).to receive( :add_env_var ).with( 'RUBYLIB', '$RUBYLIB' ).once
525
517
  expect( host ).to receive( :add_env_var ).with( 'PATH', '$PATH' ).once
@@ -527,7 +519,7 @@ describe Beaker do
527
519
  expect( host ).to receive( :add_env_var ).with( key, value ).once
528
520
  end
529
521
  expect( host ).to receive( :add_env_var ).with( 'CYGWIN', 'nodosfilewarning' ).once if platform_name =~ /windows/
530
- expect( host ).to receive( :exec ).exactly( host_specific_commands_array.length + 1 ).times
522
+ expect( host ).to receive( :exec ).exactly( host_specific_commands_array.length + 3 ).times
531
523
 
532
524
  subject.set_env(host, options.merge( opts ))
533
525
  end
@@ -233,10 +233,22 @@ module Beaker
233
233
  host.instance_variable_set :@connection, conn
234
234
  end
235
235
 
236
- it 'takes a command object and a hash of options'
237
- it "acts on the host's logger and connection object"
238
- it 'receives a result object from the connection#execute'
239
- it "returns the result object"
236
+ it 'takes a command object and a hash of options' do
237
+ result.exit_code = 0
238
+ expect{ host.exec(command, {}) }.to_not raise_error
239
+ end
240
+
241
+ it 'acts on the host\'s logger and connection object' do
242
+ result.exit_code = 0
243
+ expect( host.instance_variable_get(:@logger) ).to receive(:debug).at_least(1).times
244
+ expect( host.instance_variable_get(:@connection) ).to receive(:execute).once
245
+ host.exec(command)
246
+ end
247
+
248
+ it 'returns the result object' do
249
+ result.exit_code = 0
250
+ expect( host.exec(command) ).to be === result
251
+ end
240
252
 
241
253
  it 'logs the amount of time spent executing the command' do
242
254
  result.exit_code = 0
@@ -372,11 +384,11 @@ module Beaker
372
384
 
373
385
  (@fileset1 + @fileset2).each do |file|
374
386
  if file !~ /#{exclude_file}/
375
- file_args = [ file, File.join(target_path, file.gsub(source_path,'')), {:ignore => [exclude_file]} ]
387
+ file_args = [ file, File.join(target_path, File.dirname(file).gsub(source_path,'')), {:ignore => [exclude_file]} ]
376
388
  conn_args = file_args + [ nil ]
377
389
  expect( conn ).to receive(:scp_to).with( *conn_args ).and_return(Beaker::Result.new(host, 'output!'))
378
390
  else
379
- file_args = [ file, File.join(target_path, file.gsub(source_path,'')), {:ignore => [exclude_file]} ]
391
+ file_args = [ file, File.join(target_path, File.dirname(file).gsub(source_path,'')), {:ignore => [exclude_file]} ]
380
392
  conn_args = file_args + [ nil ]
381
393
  expect( conn ).to_not receive(:scp_to).with( *conn_args )
382
394
  end
@@ -433,9 +445,13 @@ module Beaker
433
445
  expect( host ).to receive( :mkdir_p ).with('target/tmp/tests2')
434
446
  (@fileset1 + @fileset2).each do |file|
435
447
  if file !~ /#{exclude_file}/
436
- file_args = [ file, File.join('target', file), {:ignore => [exclude_file]} ]
448
+ file_args = [ file, File.join('target', File.dirname(file)), {:ignore => [exclude_file]} ]
437
449
  conn_args = file_args + [ nil ]
438
450
  expect( conn ).to receive(:scp_to).with( *conn_args ).and_return(Beaker::Result.new(host, 'output!'))
451
+ else
452
+ file_args = [ file, File.join('target', File.dirname(file)), {:ignore => [exclude_file]} ]
453
+ conn_args = file_args + [ nil ]
454
+ expect( conn ).to_not receive(:scp_to).with( *conn_args )
439
455
  end
440
456
  end
441
457
 
@@ -453,9 +469,15 @@ module Beaker
453
469
  allow( Dir ).to receive( :glob ).and_return( @fileset1 + @fileset2 )
454
470
 
455
471
  expect( logger ).to receive(:trace)
472
+ expect( host ).to_not receive( :mkdir_p ).with('target/tmp/tests')
456
473
  expect( host ).to receive( :mkdir_p ).with('target/tmp/tests2')
474
+ (@fileset1).each do |file|
475
+ file_args = [ file, File.join('target', File.dirname(file)), {:ignore => [exclude_file]} ]
476
+ conn_args = file_args + [ nil ]
477
+ expect( conn ).to_not receive(:scp_to).with( *conn_args )
478
+ end
457
479
  (@fileset2).each do |file|
458
- file_args = [ file, File.join('target', file), {:ignore => [exclude_file]} ]
480
+ file_args = [ file, File.join('target', File.dirname(file)), {:ignore => [exclude_file]} ]
459
481
  conn_args = file_args + [ nil ]
460
482
  expect( conn ).to receive(:scp_to).with( *conn_args ).and_return(Beaker::Result.new(host, 'output!'))
461
483
  end
@@ -22,6 +22,11 @@ module Beaker
22
22
  logger
23
23
  end
24
24
 
25
+ let(:options) {{
26
+ :logger => logger,
27
+ :forward_ssh_agent => true,
28
+ }}
29
+
25
30
  let(:image) do
26
31
  image = double('Docker::Image')
27
32
  allow( image ).to receive(:id)
@@ -52,7 +57,7 @@ module Beaker
52
57
  container
53
58
  end
54
59
 
55
- let (:docker) { ::Beaker::Docker.new( hosts, { :logger => logger }) }
60
+ let (:docker) { ::Beaker::Docker.new( hosts, options ) }
56
61
  let(:docker_options) { nil }
57
62
 
58
63
  before :each do
@@ -165,6 +170,18 @@ module Beaker
165
170
  expect( hosts[0]['ip'] ).to be === '192.0.2.2'
166
171
  expect( hosts[0]['port'] ).to be === 8022
167
172
  end
173
+
174
+ it 'should have ssh agent forwarding enabled' do
175
+ ENV['DOCKER_HOST'] = nil
176
+ docker.provision
177
+
178
+ expect( hosts[0]['ip'] ).to be === '127.0.1.1'
179
+ expect( hosts[0]['port'] ).to be === 8022
180
+ expect( hosts[0]['ssh'][:password] ).to be === 'root'
181
+ expect( hosts[0]['ssh'][:port] ).to be === 8022
182
+ expect( hosts[0]['ssh'][:forward_agent] ).to be === true
183
+ end
184
+
168
185
  end
169
186
 
170
187
  it 'should record the image and container for later' do
@@ -89,6 +89,30 @@ module Beaker
89
89
  end
90
90
  end
91
91
 
92
+ context 'if :configure option set false' do
93
+ it 'does not make any configure calls' do
94
+ options[:configure] = false
95
+ options[:timesync] = true
96
+ options[:root_keys] = true
97
+ options[:add_el_extras] = true
98
+ options[:disable_iptables] = true
99
+ expect( hypervisor ).to_not receive( :timesync )
100
+ expect( hypervisor ).to_not receive( :sync_root_keys )
101
+ expect( hypervisor ).to_not receive( :add_el_extras )
102
+ expect( hypervisor ).to_not receive( :disable_iptables )
103
+ expect( hypervisor ).to_not receive( :set_env )
104
+ hypervisor.configure
105
+ end
106
+ end
107
+
108
+ context 'if :configure option set true' do
109
+ it 'does call set_env' do
110
+ options[:configure] = true
111
+ expect( hypervisor ).to receive( :set_env ).once
112
+ hypervisor.configure
113
+ end
114
+ end
115
+
92
116
  end
93
117
 
94
118
  end
@@ -2,7 +2,15 @@ require 'spec_helper'
2
2
 
3
3
  module Beaker
4
4
  describe Vagrant do
5
- let( :options ) { make_opts.merge({ 'logger' => double().as_null_object, :hosts_file => 'sample.cfg' }) }
5
+
6
+ let( :options ) {
7
+ make_opts.merge({
8
+ 'logger' => double().as_null_object,
9
+ :hosts_file => 'sample.cfg',
10
+ :forward_ssh_agent => true,
11
+ })
12
+ }
13
+
6
14
  let( :vagrant ) { Beaker::Vagrant.new( @hosts, options ) }
7
15
 
8
16
  before :each do
@@ -31,8 +39,7 @@ Vagrant.configure("2") do |c|
31
39
  v.vm.box = 'vm1_of_my_box'
32
40
  v.vm.box_url = 'http://address.for.my.box.vm1'
33
41
  v.vm.box_check_update = 'true'
34
- v.vm.base_mac = '0123456789'
35
- v.vm.network :private_network, ip: "ip.address.for.vm1", :netmask => "255.255.0.0"
42
+ v.vm.network :private_network, ip: "ip.address.for.vm1", :netmask => "255.255.0.0", :mac => "0123456789"
36
43
  v.vm.provider :virtualbox do |vb|
37
44
  vb.customize ['modifyvm', :id, '--memory', '1024']
38
45
  end
@@ -42,8 +49,7 @@ Vagrant.configure("2") do |c|
42
49
  v.vm.box = 'vm2_of_my_box'
43
50
  v.vm.box_url = 'http://address.for.my.box.vm2'
44
51
  v.vm.box_check_update = 'true'
45
- v.vm.base_mac = '0123456789'
46
- v.vm.network :private_network, ip: "ip.address.for.vm2", :netmask => "255.255.0.0"
52
+ v.vm.network :private_network, ip: "ip.address.for.vm2", :netmask => "255.255.0.0", :mac => "0123456789"
47
53
  v.vm.provider :virtualbox do |vb|
48
54
  vb.customize ['modifyvm', :id, '--memory', '1024']
49
55
  end
@@ -53,8 +59,7 @@ Vagrant.configure("2") do |c|
53
59
  v.vm.box = 'vm3_of_my_box'
54
60
  v.vm.box_url = 'http://address.for.my.box.vm3'
55
61
  v.vm.box_check_update = 'true'
56
- v.vm.base_mac = '0123456789'
57
- v.vm.network :private_network, ip: "ip.address.for.vm3", :netmask => "255.255.0.0"
62
+ v.vm.network :private_network, ip: "ip.address.for.vm3", :netmask => "255.255.0.0", :mac => "0123456789"
58
63
  v.vm.provider :virtualbox do |vb|
59
64
  vb.customize ['modifyvm', :id, '--memory', '1024']
60
65
  end
@@ -63,6 +68,17 @@ end
63
68
  EOF
64
69
  end
65
70
 
71
+ it "can make a Vagrantfile with ssh agent forwarding enabled" do
72
+ path = vagrant.instance_variable_get( :@vagrant_path )
73
+ allow( vagrant ).to receive( :randmac ).and_return( "0123456789" )
74
+
75
+ hosts = make_hosts({},1)
76
+ vagrant.make_vfile( hosts, options )
77
+
78
+ vagrantfile = File.read( File.expand_path( File.join( path, "Vagrantfile")))
79
+ expect( vagrantfile ).to match(/(ssh.forward_agent = true)/)
80
+ end
81
+
66
82
  it "generates a valid windows config" do
67
83
  path = vagrant.instance_variable_get( :@vagrant_path )
68
84
  allow( vagrant ).to receive( :randmac ).and_return( "0123456789" )
@@ -44,6 +44,20 @@ module Beaker
44
44
 
45
45
  end
46
46
 
47
+ it 'provisions hosts if no snapshot is provided' do
48
+ MockVsphereHelper.powerOff
49
+ hosts = make_hosts()
50
+ hosts[0]["snapshot"] = nil
51
+ vsphere = Beaker::Vsphere.new( hosts, make_opts )
52
+
53
+ vsphere.provision
54
+
55
+ hosts.each do |host|
56
+ expect( MockVsphereHelper.find_vm( host.name ).powerState ) == "poweredOn"
57
+ end
58
+
59
+ end
60
+
47
61
  end
48
62
 
49
63
  describe "#cleanup" do
@@ -9,6 +9,8 @@ module Beaker
9
9
  let(:full_opts) {["--hosts", "host.cfg", "--options", "opts_file", "--type", "pe", "--helper", "path_to_helper", "--load-path", "load_path", "--tests", "test1.rb,test2.rb,test3.rb", "--pre-suite", "pre_suite.rb", "--post-suite", "post_suite.rb", "--no-provision", "--preserve-hosts", "always", "--root-keys", "--keyfile", "../.ssh/id_rsa", "--install", "gitrepopath", "-m", "module", "-q", "--dry-run", "--no-ntp", "--repo-proxy", "--add-el-extras", "--config", "anotherfile.cfg", "--fail-mode", "fast", "--no-color", "--version", "--log-level", "info", "--package-proxy", "http://192.168.100.1:3128", "--collect-perf-data", "--parse-only", "--validate", "--timeout", "40"]}
10
10
  let(:validate_true) {["--validate"]}
11
11
  let(:validate_false) {["--no-validate"]}
12
+ let(:configure_true) {['--configure']}
13
+ let(:configure_false) {['--no-configure']}
12
14
 
13
15
 
14
16
  it "can correctly read command line input" do
@@ -24,6 +26,11 @@ module Beaker
24
26
  expect(parser.parse(validate_false)).to be === {:validate=>false}
25
27
  end
26
28
 
29
+ it 'supports both configure options' do
30
+ expect(parser.parse(configure_true)).to be === {:configure=>true}
31
+ expect(parser.parse(configure_false)).to be === {:configure=>false}
32
+ end
33
+
27
34
  it "can produce a usage description" do
28
35
  expect{parser.usage}.to_not raise_error
29
36
  end