daptiv-chef-ci 0.0.15 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/daptiv-chef-ci.gemspec +21 -20
  3. data/lib/daptiv-chef-ci/clone_environment_task.rb +69 -0
  4. data/lib/daptiv-chef-ci/logger.rb +9 -10
  5. data/lib/daptiv-chef-ci/raketask_helper.rb +5 -6
  6. data/lib/daptiv-chef-ci/shell.rb +50 -28
  7. data/lib/daptiv-chef-ci/upload_cookbook_task.rb +62 -0
  8. data/lib/daptiv-chef-ci/vagrant_destroy_task.rb +11 -12
  9. data/lib/daptiv-chef-ci/vagrant_driver.rb +47 -56
  10. data/lib/daptiv-chef-ci/vagrant_provision_task.rb +12 -15
  11. data/lib/daptiv-chef-ci/vagrant_task.rb +34 -57
  12. data/lib/daptiv-chef-ci/vagrant_up_task.rb +14 -16
  13. data/lib/daptiv-chef-ci/version_cookbook_task.rb +69 -0
  14. data/lib/daptiv-chef-ci/virtualbox_driver.rb +11 -12
  15. data/spec/daptiv-chef-ci/logger_spec.rb +11 -15
  16. data/spec/daptiv-chef-ci/shell_spec.rb +23 -27
  17. data/spec/daptiv-chef-ci/vagrant_destroy_task_spec.rb +5 -7
  18. data/spec/daptiv-chef-ci/vagrant_driver_spec.rb +34 -72
  19. data/spec/daptiv-chef-ci/vagrant_provision_task_spec.rb +9 -13
  20. data/spec/daptiv-chef-ci/vagrant_task_spec.rb +29 -21
  21. data/spec/daptiv-chef-ci/vagrant_up_task_spec.rb +9 -12
  22. data/spec/daptiv-chef-ci/virtualbox_driver_spec.rb +21 -16
  23. data/spec/shared_contexts/rake.rb +7 -7
  24. metadata +21 -14
  25. data/lib/daptiv-chef-ci/basebox_builder_factory.rb +0 -19
  26. data/lib/daptiv-chef-ci/virtualbox_basebox_builder.rb +0 -33
  27. data/lib/daptiv-chef-ci/vmware_basebox_builder.rb +0 -103
  28. data/spec/daptiv-chef-ci/basebox_builder_factory_spec.rb +0 -25
  29. data/spec/daptiv-chef-ci/virtualbox_basebox_builder_spec.rb +0 -20
  30. data/spec/daptiv-chef-ci/vmware_basebox_builder_spec.rb +0 -20
@@ -2,16 +2,17 @@ require 'log4r'
2
2
  require_relative 'shell'
3
3
 
4
4
  module DaptivChefCI
5
+ # Wrapper around VBox CLI for VM cleanup
6
+ # Currently unused
5
7
  class VirtualBoxDriver
6
-
7
8
  def initialize(shell)
8
- @logger = Log4r::Logger.new("daptiv_chef_ci::virtual_box")
9
+ @logger = Log4r::Logger.new('daptiv_chef_ci::virtual_box')
9
10
  @shell = shell
10
11
  end
11
-
12
+
12
13
  # Remove any running vms that have the same name as this box
13
14
  def cleanup_vms(box_name)
14
- list_all_running_vms().each do |vm|
15
+ list_all_running_vms.each do |vm|
15
16
  if vm.include?(box_name)
16
17
  machine_name = vm.split[0]
17
18
  @logger.debug("Found matching VBox #{machine_name} - Running")
@@ -22,10 +23,9 @@ module DaptivChefCI
22
23
  end
23
24
  end
24
25
  end
25
-
26
-
27
- private
28
-
26
+
27
+ private
28
+
29
29
  # Power off the named virtual box
30
30
  def poweroff(machine_name)
31
31
  @logger.info("Powering off VM: #{machine_name}")
@@ -39,10 +39,9 @@ module DaptivChefCI
39
39
  end
40
40
 
41
41
  # Get a list of running vms
42
- def list_all_running_vms()
43
- @logger.info("List running VMs")
42
+ def list_all_running_vms
43
+ @logger.info('List running VMs')
44
44
  @shell.exec_cmd('vboxmanage list runningvms') || ''
45
45
  end
46
-
47
46
  end
48
- end
47
+ end
@@ -1,40 +1,36 @@
1
1
  require 'daptiv-chef-ci/logger'
2
2
  require 'log4r'
3
3
 
4
- describe DaptivChefCI::Logger, :unit => true do
5
-
4
+ describe DaptivChefCI::Logger, unit: true do
6
5
  describe 'init' do
7
-
8
6
  # get logging level before running any of these tests
9
7
  before(:all) do
10
8
  @chef_ci_log = ENV['CHEF_CI_LOG']
11
9
  end
12
-
10
+
13
11
  # reset logging back to starting state before this fixture
14
12
  after(:all) do
15
13
  ENV['CHEF_CI_LOG'] = @chef_ci_log
16
- DaptivChefCI::Logger.init()
14
+ DaptivChefCI::Logger.init
17
15
  end
18
-
16
+
19
17
  # reset logging back to default state before every test
20
18
  before(:each) do
21
19
  ENV['CHEF_CI_LOG'] = ''
22
- DaptivChefCI::Logger.init()
20
+ DaptivChefCI::Logger.init
23
21
  end
24
-
22
+
25
23
  it 'should initialize logging to info by default' do
26
- DaptivChefCI::Logger.init()
27
- logger = Log4r::Logger.new("daptiv_chef_ci::logger_spec")
24
+ DaptivChefCI::Logger.init
25
+ logger = Log4r::Logger.new('daptiv_chef_ci::logger_spec')
28
26
  expect(logger.level).to eq(2)
29
27
  end
30
-
28
+
31
29
  it 'should initialize logging to the specified level' do
32
30
  ENV['CHEF_CI_LOG'] = 'DEBUG'
33
- DaptivChefCI::Logger.init()
34
- logger = Log4r::Logger.new("daptiv_chef_ci::logger_spec")
31
+ DaptivChefCI::Logger.init
32
+ logger = Log4r::Logger.new('daptiv_chef_ci::logger_spec')
35
33
  expect(logger.level).to eq(1)
36
34
  end
37
-
38
35
  end
39
-
40
36
  end
@@ -3,46 +3,46 @@ require 'daptiv-chef-ci/logger'
3
3
  require 'mixlib/shellout/exceptions'
4
4
  require 'bundler'
5
5
 
6
- describe DaptivChefCI::Shell, :unit => true do
7
-
6
+ describe DaptivChefCI::Shell, unit: true do
8
7
  describe 'exec_cmd' do
9
-
10
8
  it 'should split output by line' do
11
- shell = DaptivChefCI::Shell.new()
9
+ shell = DaptivChefCI::Shell.new
12
10
  out = shell.exec_cmd('ls -l')
13
11
  expect(out.count).to be > 1
14
12
  end
15
-
13
+
16
14
  it 'should raise exception if exit status is non-zero' do
17
- shell = DaptivChefCI::Shell.new()
18
- expect { shell.exec_cmd('rm') }.to raise_error(Mixlib::ShellOut::ShellCommandFailed)
15
+ shell = DaptivChefCI::Shell.new
16
+ expect { shell.exec_cmd('rm') }
17
+ .to raise_error(Mixlib::ShellOut::ShellCommandFailed)
19
18
  end
20
-
19
+
21
20
  it 'should revert path when method returns' do
22
21
  path_before = ENV['PATH']
23
- shell = DaptivChefCI::Shell.new()
22
+ shell = DaptivChefCI::Shell.new
24
23
  shell.exec_cmd('ls -l')
25
24
  expect(ENV['PATH']).to eq(path_before)
26
25
  end
27
-
26
+
28
27
  it 'should pass long environment vars' do
29
- shell = DaptivChefCI::Shell.new()
30
- out = shell.exec_cmd('echo $ENV_VAR1', 600, { 'ENV_VAR1' => 'val1' })
28
+ shell = DaptivChefCI::Shell.new
29
+ out = shell.exec_cmd('echo $ENV_VAR1', 600, 'ENV_VAR1' => 'val1')
31
30
  expect(out[0]).to eq('val1')
32
31
  end
33
-
32
+
34
33
  it 'should convert environment symbol keys to strings' do
35
- shell = DaptivChefCI::Shell.new()
36
- out = shell.exec_cmd('echo $ENV_VAR1', 600, { :ENV_VAR1 => 'val1' })
34
+ shell = DaptivChefCI::Shell.new
35
+ out = shell.exec_cmd('echo $ENV_VAR1', 600, ENV_VAR1: 'val1')
37
36
  expect(out[0]).to eq('val1')
38
37
  end
39
38
 
40
39
  it 'should default LC_ALL environment var to nil' do
41
- # On TravisCI (Linux) this ENV var is set to en_US.UTF-8, on OS X it is nil
40
+ # On TravisCI (Linux) this ENV var is set to en_US.UTF-8,
41
+ # on OS X it is nil
42
42
  original_lc_all = ENV['LC_ALL']
43
43
  ENV.delete('LC_ALL') if original_lc_all
44
44
 
45
- shell = DaptivChefCI::Shell.new()
45
+ shell = DaptivChefCI::Shell.new
46
46
  out = shell.exec_cmd('echo $LC_ALL', 600)
47
47
  expect(out[0]).to be nil
48
48
 
@@ -50,22 +50,18 @@ describe DaptivChefCI::Shell, :unit => true do
50
50
  end
51
51
 
52
52
  it 'should allow override of LC_ALL environment var' do
53
- shell = DaptivChefCI::Shell.new()
54
- out = shell.exec_cmd('echo $LC_ALL', 600, { :LC_ALL => 'en_US.UTF-8' })
53
+ shell = DaptivChefCI::Shell.new
54
+ out = shell.exec_cmd('echo $LC_ALL', 600, LC_ALL: 'en_US.UTF-8')
55
55
  expect(out[0]).to eq('en_US.UTF-8')
56
56
  end
57
-
58
57
  end
59
-
58
+
60
59
  describe 'path_without_gem_dir' do
61
-
62
60
  it 'should not be prefixed by the system gem dir' do
63
- shell = DaptivChefCI::Shell.new()
64
- path = shell.path_without_gem_dir()
65
- expect(path).not_to include(Bundler.bundle_path.to_s() + ':')
61
+ shell = DaptivChefCI::Shell.new
62
+ path = shell.path_without_gem_dir
63
+ expect(path).not_to include(Bundler.bundle_path.to_s + ':')
66
64
  expect(ENV['PATH']).to include(path)
67
65
  end
68
-
69
66
  end
70
-
71
67
  end
@@ -1,18 +1,16 @@
1
1
  require 'daptiv-chef-ci/vagrant_destroy_task'
2
2
  require_relative '../shared_contexts/rake'
3
3
 
4
- describe VagrantDestroy::RakeTask, :unit => true do
4
+ describe VagrantDestroy::RakeTask, unit: true do
5
5
  include_context 'rake'
6
6
 
7
7
  describe 'vagrant_destroy' do
8
8
  it 'should destroy the box' do
9
-
10
- vagrant_driver.should_receive(:destroy).with({ :cmd_timeout_in_seconds => 180, :environment => {} })
11
-
9
+ vagrant_driver.should_receive(:destroy).with(
10
+ cmd_timeout_in_seconds: 180,
11
+ environment: {})
12
12
  task = rake['vagrant_destroy']
13
- task.invoke()
14
-
13
+ task.invoke
15
14
  end
16
15
  end
17
-
18
16
  end
@@ -2,113 +2,75 @@ require 'mixlib/shellout/exceptions'
2
2
  require 'daptiv-chef-ci/vagrant_driver'
3
3
  require 'daptiv-chef-ci/logger'
4
4
 
5
- describe DaptivChefCI::VagrantDriver, :unit => true do
6
-
5
+ describe DaptivChefCI::VagrantDriver, unit: true do
7
6
  before(:each) do
8
- @shell = mock()
9
- @basebox_builder_factory = stub()
10
- @vagrant = DaptivChefCI::VagrantDriver.new(:virtualbox, @shell, @basebox_builder_factory)
7
+ @shell = mock
8
+ @vagrant = DaptivChefCI::VagrantDriver.new(:virtualbox, @shell)
11
9
  end
12
10
 
13
11
  describe 'destroy' do
14
12
  it 'should force shutdown vagrant with a timeout of 180 seconds' do
15
13
  @shell.should_receive(:exec_cmd).with('vagrant destroy -f', 180, {})
16
- @vagrant.destroy()
14
+ @vagrant.destroy
17
15
  end
18
16
  end
19
-
17
+
20
18
  describe 'halt' do
21
19
  it 'should halt vagrant with a timeout of 180 seconds' do
22
20
  @shell.should_receive(:exec_cmd).with('vagrant halt', 180, {})
23
- @vagrant.halt()
21
+ @vagrant.halt
24
22
  end
25
-
23
+
26
24
  it 'should retry when exec fails' do
27
- @shell.should_receive(:exec_cmd).and_raise(Mixlib::ShellOut::ShellCommandFailed)
25
+ @shell.should_receive(:exec_cmd)
26
+ .and_raise(Mixlib::ShellOut::ShellCommandFailed)
28
27
  @shell.should_receive(:exec_cmd).and_return('success')
29
28
  # shell cmd fails then succeeds, the vagrant.halt should succeed overall
30
- @vagrant.halt({ :retry_wait_in_seconds => 0 })
29
+ @vagrant.halt(retry_wait_in_seconds: 0)
31
30
  end
32
-
31
+
33
32
  it 'should fail after retrying twice' do
34
33
  # shell always fails, vagrant.halt should fail after a couple retries
35
- @shell.should_receive(:exec_cmd).exactly(3).times.and_raise(Mixlib::ShellOut::ShellCommandFailed)
36
- expect { @vagrant.halt({ :retry_wait_in_seconds => 0 }) }.to raise_error(Mixlib::ShellOut::ShellCommandFailed)
34
+ @shell.should_receive(:exec_cmd)
35
+ .exactly(3).times.and_raise(Mixlib::ShellOut::ShellCommandFailed)
36
+ expect { @vagrant.halt(retry_wait_in_seconds: 0) }
37
+ .to raise_error(Mixlib::ShellOut::ShellCommandFailed)
37
38
  end
38
39
  end
39
-
40
+
40
41
  describe 'up' do
41
42
  it 'should up vagrant with a timeout of 7200 seconds' do
42
- @shell.should_receive(:exec_cmd).with('vagrant up', 7200, {})
43
- @vagrant.up()
43
+ @shell.should_receive(:exec_cmd).with(
44
+ 'vagrant up --provider=virtualbox', 7200, {})
45
+ @vagrant.up
44
46
  end
45
47
 
46
48
  it 'should up vagrant and specify the provider if not virtualbox' do
47
- @vagrant = DaptivChefCI::VagrantDriver.new(:my_custom_provider, @shell, @basebox_builder_factory)
48
- @shell.should_receive(:exec_cmd).with('vagrant up --provider=my_custom_provider', 7200, {})
49
- @vagrant.up()
49
+ @vagrant = DaptivChefCI::VagrantDriver.new(:my_custom_provider, @shell)
50
+ @shell.should_receive(:exec_cmd).with(
51
+ 'vagrant up --provider=my_custom_provider', 7200, {})
52
+ @vagrant.up
50
53
  end
51
-
54
+
52
55
  it 'should pass along environment variables' do
53
- environment = { :A => 'A' }
54
- @shell.should_receive(:exec_cmd).with('vagrant up', 7200, environment)
55
- @vagrant.up({ :environment => environment })
56
+ environment = { A: 'A' }
57
+ @shell.should_receive(:exec_cmd)
58
+ .with('vagrant up --provider=virtualbox', 7200, environment)
59
+ @vagrant.up(environment: environment)
56
60
  end
57
61
  end
58
62
 
59
63
  describe 'provision' do
60
64
  it 'should provision vagrant with a timeout of 7200 seconds' do
61
65
  @shell.should_receive(:exec_cmd).with('vagrant provision', 7200, {})
62
- @vagrant.provision()
63
- end
64
-
65
- it 'should pass along environment variables' do
66
- environment = { :A => 'A' }
67
- @shell.should_receive(:exec_cmd).with('vagrant provision', 7200, environment)
68
- @vagrant.provision({ :environment => environment })
69
- end
70
- end
71
-
72
- describe 'reload' do
73
- it 'should reload vagrant with a timeout of 180 seconds' do
74
- @shell.should_receive(:exec_cmd).with('vagrant reload', 180, {})
75
- @vagrant.reload()
76
- end
77
- end
78
-
79
- describe 'package' do
80
- it 'should default to virtualbox and base_dir to current working dir' do
81
- builder = double('builder').as_null_object
82
- @basebox_builder_factory.should_receive(:create).with(@shell, :virtualbox, Dir.pwd).and_return(builder)
83
- @vagrant.package()
66
+ @vagrant.provision
84
67
  end
85
68
 
86
- it 'should use the specified provider' do
87
- builder = double('builder').as_null_object
88
- @vagrant = DaptivChefCI::VagrantDriver.new(:vmware_fusion, @shell, @basebox_builder_factory)
89
- @basebox_builder_factory.should_receive(:create).with(@shell, :vmware_fusion, Dir.pwd).and_return(builder)
90
- @vagrant.package()
91
- end
92
-
93
- it 'should use the specified base_dir' do
94
- builder = double('builder').as_null_object
95
- @basebox_builder_factory.should_receive(:create).with(@shell, :virtualbox, '/Users/admin/mybox').and_return(builder)
96
- @vagrant.package({ :base_dir => '/Users/admin/mybox' })
97
- end
98
-
99
- it 'should default box_name to directory name' do
100
- builder = mock('builder')
101
- builder.should_receive(:build).with('mybox.box')
102
- @basebox_builder_factory.stub(:create).and_return(builder)
103
- @vagrant.package({ :base_dir => '/Users/admin/mybox' })
104
- end
105
-
106
- it 'should ensure box name ends with .box' do
107
- builder = mock('builder')
108
- builder.should_receive(:build).with('mybox.box')
109
- @basebox_builder_factory.stub(:create).and_return(builder)
110
- @vagrant.package({ :box_name => 'mybox' })
69
+ it 'should pass along environment variables' do
70
+ environment = { A: 'A' }
71
+ @shell.should_receive(:exec_cmd)
72
+ .with('vagrant provision', 7200, environment)
73
+ @vagrant.provision(environment: environment)
111
74
  end
112
75
  end
113
-
114
76
  end
@@ -1,29 +1,25 @@
1
1
  require 'daptiv-chef-ci/vagrant_provision_task'
2
2
  require_relative '../shared_contexts/rake'
3
3
 
4
- describe VagrantProvision::RakeTask, :unit => true do
4
+ describe VagrantProvision::RakeTask, unit: true do
5
5
  include_context 'rake'
6
6
 
7
7
  describe 'vagrant_provision' do
8
8
  it 'should provision the box' do
9
-
10
- vagrant_driver.should_receive(:provision).with({ :cmd_timeout_in_seconds => 7200, :environment => {} })
11
-
9
+ vagrant_driver.should_receive(:provision)
10
+ .with(cmd_timeout_in_seconds: 7200, environment: {})
12
11
  task = rake['vagrant_provision']
13
- task.invoke()
14
-
12
+ task.invoke
15
13
  end
16
-
14
+
17
15
  it 'should up the box with the specified environment vars' do
16
+ environment = { ENV_VAR1: 'val1', ENV_VAR2: 'val2' }
17
+ vagrant_driver.should_receive(:provision)
18
+ .with(cmd_timeout_in_seconds: 7200, environment: environment)
18
19
 
19
- environment = { :ENV_VAR1 => 'val1', :ENV_VAR2 => 'val2' }
20
- vagrant_driver.should_receive(:provision).with({ :cmd_timeout_in_seconds => 7200, :environment => environment })
21
-
22
20
  task = rake['vagrant_provision']
23
21
  subject.environment = environment
24
- task.invoke()
25
-
22
+ task.invoke
26
23
  end
27
24
  end
28
-
29
25
  end
@@ -1,37 +1,45 @@
1
1
  require 'daptiv-chef-ci/vagrant_task'
2
2
  require_relative '../shared_contexts/rake'
3
3
 
4
- describe Vagrant::RakeTask, :unit => true do
4
+ describe Vagrant::RakeTask, unit: true do
5
5
  include_context 'rake'
6
6
 
7
7
  describe 'vagrant' do
8
8
  it 'should destroy, up, halt, then destroy the box' do
9
-
10
- vagrant_driver.should_receive(:destroy).with({ :cmd_timeout_in_seconds => 180, :retry_attempts => 2, :environment => {} })
11
- vagrant_driver.should_receive(:up).with({ :cmd_timeout_in_seconds => 7200, :environment => {} })
12
- vagrant_driver.should_receive(:destroy).with({ :cmd_timeout_in_seconds => 180, :retry_attempts => 2, :environment => {} })
13
-
14
- task = rake['vagrant']
15
- task.invoke()
9
+ vagrant_driver.should_receive(:destroy).with(
10
+ cmd_timeout_in_seconds: 180,
11
+ retry_attempts: 0,
12
+ environment: {})
13
+ vagrant_driver.should_receive(:up).with(
14
+ cmd_timeout_in_seconds: 7200,
15
+ environment: {})
16
+ vagrant_driver.should_receive(:destroy).with(
17
+ cmd_timeout_in_seconds: 180,
18
+ retry_attempts: 2,
19
+ environment: {})
16
20
 
21
+ task = rake['vagrant']
22
+ task.invoke
17
23
  end
18
-
24
+
19
25
  it 'should up the box with the specified environment vars' do
26
+ environment = { ENV_VAR1: 'val1', ENV_VAR2: 'val2' }
27
+
28
+ vagrant_driver.should_receive(:destroy).with(
29
+ cmd_timeout_in_seconds: 180,
30
+ retry_attempts: 0,
31
+ environment: environment)
32
+ vagrant_driver.should_receive(:up).with(
33
+ cmd_timeout_in_seconds: 7200,
34
+ environment: environment)
35
+ vagrant_driver.should_receive(:destroy).with(
36
+ cmd_timeout_in_seconds: 180,
37
+ retry_attempts: 2,
38
+ environment: environment)
20
39
 
21
- environment = { :ENV_VAR1 => 'val1', :ENV_VAR2 => 'val2' }
22
-
23
- vagrant_driver.should_receive(:destroy).with({
24
- :cmd_timeout_in_seconds => 180, :retry_attempts => 2, :environment => environment })
25
- vagrant_driver.should_receive(:up).with({
26
- :cmd_timeout_in_seconds => 7200, :environment => environment })
27
- vagrant_driver.should_receive(:destroy).with({
28
- :cmd_timeout_in_seconds => 180, :retry_attempts => 2, :environment => environment })
29
-
30
40
  task = rake['vagrant']
31
41
  subject.environment = environment
32
- task.invoke()
33
-
42
+ task.invoke
34
43
  end
35
44
  end
36
-
37
45
  end