daptiv-chef-ci 0.0.8 → 0.0.9

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.
@@ -43,7 +43,7 @@ Gem::Specification.new do |gem|
43
43
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
44
44
  gem.name = "daptiv-chef-ci"
45
45
  gem.require_paths = ["lib"]
46
- gem.version = '0.0.8'
46
+ gem.version = '0.0.9'
47
47
 
48
48
  gem.add_runtime_dependency "log4r", "~> 1.1.10"
49
49
  gem.add_runtime_dependency "mixlib-shellout", "~> 1.2.0"
@@ -30,4 +30,6 @@ module DaptivChefCI
30
30
  end
31
31
 
32
32
  end
33
- end
33
+ end
34
+
35
+ DaptivChefCI::Logger.init()
@@ -0,0 +1,18 @@
1
+ module DaptivChefCI
2
+ module RakeTaskHelpers
3
+ extend self
4
+
5
+ def execute(&block)
6
+ begin
7
+ block.call()
8
+ rescue SystemExit => ex
9
+ exit(ex.status)
10
+ rescue Exception => ex
11
+ STDERR.puts("#{ex.message} (#{ex.class})")
12
+ STDERR.puts(ex.backtrace.join("\n"))
13
+ exit(1)
14
+ end
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,45 @@
1
+ require 'rake'
2
+ require 'rake/tasklib'
3
+ require 'rake/dsl_definition'
4
+ require_relative 'vagrant_driver'
5
+ require_relative 'raketask_helper'
6
+ require_relative 'logger'
7
+
8
+ class VagrantDestroy
9
+
10
+ # Example usage, destroys a Vagrant box.
11
+ #
12
+ # VagrantUp::RakeTask.new 'up' do |t|
13
+ # t.destroy_timeout_in_seconds = 180
14
+ # end
15
+ #
16
+ # This class lets you define Rake tasks to drive Vagrant.
17
+ class RakeTask < ::Rake::TaskLib
18
+ include ::Rake::DSL if defined? ::Rake::DSL
19
+ include DaptivChefCI::RakeTaskHelpers
20
+
21
+ attr_accessor :vagrant_driver
22
+ attr_accessor :destroy_timeout_in_seconds
23
+
24
+ # @param [String] name The task name.
25
+ # @param [String] desc Description of the task.
26
+ def initialize(name = 'vagrant_destroy', desc = 'Vagrant destroy task')
27
+ @name, @desc = name, desc
28
+ @destroy_timeout_in_seconds = 180
29
+ @vagrant_driver = DaptivChefCI::VagrantDriver.new()
30
+ yield self if block_given?
31
+ define_task
32
+ end
33
+
34
+ private
35
+
36
+ def define_task
37
+ desc @desc
38
+ task @name do
39
+ execute { @vagrant_driver.destroy({ :cmd_timeout_in_seconds => @destroy_timeout_in_seconds }) }
40
+ end
41
+ end
42
+
43
+ end
44
+ end
45
+
@@ -1,5 +1,6 @@
1
1
  require 'log4r'
2
2
  require 'mixlib/shellout/exceptions'
3
+ require_relative 'basebox_builder_factory'
3
4
  require_relative 'shell'
4
5
 
5
6
  module DaptivChefCI
@@ -7,13 +8,14 @@ module DaptivChefCI
7
8
 
8
9
  # Constructs a new Vagrant management instance
9
10
  #
10
- # @param [Shell] The CLI
11
- # @param [BaseBoxBuilderFactory] The base box builder factory instance
12
11
  # @param [String] The name of the Vagrant virtualization provider: virtualbox, vmware_fusion
13
- def initialize(shell, basebox_builder_factory, provider = :virtualbox)
12
+ # defaults to :virtualbox
13
+ # @param [Shell] The CLI, optional
14
+ # @param [BaseBoxBuilderFactory] The base box builder factory instance, optional
15
+ def initialize(provider = :virtualbox, shell = nil, basebox_builder_factory = nil)
14
16
  @logger = Log4r::Logger.new("daptiv_chef_ci::vagrant")
15
- @shell = shell
16
- @basebox_builder_factory = basebox_builder_factory
17
+ @shell = shell || DaptivChefCI::Shell.new()
18
+ @basebox_builder_factory = basebox_builder_factory || DaptivChefCI::BaseBoxBuilderFactory.new()
17
19
  @provider = provider
18
20
  end
19
21
 
@@ -0,0 +1,46 @@
1
+ require 'rake'
2
+ require 'rake/tasklib'
3
+ require 'rake/dsl_definition'
4
+ require_relative 'vagrant_driver'
5
+ require_relative 'raketask_helper'
6
+ require_relative 'logger'
7
+
8
+ class VagrantProvision
9
+
10
+ # Example usage, provisions a vmware box (box must already be up):
11
+ #
12
+ # VagrantProvision::RakeTask.new 'provision' do |t|
13
+ # t.provision_timeout_in_seconds = 3600
14
+ # end
15
+ #
16
+ # This class lets you define Rake tasks to drive Vagrant.
17
+ class RakeTask < ::Rake::TaskLib
18
+ include ::Rake::DSL if defined? ::Rake::DSL
19
+ include DaptivChefCI::RakeTaskHelpers
20
+
21
+ attr_accessor :vagrant_driver
22
+ attr_accessor :provision_timeout_in_seconds
23
+
24
+ # @param [String] name The task name.
25
+ # @param [String] desc Description of the task.
26
+ # @param [String] provider vagrant provider to use if other than the default virtualbox provider
27
+ def initialize(name = 'vagrant_provision', desc = 'Vagrant provision task')
28
+ @name, @desc = name, desc
29
+ @provision_timeout_in_seconds = 7200
30
+ @vagrant_driver = DaptivChefCI::VagrantDriver.new()
31
+ yield self if block_given?
32
+ define_task
33
+ end
34
+
35
+ private
36
+
37
+ def define_task
38
+ desc @desc
39
+ task @name do
40
+ execute { @vagrant_driver.provision({ :cmd_timeout_in_seconds => @provision_timeout_in_seconds }) }
41
+ end
42
+ end
43
+
44
+ end
45
+ end
46
+
@@ -1,19 +1,10 @@
1
1
  require 'rake'
2
2
  require 'rake/tasklib'
3
+ require 'rake/dsl_definition'
3
4
  require_relative 'vagrant_driver'
4
- require_relative 'virtualbox_driver'
5
- require_relative 'basebox_builder_factory'
6
- require_relative 'shell'
5
+ require_relative 'raketask_helper'
7
6
  require_relative 'logger'
8
7
 
9
- begin
10
- # Support Rake > 0.8.7
11
- require 'rake/dsl_definition'
12
- rescue LoadError
13
- end
14
-
15
- DaptivChefCI::Logger.init()
16
-
17
8
  class Vagrant
18
9
 
19
10
  # Example usage, creates a vmware base box:
@@ -28,7 +19,9 @@ class Vagrant
28
19
  # This class lets you define Rake tasks to drive Vagrant.
29
20
  class RakeTask < ::Rake::TaskLib
30
21
  include ::Rake::DSL if defined? ::Rake::DSL
22
+ include DaptivChefCI::RakeTaskHelpers
31
23
 
24
+ attr_accessor :vagrant_driver
32
25
  attr_accessor :provider
33
26
  attr_accessor :create_box
34
27
  attr_accessor :vagrantfile_dir
@@ -42,7 +35,7 @@ class Vagrant
42
35
  # @param [String] name The task name.
43
36
  # @param [String] desc Description of the task.
44
37
  # @param [String] provider vagrant provider to use if other than the default virtualbox provider
45
- def initialize(name = 'vagrant', desc = 'Daptiv Vagrant Tasks')
38
+ def initialize(name = 'vagrant', desc = 'Vagrant up, halt, destroy, package task')
46
39
  @name, @desc = name, desc
47
40
  @provider = :virtualbox
48
41
  @create_box = false
@@ -53,6 +46,7 @@ class Vagrant
53
46
  @destroy_timeout_in_seconds = 180
54
47
  @destroy_retry_attempts = 2
55
48
  @halt_retry_attempts = 2
49
+ @vagrant_driver = DaptivChefCI::VagrantDriver.new(@provider)
56
50
  yield self if block_given?
57
51
  define_task
58
52
  end
@@ -62,63 +56,42 @@ class Vagrant
62
56
  def define_task
63
57
  desc @desc
64
58
  task @name do
65
- shell = DaptivChefCI::Shell.new()
66
- basebox_builder_factory = DaptivChefCI::BaseBoxBuilderFactory.new()
67
- vagrant = DaptivChefCI::VagrantDriver.new(shell, basebox_builder_factory, @provider)
68
- execute_vagrant_run(vagrant)
59
+ execute_vagrant_run()
69
60
  end
70
61
  end
71
62
 
72
- def execute_vagrant_run(vagrant)
73
- try_destroy_before_vagrant_up(vagrant)
74
- try_vagrant_up(vagrant)
63
+ def execute_vagrant_run()
64
+ execute { destroy() }
65
+ try_vagrant_up()
75
66
  end
76
67
 
77
- def try_destroy_before_vagrant_up(vagrant)
68
+ def try_vagrant_up()
78
69
  begin
79
- destroy(vagrant)
80
- rescue SystemExit => ex
81
- exit(ex.status)
82
- rescue Exception => ex
83
- print_err(ex)
84
- end
85
- end
86
-
87
- def try_vagrant_up(vagrant)
88
- begin
89
- up(vagrant)
90
- halt(vagrant)
91
- package(vagrant) if @create_box
92
- rescue SystemExit => ex
93
- exit(ex.status)
94
- rescue Exception => ex
95
- print_err(ex)
96
- exit(1)
70
+ execute do
71
+ up()
72
+ halt()
73
+ package() if @create_box
74
+ end
97
75
  ensure
98
- halt(vagrant)
99
- destroy(vagrant)
76
+ halt()
77
+ destroy()
100
78
  end
101
79
  end
102
80
 
103
- def up(vagrant)
104
- vagrant.up({ :cmd_timeout_in_seconds => @up_timeout_in_seconds })
105
- end
106
-
107
- def package(vagrant)
108
- vagrant.package({ :base_dir => @vagrantfile_dir, :box_name => @box_name })
81
+ def up()
82
+ @vagrant_driver.up({ :cmd_timeout_in_seconds => @up_timeout_in_seconds })
109
83
  end
110
84
 
111
- def destroy(vagrant)
112
- vagrant.destroy({ :cmd_timeout_in_seconds => @destroy_timeout_in_seconds, :retry_attempts => @destroy_retry_attempts })
85
+ def package()
86
+ @vagrant_driver.package({ :base_dir => @vagrantfile_dir, :box_name => @box_name })
113
87
  end
114
88
 
115
- def halt(vagrant)
116
- vagrant.halt({ :cmd_timeout_in_seconds => @halt_timeout_in_seconds, :retry_attempts => @halt_retry_attempts })
89
+ def destroy()
90
+ @vagrant_driver.destroy({ :cmd_timeout_in_seconds => @destroy_timeout_in_seconds, :retry_attempts => @destroy_retry_attempts })
117
91
  end
118
92
 
119
- def print_err(ex)
120
- STDERR.puts("#{ex.message} (#{ex.class})")
121
- STDERR.puts(ex.backtrace.join("\n"))
93
+ def halt()
94
+ @vagrant_driver.halt({ :cmd_timeout_in_seconds => @halt_timeout_in_seconds, :retry_attempts => @halt_retry_attempts })
122
95
  end
123
96
 
124
97
  end
@@ -0,0 +1,49 @@
1
+ require 'rake'
2
+ require 'rake/tasklib'
3
+ require 'rake/dsl_definition'
4
+ require_relative 'vagrant_driver'
5
+ require_relative 'raketask_helper'
6
+ require_relative 'logger'
7
+
8
+ class VagrantUp
9
+
10
+ # Example usage, ups and provisions a Vagrant box without halting or destroying it.
11
+ #
12
+ # VagrantUp::RakeTask.new 'up' do |t|
13
+ # t.provider = :vmware_fusion
14
+ # t.up_timeout_in_seconds = 3600
15
+ # end
16
+ #
17
+ # This class lets you define Rake tasks to drive Vagrant.
18
+ class RakeTask < ::Rake::TaskLib
19
+ include ::Rake::DSL if defined? ::Rake::DSL
20
+ include DaptivChefCI::RakeTaskHelpers
21
+
22
+ attr_accessor :vagrant_driver
23
+ attr_accessor :provider
24
+ attr_accessor :up_timeout_in_seconds
25
+
26
+ # @param [String] name The task name.
27
+ # @param [String] desc Description of the task.
28
+ # @param [String] provider vagrant provider to use if other than the default virtualbox provider
29
+ def initialize(name = 'vagrant_up', desc = 'Vagrant up task')
30
+ @name, @desc = name, desc
31
+ @provider = :virtualbox
32
+ @up_timeout_in_seconds = 7200
33
+ @vagrant_driver = DaptivChefCI::VagrantDriver.new(@provider)
34
+ yield self if block_given?
35
+ define_task
36
+ end
37
+
38
+ private
39
+
40
+ def define_task
41
+ desc @desc
42
+ task @name do
43
+ execute { @vagrant_driver.up({ :cmd_timeout_in_seconds => @up_timeout_in_seconds }) }
44
+ end
45
+ end
46
+
47
+ end
48
+ end
49
+
@@ -0,0 +1,18 @@
1
+ require 'daptiv-chef-ci/vagrant_destroy_task'
2
+ require_relative '../shared_contexts/rake'
3
+
4
+ describe VagrantDestroy::RakeTask, :unit => true do
5
+ include_context 'rake'
6
+
7
+ describe 'vagrant_destroy' do
8
+ it 'should destroy the box' do
9
+
10
+ vagrant_driver.should_receive(:destroy).with({ :cmd_timeout_in_seconds => 180 })
11
+
12
+ task = rake['vagrant_destroy']
13
+ task.invoke()
14
+
15
+ end
16
+ end
17
+
18
+ end
@@ -7,7 +7,7 @@ describe DaptivChefCI::VagrantDriver, :unit => true do
7
7
  before(:each) do
8
8
  @shell = mock()
9
9
  @basebox_builder_factory = stub()
10
- @vagrant = DaptivChefCI::VagrantDriver.new(@shell, @basebox_builder_factory)
10
+ @vagrant = DaptivChefCI::VagrantDriver.new(:virtualbox, @shell, @basebox_builder_factory)
11
11
  end
12
12
 
13
13
  describe 'destroy' do
@@ -44,7 +44,7 @@ describe DaptivChefCI::VagrantDriver, :unit => true do
44
44
  end
45
45
 
46
46
  it 'should up vagrant and specify the provider if not virtualbox' do
47
- @vagrant = DaptivChefCI::VagrantDriver.new(@shell, @basebox_builder_factory, :my_custom_provider)
47
+ @vagrant = DaptivChefCI::VagrantDriver.new(:my_custom_provider, @shell, @basebox_builder_factory)
48
48
  @shell.should_receive(:exec_cmd).with('vagrant up --provider=my_custom_provider', 7200)
49
49
  @vagrant.up()
50
50
  end
@@ -73,7 +73,7 @@ describe DaptivChefCI::VagrantDriver, :unit => true do
73
73
 
74
74
  it 'should use the specified provider' do
75
75
  builder = double('builder').as_null_object
76
- @vagrant = DaptivChefCI::VagrantDriver.new(@shell, @basebox_builder_factory, :vmware_fusion)
76
+ @vagrant = DaptivChefCI::VagrantDriver.new(:vmware_fusion, @shell, @basebox_builder_factory)
77
77
  @basebox_builder_factory.should_receive(:create).with(@shell, :vmware_fusion, Dir.pwd).and_return(builder)
78
78
  @vagrant.package()
79
79
  end
@@ -0,0 +1,18 @@
1
+ require 'daptiv-chef-ci/vagrant_provision_task'
2
+ require_relative '../shared_contexts/rake'
3
+
4
+ describe VagrantProvision::RakeTask, :unit => true do
5
+ include_context 'rake'
6
+
7
+ describe 'vagrant_provision' do
8
+ it 'should provision the box' do
9
+
10
+ vagrant_driver.should_receive(:provision).with({ :cmd_timeout_in_seconds => 7200 })
11
+
12
+ task = rake['vagrant_provision']
13
+ task.invoke()
14
+
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,21 @@
1
+ require 'daptiv-chef-ci/vagrant_task'
2
+ require_relative '../shared_contexts/rake'
3
+
4
+ describe Vagrant::RakeTask, :unit => true do
5
+ include_context 'rake'
6
+
7
+ describe 'vagrant' do
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 })
11
+ vagrant_driver.should_receive(:up).with({ :cmd_timeout_in_seconds => 7200 })
12
+ vagrant_driver.should_receive(:halt).at_least(1).times.with({ :cmd_timeout_in_seconds => 180, :retry_attempts => 2 })
13
+ vagrant_driver.should_receive(:destroy).with({ :cmd_timeout_in_seconds => 180, :retry_attempts => 2 })
14
+
15
+ task = rake['vagrant']
16
+ task.invoke()
17
+
18
+ end
19
+ end
20
+
21
+ end
@@ -0,0 +1,18 @@
1
+ require 'daptiv-chef-ci/vagrant_up_task'
2
+ require_relative '../shared_contexts/rake'
3
+
4
+ describe VagrantUp::RakeTask, :unit => true do
5
+ include_context 'rake'
6
+
7
+ describe 'vagrant_up' do
8
+ it 'should up the box' do
9
+
10
+ vagrant_driver.should_receive(:up).with({ :cmd_timeout_in_seconds => 7200 })
11
+
12
+ task = rake['vagrant_up']
13
+ task.invoke()
14
+
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,13 @@
1
+ require "rake"
2
+
3
+ shared_context "rake" do
4
+ let(:rake) { create_rake_application() }
5
+ let(:vagrant_driver) { stub() }
6
+
7
+ def create_rake_application
8
+ Rake.application = Rake::Application.new
9
+ subject.vagrant_driver = vagrant_driver
10
+ Rake::Task.define_task(subject)
11
+ Rake.application
12
+ end
13
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: daptiv-chef-ci
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-07 00:00:00.000000000 Z
12
+ date: 2013-11-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: log4r
@@ -118,9 +118,13 @@ files:
118
118
  - Gemfile
119
119
  - lib/daptiv-chef-ci/basebox_builder_factory.rb
120
120
  - lib/daptiv-chef-ci/logger.rb
121
+ - lib/daptiv-chef-ci/raketask_helper.rb
121
122
  - lib/daptiv-chef-ci/shell.rb
123
+ - lib/daptiv-chef-ci/vagrant_destroy_task.rb
122
124
  - lib/daptiv-chef-ci/vagrant_driver.rb
125
+ - lib/daptiv-chef-ci/vagrant_provision_task.rb
123
126
  - lib/daptiv-chef-ci/vagrant_task.rb
127
+ - lib/daptiv-chef-ci/vagrant_up_task.rb
124
128
  - lib/daptiv-chef-ci/virtualbox_basebox_builder.rb
125
129
  - lib/daptiv-chef-ci/virtualbox_driver.rb
126
130
  - lib/daptiv-chef-ci/vmware_basebox_builder.rb
@@ -131,15 +135,21 @@ files:
131
135
  - pkg/daptiv-chef-ci-0.0.5.gem
132
136
  - pkg/daptiv-chef-ci-0.0.6.gem
133
137
  - pkg/daptiv-chef-ci-0.0.7.gem
138
+ - pkg/daptiv-chef-ci-0.0.8.gem
134
139
  - Rakefile
135
140
  - README.md
136
141
  - spec/daptiv-chef-ci/basebox_builder_factory_spec.rb
137
142
  - spec/daptiv-chef-ci/logger_spec.rb
138
143
  - spec/daptiv-chef-ci/shell_spec.rb
144
+ - spec/daptiv-chef-ci/vagrant_destroy_task_spec.rb
139
145
  - spec/daptiv-chef-ci/vagrant_driver_spec.rb
146
+ - spec/daptiv-chef-ci/vagrant_provision_task_spec.rb
147
+ - spec/daptiv-chef-ci/vagrant_task_spec.rb
148
+ - spec/daptiv-chef-ci/vagrant_up_task_spec.rb
140
149
  - spec/daptiv-chef-ci/virtualbox_basebox_builder_spec.rb
141
150
  - spec/daptiv-chef-ci/virtualbox_driver_spec.rb
142
151
  - spec/daptiv-chef-ci/vmware_basebox_builder_spec.rb
152
+ - spec/shared_contexts/rake.rb
143
153
  - .gitignore
144
154
  homepage: ''
145
155
  licenses: []
@@ -155,7 +165,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
155
165
  version: '0'
156
166
  segments:
157
167
  - 0
158
- hash: 1439606401422604689
168
+ hash: -3145193294758643333
159
169
  required_rubygems_version: !ruby/object:Gem::Requirement
160
170
  none: false
161
171
  requirements:
@@ -164,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
174
  version: '0'
165
175
  segments:
166
176
  - 0
167
- hash: 1439606401422604689
177
+ hash: -3145193294758643333
168
178
  requirements: []
169
179
  rubyforge_project:
170
180
  rubygems_version: 1.8.23
@@ -175,7 +185,12 @@ test_files:
175
185
  - spec/daptiv-chef-ci/basebox_builder_factory_spec.rb
176
186
  - spec/daptiv-chef-ci/logger_spec.rb
177
187
  - spec/daptiv-chef-ci/shell_spec.rb
188
+ - spec/daptiv-chef-ci/vagrant_destroy_task_spec.rb
178
189
  - spec/daptiv-chef-ci/vagrant_driver_spec.rb
190
+ - spec/daptiv-chef-ci/vagrant_provision_task_spec.rb
191
+ - spec/daptiv-chef-ci/vagrant_task_spec.rb
192
+ - spec/daptiv-chef-ci/vagrant_up_task_spec.rb
179
193
  - spec/daptiv-chef-ci/virtualbox_basebox_builder_spec.rb
180
194
  - spec/daptiv-chef-ci/virtualbox_driver_spec.rb
181
195
  - spec/daptiv-chef-ci/vmware_basebox_builder_spec.rb
196
+ - spec/shared_contexts/rake.rb