vagrant 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (149) hide show
  1. data/Gemfile +4 -4
  2. data/Rakefile +3 -3
  3. data/VERSION +1 -1
  4. data/bin/vagrant +5 -13
  5. data/config/default.rb +1 -0
  6. data/keys/README.md +8 -1
  7. data/keys/vagrant.ppk +26 -0
  8. data/lib/vagrant.rb +3 -3
  9. data/lib/vagrant/actions/base.rb +15 -4
  10. data/lib/vagrant/actions/box/add.rb +1 -1
  11. data/lib/vagrant/actions/box/download.rb +72 -66
  12. data/lib/vagrant/actions/box/unpackage.rb +1 -4
  13. data/lib/vagrant/actions/runner.rb +1 -1
  14. data/lib/vagrant/actions/vm/boot.rb +5 -7
  15. data/lib/vagrant/actions/vm/customize.rb +2 -2
  16. data/lib/vagrant/actions/vm/destroy.rb +2 -2
  17. data/lib/vagrant/actions/vm/down.rb +7 -0
  18. data/lib/vagrant/actions/vm/export.rb +10 -4
  19. data/lib/vagrant/actions/vm/forward_ports.rb +5 -15
  20. data/lib/vagrant/actions/vm/halt.rb +5 -3
  21. data/lib/vagrant/actions/vm/import.rb +10 -3
  22. data/lib/vagrant/actions/vm/move_hard_drive.rb +1 -3
  23. data/lib/vagrant/actions/vm/package.rb +33 -10
  24. data/lib/vagrant/actions/vm/provision.rb +4 -4
  25. data/lib/vagrant/actions/vm/reload.rb +1 -1
  26. data/lib/vagrant/actions/vm/resume.rb +1 -1
  27. data/lib/vagrant/actions/vm/shared_folders.rb +7 -7
  28. data/lib/vagrant/actions/vm/start.rb +3 -2
  29. data/lib/vagrant/actions/vm/suspend.rb +2 -2
  30. data/lib/vagrant/actions/vm/up.rb +7 -17
  31. data/lib/vagrant/active_list.rb +52 -45
  32. data/lib/vagrant/box.rb +18 -11
  33. data/lib/vagrant/busy.rb +7 -0
  34. data/lib/vagrant/command.rb +27 -0
  35. data/lib/vagrant/commands/base.rb +163 -0
  36. data/lib/vagrant/commands/box.rb +16 -0
  37. data/lib/vagrant/commands/box/add.rb +24 -0
  38. data/lib/vagrant/commands/box/list.rb +30 -0
  39. data/lib/vagrant/commands/box/remove.rb +31 -0
  40. data/lib/vagrant/commands/destroy.rb +23 -0
  41. data/lib/vagrant/commands/down.rb +16 -0
  42. data/lib/vagrant/commands/halt.rb +23 -0
  43. data/lib/vagrant/commands/init.rb +32 -0
  44. data/lib/vagrant/commands/package.rb +46 -0
  45. data/lib/vagrant/commands/reload.rb +22 -0
  46. data/lib/vagrant/commands/resume.rb +22 -0
  47. data/lib/vagrant/commands/ssh.rb +22 -0
  48. data/lib/vagrant/commands/ssh_config.rb +30 -0
  49. data/lib/vagrant/commands/status.rb +58 -0
  50. data/lib/vagrant/commands/suspend.rb +23 -0
  51. data/lib/vagrant/commands/up.rb +26 -0
  52. data/lib/vagrant/config.rb +21 -11
  53. data/lib/vagrant/downloaders/file.rb +5 -5
  54. data/lib/vagrant/downloaders/http.rb +10 -15
  55. data/lib/vagrant/environment.rb +259 -0
  56. data/lib/vagrant/provisioners/base.rb +7 -0
  57. data/lib/vagrant/provisioners/chef.rb +24 -9
  58. data/lib/vagrant/provisioners/chef_server.rb +23 -48
  59. data/lib/vagrant/provisioners/chef_solo.rb +48 -22
  60. data/lib/vagrant/ssh.rb +95 -46
  61. data/lib/vagrant/util.rb +2 -2
  62. data/lib/vagrant/util/errors.rb +36 -0
  63. data/lib/vagrant/util/platform.rb +12 -0
  64. data/lib/vagrant/util/progress_meter.rb +33 -0
  65. data/lib/vagrant/util/stacked_proc_runner.rb +35 -0
  66. data/lib/vagrant/util/template_renderer.rb +83 -0
  67. data/lib/vagrant/vm.rb +1 -0
  68. data/templates/{Vagrantfile → Vagrantfile.erb} +2 -2
  69. data/templates/chef_server_client.erb +16 -0
  70. data/templates/chef_solo_solo.erb +4 -0
  71. data/templates/errors.yml +157 -0
  72. data/templates/package_Vagrantfile.erb +11 -0
  73. data/templates/ssh_config.erb +7 -0
  74. data/test/test_helper.rb +12 -15
  75. data/test/vagrant/actions/box/add_test.rb +1 -2
  76. data/test/vagrant/actions/box/destroy_test.rb +0 -1
  77. data/test/vagrant/actions/box/download_test.rb +40 -15
  78. data/test/vagrant/actions/box/unpackage_test.rb +2 -3
  79. data/test/vagrant/actions/collection_test.rb +8 -5
  80. data/test/vagrant/actions/runner_test.rb +8 -6
  81. data/test/vagrant/actions/vm/boot_test.rb +12 -11
  82. data/test/vagrant/actions/vm/customize_test.rb +2 -3
  83. data/test/vagrant/actions/vm/destroy_test.rb +2 -3
  84. data/test/vagrant/actions/vm/down_test.rb +16 -3
  85. data/test/vagrant/actions/vm/export_test.rb +4 -5
  86. data/test/vagrant/actions/vm/forward_ports_test.rb +6 -5
  87. data/test/vagrant/actions/vm/halt_test.rb +8 -2
  88. data/test/vagrant/actions/vm/import_test.rb +5 -5
  89. data/test/vagrant/actions/vm/move_hard_drive_test.rb +4 -6
  90. data/test/vagrant/actions/vm/package_test.rb +60 -22
  91. data/test/vagrant/actions/vm/provision_test.rb +7 -16
  92. data/test/vagrant/actions/vm/reload_test.rb +3 -2
  93. data/test/vagrant/actions/vm/resume_test.rb +0 -1
  94. data/test/vagrant/actions/vm/shared_folders_test.rb +17 -12
  95. data/test/vagrant/actions/vm/start_test.rb +10 -3
  96. data/test/vagrant/actions/vm/suspend_test.rb +1 -2
  97. data/test/vagrant/actions/vm/up_test.rb +19 -11
  98. data/test/vagrant/active_list_test.rb +148 -129
  99. data/test/vagrant/box_test.rb +26 -14
  100. data/test/vagrant/busy_test.rb +15 -6
  101. data/test/vagrant/command_test.rb +53 -0
  102. data/test/vagrant/commands/base_test.rb +118 -0
  103. data/test/vagrant/commands/box/add_test.rb +34 -0
  104. data/test/vagrant/commands/box/list_test.rb +32 -0
  105. data/test/vagrant/commands/box/remove_test.rb +41 -0
  106. data/test/vagrant/commands/destroy_test.rb +32 -0
  107. data/test/vagrant/commands/down_test.rb +17 -0
  108. data/test/vagrant/commands/halt_test.rb +28 -0
  109. data/test/vagrant/commands/init_test.rb +55 -0
  110. data/test/vagrant/commands/package_test.rb +84 -0
  111. data/test/vagrant/commands/reload_test.rb +28 -0
  112. data/test/vagrant/commands/resume_test.rb +33 -0
  113. data/test/vagrant/commands/ssh_config_test.rb +54 -0
  114. data/test/vagrant/commands/ssh_test.rb +32 -0
  115. data/test/vagrant/commands/status_test.rb +20 -0
  116. data/test/vagrant/commands/suspend_test.rb +33 -0
  117. data/test/vagrant/commands/up_test.rb +41 -0
  118. data/test/vagrant/config_test.rb +42 -17
  119. data/test/vagrant/downloaders/file_test.rb +7 -0
  120. data/test/vagrant/downloaders/http_test.rb +12 -0
  121. data/test/vagrant/environment_test.rb +595 -0
  122. data/test/vagrant/provisioners/base_test.rb +7 -1
  123. data/test/vagrant/provisioners/chef_server_test.rb +41 -51
  124. data/test/vagrant/provisioners/chef_solo_test.rb +93 -62
  125. data/test/vagrant/provisioners/chef_test.rb +61 -15
  126. data/test/vagrant/ssh_test.rb +166 -38
  127. data/test/vagrant/util/errors_test.rb +57 -0
  128. data/test/vagrant/util/progress_meter_test.rb +33 -0
  129. data/test/vagrant/{stacked_proc_runner_test.rb → util/stacked_proc_runner_test.rb} +3 -3
  130. data/test/vagrant/util/template_renderer_test.rb +138 -0
  131. data/test/vagrant/vm_test.rb +3 -2
  132. data/vagrant.gemspec +88 -33
  133. metadata +94 -51
  134. data/bin/vagrant-box +0 -34
  135. data/bin/vagrant-down +0 -27
  136. data/bin/vagrant-halt +0 -28
  137. data/bin/vagrant-init +0 -27
  138. data/bin/vagrant-package +0 -29
  139. data/bin/vagrant-reload +0 -29
  140. data/bin/vagrant-resume +0 -27
  141. data/bin/vagrant-ssh +0 -27
  142. data/bin/vagrant-status +0 -29
  143. data/bin/vagrant-suspend +0 -27
  144. data/bin/vagrant-up +0 -29
  145. data/lib/vagrant/commands.rb +0 -234
  146. data/lib/vagrant/env.rb +0 -189
  147. data/lib/vagrant/stacked_proc_runner.rb +0 -33
  148. data/test/vagrant/commands_test.rb +0 -269
  149. 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, klass)
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
- msg = "Message"
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(msg).once
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
- @mock_vm, @vm, @action = mock_action(Vagrant::Actions::VM::Boot)
6
- @mock_vm.stubs(:invoke_callback)
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
- Vagrant.config.vm.expects(:share_folder).with("vagrant-root", Vagrant.config.vm.project_directory, Vagrant::Env.root_path).once
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
- @mock_vm.expects(:invoke_around_callback).with(:boot).once.in_sequence(boot_seq).yields
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 headless mode" do
37
- @vm.expects(:start).with(:headless, true).once
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
- Vagrant::SSH.expects(:up?).times(Vagrant.config[:ssh][:max_tries].to_i - 1).returns(false).in_sequence(seq)
46
- Vagrant::SSH.expects(:up?).once.returns(true).in_sequence(seq)
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
- Vagrant::SSH.expects(:up?).times(Vagrant.config[:ssh][:max_tries].to_i).returns(false)
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
- Vagrant.config.vm.expects(:run_procs!).with(@vm)
12
- @vm.expects(:save).with(true).once
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(:destroy_image => true).once
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
- Vagrant::Env.expects(:depersist_vm).with(@runner).once
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
- @mock_vm, @vm, @action = mock_action(Vagrant::Actions::VM::Down)
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
- @mock_vm.expects(:add_action).with(action).once.in_sequence(default_seq)
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
- Vagrant::Env.stubs(:tmp_path).returns(@tmp_path)
23
+ @runner.env.stubs(:tmp_path).returns(@tmp_path)
25
24
 
26
- @temp_dir = File.join(Vagrant::Env.tmp_path, @time_now)
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, Vagrant.config.vm.box_ovf), @action.ovf_path
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, {}, true).once
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
- mock_config do |config|
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
- Vagrant.config.vm.forwarded_ports.each do |name, opts|
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).with(true).once
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).with(true).once
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).with(true).once
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
- @mock_vm, @vm, @import = mock_action(Vagrant::Actions::VM::Import)
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
- Vagrant::Env.stubs(:box).returns(@box)
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
- @mock_vm.expects(:invoke_around_callback).with(:import).once
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
- @mock_vm.expects(:vm).returns(nil)
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
- @mock_vm.expects(:vm=).with(new_vm).once
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
- mock_config do |config|
8
- File.expects(:directory?).with(@hd_location).returns(true)
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(Vagrant.config.vm.hd_location, @filename)
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}#{Vagrant.config.package.extension}"), @action.tar_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