daptiv-chef-ci 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/daptiv-chef-ci.gemspec +1 -1
- data/lib/daptiv-chef-ci/raketask_helper.rb +22 -4
- data/lib/daptiv-chef-ci/shell.rb +6 -3
- data/lib/daptiv-chef-ci/vagrant_driver.rb +3 -1
- data/lib/daptiv-chef-ci/vagrant_provision_task.rb +9 -1
- data/lib/daptiv-chef-ci/vagrant_task.rb +7 -1
- data/lib/daptiv-chef-ci/vagrant_up_task.rb +9 -1
- data/spec/daptiv-chef-ci/shell_spec.rb +12 -0
- data/spec/daptiv-chef-ci/vagrant_driver_spec.rb +18 -6
- data/spec/daptiv-chef-ci/vagrant_provision_task_spec.rb +12 -1
- data/spec/daptiv-chef-ci/vagrant_task_spec.rb +16 -1
- data/spec/daptiv-chef-ci/vagrant_up_task_spec.rb +12 -1
- data/spec/shared_contexts/rake.rb +4 -0
- metadata +5 -4
data/daptiv-chef-ci.gemspec
CHANGED
@@ -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.
|
46
|
+
gem.version = '0.0.10'
|
47
47
|
|
48
48
|
gem.add_runtime_dependency "log4r", "~> 1.1.10"
|
49
49
|
gem.add_runtime_dependency "mixlib-shellout", "~> 1.2.0"
|
@@ -2,15 +2,33 @@ module DaptivChefCI
|
|
2
2
|
module RakeTaskHelpers
|
3
3
|
extend self
|
4
4
|
|
5
|
+
@@exit_on_failure = true
|
6
|
+
|
7
|
+
def exit_on_failure
|
8
|
+
@@exit_on_failure
|
9
|
+
end
|
10
|
+
|
11
|
+
def exit_on_failure=(exit_on_failure)
|
12
|
+
@@exit_on_failure = exit_on_failure
|
13
|
+
end
|
14
|
+
|
5
15
|
def execute(&block)
|
6
16
|
begin
|
7
17
|
block.call()
|
8
18
|
rescue SystemExit => ex
|
9
|
-
|
19
|
+
if @@exit_on_failure
|
20
|
+
exit(ex.status)
|
21
|
+
else
|
22
|
+
raise
|
23
|
+
end
|
10
24
|
rescue Exception => ex
|
11
|
-
|
12
|
-
|
13
|
-
|
25
|
+
if @@exit_on_failure
|
26
|
+
STDERR.puts("#{ex.message} (#{ex.class})")
|
27
|
+
STDERR.puts(ex.backtrace.join("\n"))
|
28
|
+
exit(1)
|
29
|
+
else
|
30
|
+
raise
|
31
|
+
end
|
14
32
|
end
|
15
33
|
end
|
16
34
|
|
data/lib/daptiv-chef-ci/shell.rb
CHANGED
@@ -16,15 +16,18 @@ module DaptivChefCI
|
|
16
16
|
#
|
17
17
|
# @param [String] The command line to execute
|
18
18
|
# @param [Int] The number of seconds to wait for the command to finish, defaults to 600
|
19
|
+
# @param [Hash] Key value pairs of environment variables to pass to the command's environment.
|
19
20
|
# @return [Array] Each entry represents a line from the stdout
|
20
|
-
def exec_cmd(command, timeout=
|
21
|
+
def exec_cmd(command, timeout = nil, environment = {})
|
22
|
+
timeout ||= 600
|
23
|
+
environment = Hash[ environment.map{ |k, v| [k.to_s, v.to_s] } ]
|
21
24
|
path_at_start = ENV['PATH']
|
22
25
|
begin
|
23
26
|
ENV['PATH'] = path_without_gem_dir()
|
24
27
|
@logger.debug("Temporarily setting PATH: #{ENV['PATH']}")
|
25
28
|
|
26
|
-
@logger.info("
|
27
|
-
shell_out = Mixlib::ShellOut.new(command, :timeout => timeout)
|
29
|
+
@logger.info("Executing: '#{command}'\n\ttimeout: #{timeout}\n\tenvironment: #{environment}")
|
30
|
+
shell_out = Mixlib::ShellOut.new(command, :timeout => timeout, :environment => environment)
|
28
31
|
shell_out.run_command()
|
29
32
|
shell_out.invalid! if shell_out.exitstatus != 0
|
30
33
|
|
@@ -77,7 +77,9 @@ module DaptivChefCI
|
|
77
77
|
|
78
78
|
def exec_cmd_with_retry(cmd, opts)
|
79
79
|
attempt ||= 1
|
80
|
-
|
80
|
+
environment ||= opts[:environment] || {}
|
81
|
+
timeout ||= opts[:cmd_timeout_in_seconds] || 600
|
82
|
+
@shell.exec_cmd(cmd, timeout, environment)
|
81
83
|
rescue Mixlib::ShellOut::ShellCommandFailed => e
|
82
84
|
@logger.warn("#{cmd} failed with error: #{e.message}")
|
83
85
|
raise if attempt > (opts[:retry_attempts] || 0)
|
@@ -11,6 +11,7 @@ class VagrantProvision
|
|
11
11
|
#
|
12
12
|
# VagrantProvision::RakeTask.new 'provision' do |t|
|
13
13
|
# t.provision_timeout_in_seconds = 3600
|
14
|
+
# t.environment = { :ENV_VAR1 => 'val1', :ENV_VAR2 => 'val2' }
|
14
15
|
# end
|
15
16
|
#
|
16
17
|
# This class lets you define Rake tasks to drive Vagrant.
|
@@ -20,6 +21,7 @@ class VagrantProvision
|
|
20
21
|
|
21
22
|
attr_accessor :vagrant_driver
|
22
23
|
attr_accessor :provision_timeout_in_seconds
|
24
|
+
attr_accessor :environment
|
23
25
|
|
24
26
|
# @param [String] name The task name.
|
25
27
|
# @param [String] desc Description of the task.
|
@@ -27,6 +29,7 @@ class VagrantProvision
|
|
27
29
|
def initialize(name = 'vagrant_provision', desc = 'Vagrant provision task')
|
28
30
|
@name, @desc = name, desc
|
29
31
|
@provision_timeout_in_seconds = 7200
|
32
|
+
@environment = {}
|
30
33
|
@vagrant_driver = DaptivChefCI::VagrantDriver.new()
|
31
34
|
yield self if block_given?
|
32
35
|
define_task
|
@@ -37,7 +40,12 @@ class VagrantProvision
|
|
37
40
|
def define_task
|
38
41
|
desc @desc
|
39
42
|
task @name do
|
40
|
-
execute {
|
43
|
+
execute {
|
44
|
+
@vagrant_driver.provision({
|
45
|
+
:cmd_timeout_in_seconds => @provision_timeout_in_seconds,
|
46
|
+
:environment => @environment
|
47
|
+
})
|
48
|
+
}
|
41
49
|
end
|
42
50
|
end
|
43
51
|
|
@@ -14,6 +14,7 @@ class Vagrant
|
|
14
14
|
# t.create_box = true
|
15
15
|
# t.box_name = 'windows-server-vmwarefusion.box'
|
16
16
|
# t.up_timeout_in_seconds = 3600
|
17
|
+
# t.environment = { :ENV_VAR1 => 'val1', :ENV_VAR2 => 'val2' }
|
17
18
|
# end
|
18
19
|
#
|
19
20
|
# This class lets you define Rake tasks to drive Vagrant.
|
@@ -31,6 +32,7 @@ class Vagrant
|
|
31
32
|
attr_accessor :destroy_timeout_in_seconds
|
32
33
|
attr_accessor :destroy_retry_attempts
|
33
34
|
attr_accessor :halt_retry_attempts
|
35
|
+
attr_accessor :environment
|
34
36
|
|
35
37
|
# @param [String] name The task name.
|
36
38
|
# @param [String] desc Description of the task.
|
@@ -46,6 +48,7 @@ class Vagrant
|
|
46
48
|
@destroy_timeout_in_seconds = 180
|
47
49
|
@destroy_retry_attempts = 2
|
48
50
|
@halt_retry_attempts = 2
|
51
|
+
@environment = {}
|
49
52
|
@vagrant_driver = DaptivChefCI::VagrantDriver.new(@provider)
|
50
53
|
yield self if block_given?
|
51
54
|
define_task
|
@@ -79,7 +82,10 @@ class Vagrant
|
|
79
82
|
end
|
80
83
|
|
81
84
|
def up()
|
82
|
-
@vagrant_driver.up({
|
85
|
+
@vagrant_driver.up({
|
86
|
+
:cmd_timeout_in_seconds => @up_timeout_in_seconds,
|
87
|
+
:environment => @environment
|
88
|
+
})
|
83
89
|
end
|
84
90
|
|
85
91
|
def package()
|
@@ -12,6 +12,7 @@ class VagrantUp
|
|
12
12
|
# VagrantUp::RakeTask.new 'up' do |t|
|
13
13
|
# t.provider = :vmware_fusion
|
14
14
|
# t.up_timeout_in_seconds = 3600
|
15
|
+
# t.environment = { :ENV_VAR1 => 'val1', :ENV_VAR2 => 'val2' }
|
15
16
|
# end
|
16
17
|
#
|
17
18
|
# This class lets you define Rake tasks to drive Vagrant.
|
@@ -22,6 +23,7 @@ class VagrantUp
|
|
22
23
|
attr_accessor :vagrant_driver
|
23
24
|
attr_accessor :provider
|
24
25
|
attr_accessor :up_timeout_in_seconds
|
26
|
+
attr_accessor :environment
|
25
27
|
|
26
28
|
# @param [String] name The task name.
|
27
29
|
# @param [String] desc Description of the task.
|
@@ -30,6 +32,7 @@ class VagrantUp
|
|
30
32
|
@name, @desc = name, desc
|
31
33
|
@provider = :virtualbox
|
32
34
|
@up_timeout_in_seconds = 7200
|
35
|
+
@environment = {}
|
33
36
|
@vagrant_driver = DaptivChefCI::VagrantDriver.new(@provider)
|
34
37
|
yield self if block_given?
|
35
38
|
define_task
|
@@ -40,7 +43,12 @@ class VagrantUp
|
|
40
43
|
def define_task
|
41
44
|
desc @desc
|
42
45
|
task @name do
|
43
|
-
execute {
|
46
|
+
execute {
|
47
|
+
@vagrant_driver.up({
|
48
|
+
:cmd_timeout_in_seconds => @up_timeout_in_seconds,
|
49
|
+
:environment => @environment
|
50
|
+
})
|
51
|
+
}
|
44
52
|
end
|
45
53
|
end
|
46
54
|
|
@@ -25,6 +25,18 @@ describe DaptivChefCI::Shell, :unit => true do
|
|
25
25
|
expect(ENV['PATH']).to eq(path_before)
|
26
26
|
end
|
27
27
|
|
28
|
+
it 'should pass long environment vars' do
|
29
|
+
shell = DaptivChefCI::Shell.new()
|
30
|
+
out = shell.exec_cmd('echo $ENV_VAR1', 600, { 'ENV_VAR1' => 'val1' })
|
31
|
+
expect(out[0]).to eq('val1')
|
32
|
+
end
|
33
|
+
|
34
|
+
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' })
|
37
|
+
expect(out[0]).to eq('val1')
|
38
|
+
end
|
39
|
+
|
28
40
|
end
|
29
41
|
|
30
42
|
describe 'path_without_gem_dir' do
|
@@ -12,14 +12,14 @@ describe DaptivChefCI::VagrantDriver, :unit => true do
|
|
12
12
|
|
13
13
|
describe 'destroy' do
|
14
14
|
it 'should force shutdown vagrant with a timeout of 180 seconds' do
|
15
|
-
@shell.should_receive(:exec_cmd).with('vagrant destroy -f', 180)
|
15
|
+
@shell.should_receive(:exec_cmd).with('vagrant destroy -f', 180, {})
|
16
16
|
@vagrant.destroy()
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
describe 'halt' do
|
21
21
|
it 'should halt vagrant with a timeout of 180 seconds' do
|
22
|
-
@shell.should_receive(:exec_cmd).with('vagrant halt', 180)
|
22
|
+
@shell.should_receive(:exec_cmd).with('vagrant halt', 180, {})
|
23
23
|
@vagrant.halt()
|
24
24
|
end
|
25
25
|
|
@@ -39,27 +39,39 @@ describe DaptivChefCI::VagrantDriver, :unit => true do
|
|
39
39
|
|
40
40
|
describe 'up' do
|
41
41
|
it 'should up vagrant with a timeout of 7200 seconds' do
|
42
|
-
@shell.should_receive(:exec_cmd).with('vagrant up', 7200)
|
42
|
+
@shell.should_receive(:exec_cmd).with('vagrant up', 7200, {})
|
43
43
|
@vagrant.up()
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'should up vagrant and specify the provider if not virtualbox' do
|
47
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)
|
48
|
+
@shell.should_receive(:exec_cmd).with('vagrant up --provider=my_custom_provider', 7200, {})
|
49
49
|
@vagrant.up()
|
50
50
|
end
|
51
|
+
|
52
|
+
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
|
+
end
|
51
57
|
end
|
52
58
|
|
53
59
|
describe 'provision' do
|
54
60
|
it 'should provision vagrant with a timeout of 7200 seconds' do
|
55
|
-
@shell.should_receive(:exec_cmd).with('vagrant provision', 7200)
|
61
|
+
@shell.should_receive(:exec_cmd).with('vagrant provision', 7200, {})
|
56
62
|
@vagrant.provision()
|
57
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
|
58
70
|
end
|
59
71
|
|
60
72
|
describe 'reload' do
|
61
73
|
it 'should reload vagrant with a timeout of 180 seconds' do
|
62
|
-
@shell.should_receive(:exec_cmd).with('vagrant reload', 180)
|
74
|
+
@shell.should_receive(:exec_cmd).with('vagrant reload', 180, {})
|
63
75
|
@vagrant.reload()
|
64
76
|
end
|
65
77
|
end
|
@@ -7,12 +7,23 @@ describe VagrantProvision::RakeTask, :unit => true do
|
|
7
7
|
describe 'vagrant_provision' do
|
8
8
|
it 'should provision the box' do
|
9
9
|
|
10
|
-
vagrant_driver.should_receive(:provision).with({ :cmd_timeout_in_seconds => 7200 })
|
10
|
+
vagrant_driver.should_receive(:provision).with({ :cmd_timeout_in_seconds => 7200, :environment => {} })
|
11
11
|
|
12
12
|
task = rake['vagrant_provision']
|
13
13
|
task.invoke()
|
14
14
|
|
15
15
|
end
|
16
|
+
|
17
|
+
it 'should up the box with the specified environment vars' do
|
18
|
+
|
19
|
+
environment = { :ENV_VAR1 => 'val1', :ENV_VAR2 => 'val2' }
|
20
|
+
vagrant_driver.should_receive(:provision).with({ :cmd_timeout_in_seconds => 7200, :environment => environment })
|
21
|
+
|
22
|
+
task = rake['vagrant_provision']
|
23
|
+
subject.environment = environment
|
24
|
+
task.invoke()
|
25
|
+
|
26
|
+
end
|
16
27
|
end
|
17
28
|
|
18
29
|
end
|
@@ -8,7 +8,7 @@ describe Vagrant::RakeTask, :unit => true do
|
|
8
8
|
it 'should destroy, up, halt, then destroy the box' do
|
9
9
|
|
10
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 })
|
11
|
+
vagrant_driver.should_receive(:up).with({ :cmd_timeout_in_seconds => 7200, :environment => {} })
|
12
12
|
vagrant_driver.should_receive(:halt).at_least(1).times.with({ :cmd_timeout_in_seconds => 180, :retry_attempts => 2 })
|
13
13
|
vagrant_driver.should_receive(:destroy).with({ :cmd_timeout_in_seconds => 180, :retry_attempts => 2 })
|
14
14
|
|
@@ -16,6 +16,21 @@ describe Vagrant::RakeTask, :unit => true do
|
|
16
16
|
task.invoke()
|
17
17
|
|
18
18
|
end
|
19
|
+
|
20
|
+
it 'should up the box with the specified environment vars' do
|
21
|
+
|
22
|
+
environment = { :ENV_VAR1 => 'val1', :ENV_VAR2 => 'val2' }
|
23
|
+
|
24
|
+
vagrant_driver.should_receive(:destroy).with({ :cmd_timeout_in_seconds => 180, :retry_attempts => 2 })
|
25
|
+
vagrant_driver.should_receive(:up).with({ :cmd_timeout_in_seconds => 7200, :environment => environment })
|
26
|
+
vagrant_driver.should_receive(:halt).at_least(1).times.with({ :cmd_timeout_in_seconds => 180, :retry_attempts => 2 })
|
27
|
+
vagrant_driver.should_receive(:destroy).with({ :cmd_timeout_in_seconds => 180, :retry_attempts => 2 })
|
28
|
+
|
29
|
+
task = rake['vagrant']
|
30
|
+
subject.environment = environment
|
31
|
+
task.invoke()
|
32
|
+
|
33
|
+
end
|
19
34
|
end
|
20
35
|
|
21
36
|
end
|
@@ -7,12 +7,23 @@ describe VagrantUp::RakeTask, :unit => true do
|
|
7
7
|
describe 'vagrant_up' do
|
8
8
|
it 'should up the box' do
|
9
9
|
|
10
|
-
vagrant_driver.should_receive(:up).with({ :cmd_timeout_in_seconds => 7200 })
|
10
|
+
vagrant_driver.should_receive(:up).with({ :cmd_timeout_in_seconds => 7200, :environment => {} })
|
11
11
|
|
12
12
|
task = rake['vagrant_up']
|
13
13
|
task.invoke()
|
14
14
|
|
15
15
|
end
|
16
|
+
|
17
|
+
it 'should up the box with the specified environment vars' do
|
18
|
+
|
19
|
+
environment = { :ENV_VAR1 => 'val1', :ENV_VAR2 => 'val2' }
|
20
|
+
vagrant_driver.should_receive(:up).with({ :cmd_timeout_in_seconds => 7200, :environment => environment })
|
21
|
+
|
22
|
+
task = rake['vagrant_up']
|
23
|
+
subject.environment = environment
|
24
|
+
task.invoke()
|
25
|
+
|
26
|
+
end
|
16
27
|
end
|
17
28
|
|
18
29
|
end
|
@@ -1,9 +1,13 @@
|
|
1
1
|
require "rake"
|
2
|
+
require 'daptiv-chef-ci/raketask_helper'
|
2
3
|
|
3
4
|
shared_context "rake" do
|
4
5
|
let(:rake) { create_rake_application() }
|
5
6
|
let(:vagrant_driver) { stub() }
|
6
7
|
|
8
|
+
# let the errors bubble up normally, don't exit the app
|
9
|
+
before { DaptivChefCI::RakeTaskHelpers.exit_on_failure = false }
|
10
|
+
|
7
11
|
def create_rake_application
|
8
12
|
Rake.application = Rake::Application.new
|
9
13
|
subject.vagrant_driver = vagrant_driver
|
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.
|
4
|
+
version: 0.0.10
|
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-
|
12
|
+
date: 2013-11-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: log4r
|
@@ -136,6 +136,7 @@ files:
|
|
136
136
|
- pkg/daptiv-chef-ci-0.0.6.gem
|
137
137
|
- pkg/daptiv-chef-ci-0.0.7.gem
|
138
138
|
- pkg/daptiv-chef-ci-0.0.8.gem
|
139
|
+
- pkg/daptiv-chef-ci-0.0.9.gem
|
139
140
|
- Rakefile
|
140
141
|
- README.md
|
141
142
|
- spec/daptiv-chef-ci/basebox_builder_factory_spec.rb
|
@@ -165,7 +166,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
165
166
|
version: '0'
|
166
167
|
segments:
|
167
168
|
- 0
|
168
|
-
hash:
|
169
|
+
hash: 2192685794471906068
|
169
170
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
170
171
|
none: false
|
171
172
|
requirements:
|
@@ -174,7 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
174
175
|
version: '0'
|
175
176
|
segments:
|
176
177
|
- 0
|
177
|
-
hash:
|
178
|
+
hash: 2192685794471906068
|
178
179
|
requirements: []
|
179
180
|
rubyforge_project:
|
180
181
|
rubygems_version: 1.8.23
|