vagrant 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -4
- data/Rakefile +3 -3
- data/VERSION +1 -1
- data/bin/vagrant +5 -13
- data/config/default.rb +1 -0
- data/keys/README.md +8 -1
- data/keys/vagrant.ppk +26 -0
- data/lib/vagrant.rb +3 -3
- data/lib/vagrant/actions/base.rb +15 -4
- data/lib/vagrant/actions/box/add.rb +1 -1
- data/lib/vagrant/actions/box/download.rb +72 -66
- data/lib/vagrant/actions/box/unpackage.rb +1 -4
- data/lib/vagrant/actions/runner.rb +1 -1
- data/lib/vagrant/actions/vm/boot.rb +5 -7
- data/lib/vagrant/actions/vm/customize.rb +2 -2
- data/lib/vagrant/actions/vm/destroy.rb +2 -2
- data/lib/vagrant/actions/vm/down.rb +7 -0
- data/lib/vagrant/actions/vm/export.rb +10 -4
- data/lib/vagrant/actions/vm/forward_ports.rb +5 -15
- data/lib/vagrant/actions/vm/halt.rb +5 -3
- data/lib/vagrant/actions/vm/import.rb +10 -3
- data/lib/vagrant/actions/vm/move_hard_drive.rb +1 -3
- data/lib/vagrant/actions/vm/package.rb +33 -10
- data/lib/vagrant/actions/vm/provision.rb +4 -4
- data/lib/vagrant/actions/vm/reload.rb +1 -1
- data/lib/vagrant/actions/vm/resume.rb +1 -1
- data/lib/vagrant/actions/vm/shared_folders.rb +7 -7
- data/lib/vagrant/actions/vm/start.rb +3 -2
- data/lib/vagrant/actions/vm/suspend.rb +2 -2
- data/lib/vagrant/actions/vm/up.rb +7 -17
- data/lib/vagrant/active_list.rb +52 -45
- data/lib/vagrant/box.rb +18 -11
- data/lib/vagrant/busy.rb +7 -0
- data/lib/vagrant/command.rb +27 -0
- data/lib/vagrant/commands/base.rb +163 -0
- data/lib/vagrant/commands/box.rb +16 -0
- data/lib/vagrant/commands/box/add.rb +24 -0
- data/lib/vagrant/commands/box/list.rb +30 -0
- data/lib/vagrant/commands/box/remove.rb +31 -0
- data/lib/vagrant/commands/destroy.rb +23 -0
- data/lib/vagrant/commands/down.rb +16 -0
- data/lib/vagrant/commands/halt.rb +23 -0
- data/lib/vagrant/commands/init.rb +32 -0
- data/lib/vagrant/commands/package.rb +46 -0
- data/lib/vagrant/commands/reload.rb +22 -0
- data/lib/vagrant/commands/resume.rb +22 -0
- data/lib/vagrant/commands/ssh.rb +22 -0
- data/lib/vagrant/commands/ssh_config.rb +30 -0
- data/lib/vagrant/commands/status.rb +58 -0
- data/lib/vagrant/commands/suspend.rb +23 -0
- data/lib/vagrant/commands/up.rb +26 -0
- data/lib/vagrant/config.rb +21 -11
- data/lib/vagrant/downloaders/file.rb +5 -5
- data/lib/vagrant/downloaders/http.rb +10 -15
- data/lib/vagrant/environment.rb +259 -0
- data/lib/vagrant/provisioners/base.rb +7 -0
- data/lib/vagrant/provisioners/chef.rb +24 -9
- data/lib/vagrant/provisioners/chef_server.rb +23 -48
- data/lib/vagrant/provisioners/chef_solo.rb +48 -22
- data/lib/vagrant/ssh.rb +95 -46
- data/lib/vagrant/util.rb +2 -2
- data/lib/vagrant/util/errors.rb +36 -0
- data/lib/vagrant/util/platform.rb +12 -0
- data/lib/vagrant/util/progress_meter.rb +33 -0
- data/lib/vagrant/util/stacked_proc_runner.rb +35 -0
- data/lib/vagrant/util/template_renderer.rb +83 -0
- data/lib/vagrant/vm.rb +1 -0
- data/templates/{Vagrantfile → Vagrantfile.erb} +2 -2
- data/templates/chef_server_client.erb +16 -0
- data/templates/chef_solo_solo.erb +4 -0
- data/templates/errors.yml +157 -0
- data/templates/package_Vagrantfile.erb +11 -0
- data/templates/ssh_config.erb +7 -0
- data/test/test_helper.rb +12 -15
- data/test/vagrant/actions/box/add_test.rb +1 -2
- data/test/vagrant/actions/box/destroy_test.rb +0 -1
- data/test/vagrant/actions/box/download_test.rb +40 -15
- data/test/vagrant/actions/box/unpackage_test.rb +2 -3
- data/test/vagrant/actions/collection_test.rb +8 -5
- data/test/vagrant/actions/runner_test.rb +8 -6
- data/test/vagrant/actions/vm/boot_test.rb +12 -11
- data/test/vagrant/actions/vm/customize_test.rb +2 -3
- data/test/vagrant/actions/vm/destroy_test.rb +2 -3
- data/test/vagrant/actions/vm/down_test.rb +16 -3
- data/test/vagrant/actions/vm/export_test.rb +4 -5
- data/test/vagrant/actions/vm/forward_ports_test.rb +6 -5
- data/test/vagrant/actions/vm/halt_test.rb +8 -2
- data/test/vagrant/actions/vm/import_test.rb +5 -5
- data/test/vagrant/actions/vm/move_hard_drive_test.rb +4 -6
- data/test/vagrant/actions/vm/package_test.rb +60 -22
- data/test/vagrant/actions/vm/provision_test.rb +7 -16
- data/test/vagrant/actions/vm/reload_test.rb +3 -2
- data/test/vagrant/actions/vm/resume_test.rb +0 -1
- data/test/vagrant/actions/vm/shared_folders_test.rb +17 -12
- data/test/vagrant/actions/vm/start_test.rb +10 -3
- data/test/vagrant/actions/vm/suspend_test.rb +1 -2
- data/test/vagrant/actions/vm/up_test.rb +19 -11
- data/test/vagrant/active_list_test.rb +148 -129
- data/test/vagrant/box_test.rb +26 -14
- data/test/vagrant/busy_test.rb +15 -6
- data/test/vagrant/command_test.rb +53 -0
- data/test/vagrant/commands/base_test.rb +118 -0
- data/test/vagrant/commands/box/add_test.rb +34 -0
- data/test/vagrant/commands/box/list_test.rb +32 -0
- data/test/vagrant/commands/box/remove_test.rb +41 -0
- data/test/vagrant/commands/destroy_test.rb +32 -0
- data/test/vagrant/commands/down_test.rb +17 -0
- data/test/vagrant/commands/halt_test.rb +28 -0
- data/test/vagrant/commands/init_test.rb +55 -0
- data/test/vagrant/commands/package_test.rb +84 -0
- data/test/vagrant/commands/reload_test.rb +28 -0
- data/test/vagrant/commands/resume_test.rb +33 -0
- data/test/vagrant/commands/ssh_config_test.rb +54 -0
- data/test/vagrant/commands/ssh_test.rb +32 -0
- data/test/vagrant/commands/status_test.rb +20 -0
- data/test/vagrant/commands/suspend_test.rb +33 -0
- data/test/vagrant/commands/up_test.rb +41 -0
- data/test/vagrant/config_test.rb +42 -17
- data/test/vagrant/downloaders/file_test.rb +7 -0
- data/test/vagrant/downloaders/http_test.rb +12 -0
- data/test/vagrant/environment_test.rb +595 -0
- data/test/vagrant/provisioners/base_test.rb +7 -1
- data/test/vagrant/provisioners/chef_server_test.rb +41 -51
- data/test/vagrant/provisioners/chef_solo_test.rb +93 -62
- data/test/vagrant/provisioners/chef_test.rb +61 -15
- data/test/vagrant/ssh_test.rb +166 -38
- data/test/vagrant/util/errors_test.rb +57 -0
- data/test/vagrant/util/progress_meter_test.rb +33 -0
- data/test/vagrant/{stacked_proc_runner_test.rb → util/stacked_proc_runner_test.rb} +3 -3
- data/test/vagrant/util/template_renderer_test.rb +138 -0
- data/test/vagrant/vm_test.rb +3 -2
- data/vagrant.gemspec +88 -33
- metadata +94 -51
- data/bin/vagrant-box +0 -34
- data/bin/vagrant-down +0 -27
- data/bin/vagrant-halt +0 -28
- data/bin/vagrant-init +0 -27
- data/bin/vagrant-package +0 -29
- data/bin/vagrant-reload +0 -29
- data/bin/vagrant-resume +0 -27
- data/bin/vagrant-ssh +0 -27
- data/bin/vagrant-status +0 -29
- data/bin/vagrant-suspend +0 -27
- data/bin/vagrant-up +0 -29
- data/lib/vagrant/commands.rb +0 -234
- data/lib/vagrant/env.rb +0 -189
- data/lib/vagrant/stacked_proc_runner.rb +0 -33
- data/test/vagrant/commands_test.rb +0 -269
- data/test/vagrant/env_test.rb +0 -418
@@ -1,6 +1,9 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
2
2
|
|
3
3
|
class ActionRunnerTest < Test::Unit::TestCase
|
4
|
+
class MockAction; end
|
5
|
+
class MockActionOther; end
|
6
|
+
|
4
7
|
def mock_fake_action(action_klass = nil, runner = nil)
|
5
8
|
action = action_klass ? action_klass.new(runner) : mock("action")
|
6
9
|
action.stubs(:prepare)
|
@@ -162,7 +165,7 @@ class ActionRunnerTest < Test::Unit::TestCase
|
|
162
165
|
[MockAction, MockActionOther].each_with_index do |klass, i|
|
163
166
|
action = mock("action#{i}")
|
164
167
|
action.expects(:class).returns(klass)
|
165
|
-
stub_default_action_dependecies(action
|
168
|
+
stub_default_action_dependecies(action)
|
166
169
|
@runner.actions << action
|
167
170
|
actions << action
|
168
171
|
end
|
@@ -212,11 +215,10 @@ class ActionRunnerTest < Test::Unit::TestCase
|
|
212
215
|
end
|
213
216
|
|
214
217
|
should "call error_and_exit if it is an ActionException" do
|
215
|
-
|
216
|
-
@exception = Vagrant::Actions::ActionException.new(msg)
|
218
|
+
@exception = Vagrant::Actions::ActionException.new("foo")
|
217
219
|
@actions[0].stubs(:prepare).raises(@exception)
|
218
220
|
|
219
|
-
@runner.expects(:error_and_exit).with(
|
221
|
+
@runner.expects(:error_and_exit).with(@exception.key, @exception.data).once
|
220
222
|
@runner.execute!
|
221
223
|
end
|
222
224
|
end
|
@@ -243,7 +245,7 @@ class ActionRunnerTest < Test::Unit::TestCase
|
|
243
245
|
setup do
|
244
246
|
@runner = Vagrant::Actions::Runner.new
|
245
247
|
end
|
246
|
-
|
248
|
+
|
247
249
|
should "should be raised when a duplicate is added" do
|
248
250
|
action = mock_fake_action
|
249
251
|
2.times {@runner.actions << action }
|
@@ -255,7 +257,7 @@ class ActionRunnerTest < Test::Unit::TestCase
|
|
255
257
|
should "should not be raise when no duplicate actions are present" do
|
256
258
|
@runner.actions << mock_fake_action(Vagrant::Actions::Base, @runner)
|
257
259
|
@runner.actions << mock_fake_action(Vagrant::Actions::VM::Halt, @runner)
|
258
|
-
|
260
|
+
|
259
261
|
assert_nothing_raised { @runner.execute! }
|
260
262
|
end
|
261
263
|
|
@@ -2,14 +2,13 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
|
2
2
|
|
3
3
|
class BootActionTest < Test::Unit::TestCase
|
4
4
|
setup do
|
5
|
-
@
|
6
|
-
@
|
7
|
-
mock_config
|
5
|
+
@runner, @vm, @action = mock_action(Vagrant::Actions::VM::Boot)
|
6
|
+
@runner.stubs(:invoke_callback)
|
8
7
|
end
|
9
8
|
|
10
9
|
context "preparing" do
|
11
10
|
should "add the root shared folder" do
|
12
|
-
|
11
|
+
@runner.env.config.vm.expects(:share_folder).with("v-root", @runner.env.config.vm.project_directory, @runner.env.root_path).once
|
13
12
|
@action.prepare
|
14
13
|
end
|
15
14
|
end
|
@@ -17,7 +16,7 @@ class BootActionTest < Test::Unit::TestCase
|
|
17
16
|
context "execution" do
|
18
17
|
should "invoke the 'boot' around callback" do
|
19
18
|
boot_seq = sequence("boot_seq")
|
20
|
-
@
|
19
|
+
@runner.expects(:invoke_around_callback).with(:boot).once.in_sequence(boot_seq).yields
|
21
20
|
@action.expects(:boot).in_sequence(boot_seq)
|
22
21
|
@action.expects(:wait_for_boot).returns(true).in_sequence(boot_seq)
|
23
22
|
@action.execute!
|
@@ -27,14 +26,16 @@ class BootActionTest < Test::Unit::TestCase
|
|
27
26
|
fail_boot_seq = sequence("fail_boot_seq")
|
28
27
|
@action.expects(:boot).once.in_sequence(fail_boot_seq)
|
29
28
|
@action.expects(:wait_for_boot).returns(false).in_sequence(fail_boot_seq)
|
30
|
-
@action.expects(:error_and_exit).once.in_sequence(fail_boot_seq)
|
29
|
+
@action.expects(:error_and_exit).with(:vm_failed_to_boot).once.in_sequence(fail_boot_seq)
|
31
30
|
@action.execute!
|
32
31
|
end
|
33
32
|
end
|
34
33
|
|
35
34
|
context "booting" do
|
36
|
-
should "start the VM in
|
37
|
-
|
35
|
+
should "start the VM in specified mode" do
|
36
|
+
mode = mock("boot_mode")
|
37
|
+
@runner.env.config.vm.boot_mode = mode
|
38
|
+
@vm.expects(:start).with(mode).once
|
38
39
|
@action.boot
|
39
40
|
end
|
40
41
|
end
|
@@ -42,13 +43,13 @@ class BootActionTest < Test::Unit::TestCase
|
|
42
43
|
context "waiting for boot" do
|
43
44
|
should "repeatedly ping the SSH port and return false with no response" do
|
44
45
|
seq = sequence('pings')
|
45
|
-
|
46
|
-
|
46
|
+
@runner.env.ssh.expects(:up?).times(@runner.env.config.ssh.max_tries.to_i - 1).returns(false).in_sequence(seq)
|
47
|
+
@runner.env.ssh.expects(:up?).once.returns(true).in_sequence(seq)
|
47
48
|
assert @action.wait_for_boot(0)
|
48
49
|
end
|
49
50
|
|
50
51
|
should "ping the max number of times then just return" do
|
51
|
-
|
52
|
+
@runner.env.ssh.expects(:up?).times(Vagrant.config.ssh.max_tries.to_i).returns(false)
|
52
53
|
assert !@action.wait_for_boot(0)
|
53
54
|
end
|
54
55
|
end
|
@@ -3,13 +3,12 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
|
3
3
|
class CustomizeActionTest < Test::Unit::TestCase
|
4
4
|
setup do
|
5
5
|
@runner, @vm, @action = mock_action(Vagrant::Actions::VM::Customize)
|
6
|
-
mock_config
|
7
6
|
end
|
8
7
|
|
9
8
|
context "executing" do
|
10
9
|
should "run the VM customization procs then save the VM" do
|
11
|
-
|
12
|
-
@vm.expects(:save).
|
10
|
+
@runner.env.config.vm.expects(:run_procs!).with(@vm)
|
11
|
+
@vm.expects(:save).once
|
13
12
|
@action.execute!
|
14
13
|
end
|
15
14
|
end
|
@@ -3,7 +3,6 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
|
3
3
|
class DestroyActionTest < Test::Unit::TestCase
|
4
4
|
setup do
|
5
5
|
@runner, @vm, @action = mock_action(Vagrant::Actions::VM::Destroy)
|
6
|
-
mock_config
|
7
6
|
end
|
8
7
|
|
9
8
|
context "executing" do
|
@@ -23,14 +22,14 @@ class DestroyActionTest < Test::Unit::TestCase
|
|
23
22
|
|
24
23
|
context "destroying the VM" do
|
25
24
|
should "destroy VM and attached images" do
|
26
|
-
@vm.expects(:destroy).with(:
|
25
|
+
@vm.expects(:destroy).with(:destroy_medium => :delete).once
|
27
26
|
@action.destroy_vm
|
28
27
|
end
|
29
28
|
end
|
30
29
|
|
31
30
|
context "depersisting" do
|
32
31
|
should "call depersist_vm on Env" do
|
33
|
-
|
32
|
+
@runner.env.expects(:depersist_vm).once
|
34
33
|
@action.depersist
|
35
34
|
end
|
36
35
|
end
|
@@ -2,8 +2,7 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
|
2
2
|
|
3
3
|
class DownActionTest < Test::Unit::TestCase
|
4
4
|
setup do
|
5
|
-
@
|
6
|
-
mock_config
|
5
|
+
@runner, @vm, @action = mock_action(Vagrant::Actions::VM::Down)
|
7
6
|
end
|
8
7
|
|
9
8
|
context "preparing" do
|
@@ -14,7 +13,7 @@ class DownActionTest < Test::Unit::TestCase
|
|
14
13
|
def setup_action_expectations(order)
|
15
14
|
default_seq = sequence("default_seq")
|
16
15
|
order.each do |action|
|
17
|
-
@
|
16
|
+
@runner.expects(:add_action).with(action).once.in_sequence(default_seq)
|
18
17
|
end
|
19
18
|
end
|
20
19
|
|
@@ -29,4 +28,18 @@ class DownActionTest < Test::Unit::TestCase
|
|
29
28
|
@action.prepare
|
30
29
|
end
|
31
30
|
end
|
31
|
+
|
32
|
+
context "after halting" do
|
33
|
+
should "sleep if boot mode is GUI" do
|
34
|
+
@runner.env.config.vm.boot_mode = "gui"
|
35
|
+
Kernel.expects(:sleep).once
|
36
|
+
@action.after_halt
|
37
|
+
end
|
38
|
+
|
39
|
+
should "not sleep if boot mode is anything else" do
|
40
|
+
@runner.env.config.vm.boot_mode = "vrdp"
|
41
|
+
Kernel.expects(:sleep).never
|
42
|
+
@action.after_halt
|
43
|
+
end
|
44
|
+
end
|
32
45
|
end
|
@@ -3,7 +3,6 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
|
3
3
|
class ExportActionTest < Test::Unit::TestCase
|
4
4
|
setup do
|
5
5
|
@runner, @vm, @action = mock_action(Vagrant::Actions::VM::Export)
|
6
|
-
mock_config
|
7
6
|
end
|
8
7
|
|
9
8
|
context "executing" do
|
@@ -21,9 +20,9 @@ class ExportActionTest < Test::Unit::TestCase
|
|
21
20
|
Time.stubs(:now).returns(@time_now)
|
22
21
|
|
23
22
|
@tmp_path = "foo"
|
24
|
-
|
23
|
+
@runner.env.stubs(:tmp_path).returns(@tmp_path)
|
25
24
|
|
26
|
-
@temp_dir = File.join(
|
25
|
+
@temp_dir = File.join(@runner.env.tmp_path, @time_now)
|
27
26
|
FileUtils.stubs(:mkpath)
|
28
27
|
end
|
29
28
|
|
@@ -45,7 +44,7 @@ class ExportActionTest < Test::Unit::TestCase
|
|
45
44
|
end
|
46
45
|
|
47
46
|
should "be the temporary directory joined with the OVF filename" do
|
48
|
-
assert_equal File.join(@temp_dir,
|
47
|
+
assert_equal File.join(@temp_dir, @runner.env.config.vm.box_ovf), @action.ovf_path
|
49
48
|
end
|
50
49
|
end
|
51
50
|
|
@@ -56,7 +55,7 @@ class ExportActionTest < Test::Unit::TestCase
|
|
56
55
|
end
|
57
56
|
|
58
57
|
should "call export on the runner with the ovf path" do
|
59
|
-
@vm.expects(:export).with(@ovf_path
|
58
|
+
@vm.expects(:export).with(@ovf_path).once
|
60
59
|
@action.export
|
61
60
|
end
|
62
61
|
end
|
@@ -3,7 +3,6 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
|
3
3
|
class ForwardPortsActionTest < Test::Unit::TestCase
|
4
4
|
setup do
|
5
5
|
@mock_vm, @vm, @action = mock_action(Vagrant::Actions::VM::ForwardPorts)
|
6
|
-
mock_config
|
7
6
|
end
|
8
7
|
|
9
8
|
context "checking for colliding ports" do
|
@@ -20,10 +19,12 @@ class ForwardPortsActionTest < Test::Unit::TestCase
|
|
20
19
|
vms = [@vm]
|
21
20
|
VirtualBox::VM.stubs(:all).returns(vms)
|
22
21
|
|
23
|
-
|
22
|
+
@env = mock_environment do |config|
|
24
23
|
config.vm.forwarded_ports.clear
|
25
24
|
config.vm.forward_port("ssh", 22, 2222)
|
26
25
|
end
|
26
|
+
|
27
|
+
@mock_vm.stubs(:env).returns(@env)
|
27
28
|
end
|
28
29
|
|
29
30
|
should "ignore vms which aren't running" do
|
@@ -71,7 +72,7 @@ class ForwardPortsActionTest < Test::Unit::TestCase
|
|
71
72
|
should "create a port forwarding for the VM" do
|
72
73
|
forwarded_ports = mock("forwarded_ports")
|
73
74
|
|
74
|
-
|
75
|
+
@mock_vm.env.config.vm.forwarded_ports.each do |name, opts|
|
75
76
|
forwarded_ports.expects(:<<).with do |port|
|
76
77
|
assert_equal name, port.name
|
77
78
|
assert_equal opts[:hostport], port.hostport
|
@@ -81,7 +82,7 @@ class ForwardPortsActionTest < Test::Unit::TestCase
|
|
81
82
|
end
|
82
83
|
|
83
84
|
@vm.expects(:forwarded_ports).returns(forwarded_ports)
|
84
|
-
@vm.expects(:save).
|
85
|
+
@vm.expects(:save).once
|
85
86
|
@action.forward_ports
|
86
87
|
end
|
87
88
|
end
|
@@ -91,7 +92,7 @@ class ForwardPortsActionTest < Test::Unit::TestCase
|
|
91
92
|
forwarded_ports = []
|
92
93
|
5.times do |i|
|
93
94
|
port = mock("port#{i}")
|
94
|
-
port.expects(:destroy).
|
95
|
+
port.expects(:destroy).once
|
95
96
|
forwarded_ports << port
|
96
97
|
end
|
97
98
|
|
@@ -3,7 +3,6 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
|
3
3
|
class HaltActionTest < Test::Unit::TestCase
|
4
4
|
setup do
|
5
5
|
@runner, @vm, @action = mock_action(Vagrant::Actions::VM::Halt)
|
6
|
-
mock_config
|
7
6
|
end
|
8
7
|
|
9
8
|
context "executing" do
|
@@ -11,8 +10,15 @@ class HaltActionTest < Test::Unit::TestCase
|
|
11
10
|
@vm.stubs(:running?).returns(true)
|
12
11
|
end
|
13
12
|
|
13
|
+
should "invoke the 'halt' around callback" do
|
14
|
+
halt_seq = sequence("halt_seq")
|
15
|
+
@runner.expects(:invoke_around_callback).with(:halt).once.in_sequence(halt_seq).yields
|
16
|
+
@vm.expects(:stop).in_sequence(halt_seq)
|
17
|
+
@action.execute!
|
18
|
+
end
|
19
|
+
|
14
20
|
should "force the VM to stop" do
|
15
|
-
@vm.expects(:stop).
|
21
|
+
@vm.expects(:stop).once
|
16
22
|
@action.execute!
|
17
23
|
end
|
18
24
|
|
@@ -2,12 +2,12 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
|
2
2
|
|
3
3
|
class ImportActionTest < Test::Unit::TestCase
|
4
4
|
setup do
|
5
|
-
@
|
5
|
+
@runner, @vm, @import = mock_action(Vagrant::Actions::VM::Import)
|
6
6
|
|
7
7
|
@ovf_file = "foo"
|
8
8
|
@box = mock("box")
|
9
9
|
@box.stubs(:ovf_file).returns(@ovf_file)
|
10
|
-
|
10
|
+
@runner.env.stubs(:box).returns(@box)
|
11
11
|
|
12
12
|
VirtualBox::VM.stubs(:import)
|
13
13
|
end
|
@@ -18,7 +18,7 @@ class ImportActionTest < Test::Unit::TestCase
|
|
18
18
|
end
|
19
19
|
|
20
20
|
should "invoke an around callback around the import" do
|
21
|
-
@
|
21
|
+
@runner.expects(:invoke_around_callback).with(:import).once
|
22
22
|
@import.execute!
|
23
23
|
end
|
24
24
|
|
@@ -28,7 +28,7 @@ class ImportActionTest < Test::Unit::TestCase
|
|
28
28
|
end
|
29
29
|
|
30
30
|
should "raise an exception if import is nil" do
|
31
|
-
@
|
31
|
+
@runner.expects(:vm).returns(nil)
|
32
32
|
assert_raises(Vagrant::Actions::ActionException) {
|
33
33
|
@import.execute!
|
34
34
|
}
|
@@ -36,7 +36,7 @@ class ImportActionTest < Test::Unit::TestCase
|
|
36
36
|
|
37
37
|
should "set the resulting VM as the VM of the Vagrant VM object" do
|
38
38
|
new_vm = mock("new_vm")
|
39
|
-
@
|
39
|
+
@runner.expects(:vm=).with(new_vm).once
|
40
40
|
VirtualBox::VM.expects(:import).returns(new_vm).returns("foo")
|
41
41
|
@import.execute!
|
42
42
|
end
|
@@ -4,10 +4,8 @@ class MoveHardDriveActionTest < Test::Unit::TestCase
|
|
4
4
|
setup do
|
5
5
|
@mock_vm, @vm, @action = mock_action(Vagrant::Actions::VM::MoveHardDrive)
|
6
6
|
@hd_location = "/foo"
|
7
|
-
|
8
|
-
|
9
|
-
config.vm.hd_location = @hd_location
|
10
|
-
end
|
7
|
+
|
8
|
+
@mock_vm.env.config.vm.stubs(:hd_location).returns(@hd_location)
|
11
9
|
end
|
12
10
|
|
13
11
|
|
@@ -28,7 +26,7 @@ class MoveHardDriveActionTest < Test::Unit::TestCase
|
|
28
26
|
context "execution" do
|
29
27
|
should "error and exit if the vm is not powered off" do
|
30
28
|
@mock_vm.expects(:powered_off?).returns(false)
|
31
|
-
@action.expects(:error_and_exit).once
|
29
|
+
@action.expects(:error_and_exit).with(:vm_power_off_to_move_hd).once
|
32
30
|
@action.execute!
|
33
31
|
end
|
34
32
|
|
@@ -51,7 +49,7 @@ class MoveHardDriveActionTest < Test::Unit::TestCase
|
|
51
49
|
end
|
52
50
|
|
53
51
|
should "be the configured hd location and the existing hard drive filename" do
|
54
|
-
joined = File.join(
|
52
|
+
joined = File.join(@mock_vm.env.config.vm.hd_location, @filename)
|
55
53
|
assert_equal joined, @action.new_image_path
|
56
54
|
end
|
57
55
|
end
|
@@ -3,8 +3,6 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
|
3
3
|
class PackageActionTest < Test::Unit::TestCase
|
4
4
|
setup do
|
5
5
|
@runner, @vm, @action = mock_action(Vagrant::Actions::VM::Package, "bing", [])
|
6
|
-
|
7
|
-
mock_config
|
8
6
|
end
|
9
7
|
|
10
8
|
context "initialization" do
|
@@ -41,7 +39,7 @@ class PackageActionTest < Test::Unit::TestCase
|
|
41
39
|
should "be the temporary directory with the name and extension attached" do
|
42
40
|
pwd = "foo"
|
43
41
|
FileUtils.stubs(:pwd).returns(pwd)
|
44
|
-
assert_equal File.join(pwd, "#{@action.out_path}#{
|
42
|
+
assert_equal File.join(pwd, "#{@action.out_path}#{@runner.env.config.package.extension}"), @action.tar_path
|
45
43
|
end
|
46
44
|
end
|
47
45
|
|
@@ -58,6 +56,60 @@ class PackageActionTest < Test::Unit::TestCase
|
|
58
56
|
end
|
59
57
|
end
|
60
58
|
|
59
|
+
context "copying include files" do
|
60
|
+
setup do
|
61
|
+
@include_files = []
|
62
|
+
@action.stubs(:include_files).returns(@include_files)
|
63
|
+
|
64
|
+
@temp_path = "foo"
|
65
|
+
@action.stubs(:temp_path).returns(@temp_path)
|
66
|
+
end
|
67
|
+
|
68
|
+
should "do nothing if no include files are specified" do
|
69
|
+
assert @action.include_files.empty?
|
70
|
+
FileUtils.expects(:mkdir_p).never
|
71
|
+
FileUtils.expects(:cp).never
|
72
|
+
@action.copy_include_files
|
73
|
+
end
|
74
|
+
|
75
|
+
should "create the include directory and copy files to it" do
|
76
|
+
include_dir = File.join(@action.temp_path, "include")
|
77
|
+
copy_seq = sequence("copy_seq")
|
78
|
+
FileUtils.expects(:mkdir_p).with(include_dir).once.in_sequence(copy_seq)
|
79
|
+
|
80
|
+
5.times do |i|
|
81
|
+
file = mock("f#{i}")
|
82
|
+
@include_files << file
|
83
|
+
FileUtils.expects(:cp).with(file, include_dir).in_sequence(copy_seq)
|
84
|
+
end
|
85
|
+
|
86
|
+
@action.copy_include_files
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context "creating vagrantfile" do
|
91
|
+
setup do
|
92
|
+
@temp_path = "foo"
|
93
|
+
@action.stubs(:temp_path).returns(@temp_path)
|
94
|
+
|
95
|
+
@network_adapter = mock("nic")
|
96
|
+
@network_adapter.stubs(:mac_address).returns("mac_address")
|
97
|
+
@vm.stubs(:network_adapters).returns([@network_adapter])
|
98
|
+
end
|
99
|
+
|
100
|
+
should "write the rendered vagrantfile to temp_path Vagrantfile" do
|
101
|
+
f = mock("file")
|
102
|
+
rendered = mock("rendered")
|
103
|
+
File.expects(:open).with(File.join(@action.temp_path, "Vagrantfile"), "w").yields(f)
|
104
|
+
Vagrant::Util::TemplateRenderer.expects(:render).returns(rendered).with("package_Vagrantfile", {
|
105
|
+
:base_mac => @runner.vm.network_adapters.first.mac_address
|
106
|
+
})
|
107
|
+
f.expects(:write).with(rendered)
|
108
|
+
|
109
|
+
@action.create_vagrantfile
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
61
113
|
context "compression" do
|
62
114
|
setup do
|
63
115
|
@tar_path = "foo"
|
@@ -80,6 +132,9 @@ class PackageActionTest < Test::Unit::TestCase
|
|
80
132
|
@tar = Archive::Tar::Minitar
|
81
133
|
Archive::Tar::Minitar::Output.stubs(:open).yields(@output)
|
82
134
|
@tar.stubs(:pack_file)
|
135
|
+
|
136
|
+
@action.stubs(:copy_include_files)
|
137
|
+
@action.stubs(:create_vagrantfile)
|
83
138
|
end
|
84
139
|
|
85
140
|
should "open the tar file with the tar path properly" do
|
@@ -100,6 +155,8 @@ class PackageActionTest < Test::Unit::TestCase
|
|
100
155
|
compress_seq = sequence("compress_seq")
|
101
156
|
|
102
157
|
FileUtils.expects(:pwd).once.returns(@pwd).in_sequence(compress_seq)
|
158
|
+
@action.expects(:copy_include_files).once.in_sequence(compress_seq)
|
159
|
+
@action.expects(:create_vagrantfile).once.in_sequence(compress_seq)
|
103
160
|
FileUtils.expects(:cd).with(@temp_path).in_sequence(compress_seq)
|
104
161
|
Dir.expects(:glob).returns(@files).in_sequence(compress_seq)
|
105
162
|
|
@@ -122,25 +179,6 @@ class PackageActionTest < Test::Unit::TestCase
|
|
122
179
|
@action.compress
|
123
180
|
}
|
124
181
|
end
|
125
|
-
|
126
|
-
should "add included files when passed" do
|
127
|
-
compress_seq = sequence("compress")
|
128
|
-
@files = []
|
129
|
-
5.times do |i|
|
130
|
-
file = mock("file#{i}")
|
131
|
-
@tar.expects(:pack_file).with(file, @output).once.in_sequence(compress_seq)
|
132
|
-
@files << file
|
133
|
-
end
|
134
|
-
|
135
|
-
@action.expects(:include_files).returns(@files)
|
136
|
-
@action.compress
|
137
|
-
end
|
138
|
-
|
139
|
-
should "not add files when none are specified" do
|
140
|
-
@tar.expects(:pack_file).never
|
141
|
-
Dir.expects(:glob).once.returns([])
|
142
|
-
@action.compress
|
143
|
-
end
|
144
182
|
end
|
145
183
|
|
146
184
|
context "preparing the action" do
|