vagrantup 0.5.4 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (235) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.yardopts +1 -0
  4. data/CHANGELOG.md +56 -0
  5. data/Gemfile +14 -3
  6. data/Gemfile.lock +38 -11
  7. data/README.md +1 -1
  8. data/bin/vagrant +20 -5
  9. data/config/default.rb +6 -8
  10. data/lib/vagrant.rb +40 -13
  11. data/lib/vagrant/action.rb +56 -16
  12. data/lib/vagrant/action/box/destroy.rb +3 -1
  13. data/lib/vagrant/action/box/download.rb +8 -13
  14. data/lib/vagrant/action/box/unpackage.rb +8 -11
  15. data/lib/vagrant/action/box/verify.rb +3 -3
  16. data/lib/vagrant/action/builder.rb +3 -30
  17. data/lib/vagrant/action/builtin.rb +6 -1
  18. data/lib/vagrant/action/environment.rb +14 -62
  19. data/lib/vagrant/action/general/package.rb +29 -22
  20. data/lib/vagrant/action/vm/boot.rb +5 -12
  21. data/lib/vagrant/action/vm/check_box.rb +4 -4
  22. data/lib/vagrant/action/vm/check_guest_additions.rb +4 -6
  23. data/lib/vagrant/action/vm/clear_forwarded_ports.rb +2 -2
  24. data/lib/vagrant/action/vm/clear_nfs_exports.rb +1 -1
  25. data/lib/vagrant/action/vm/clear_shared_folders.rb +1 -1
  26. data/lib/vagrant/action/vm/customize.rb +1 -1
  27. data/lib/vagrant/action/vm/destroy.rb +1 -2
  28. data/lib/vagrant/action/vm/destroy_unused_network_interfaces.rb +1 -1
  29. data/lib/vagrant/action/vm/disable_networks.rb +11 -9
  30. data/lib/vagrant/action/vm/discard_state.rb +2 -2
  31. data/lib/vagrant/action/vm/export.rb +10 -11
  32. data/lib/vagrant/action/vm/forward_ports.rb +21 -9
  33. data/lib/vagrant/action/vm/halt.rb +3 -8
  34. data/lib/vagrant/action/vm/import.rb +16 -14
  35. data/lib/vagrant/action/vm/match_mac_address.rb +1 -1
  36. data/lib/vagrant/action/vm/network.rb +9 -16
  37. data/lib/vagrant/action/vm/nfs.rb +14 -18
  38. data/lib/vagrant/action/vm/provision.rb +5 -5
  39. data/lib/vagrant/action/vm/resume.rb +1 -1
  40. data/lib/vagrant/action/vm/share_folders.rb +6 -44
  41. data/lib/vagrant/action/vm/suspend.rb +1 -1
  42. data/lib/vagrant/action/warden.rb +74 -0
  43. data/lib/vagrant/box.rb +18 -82
  44. data/lib/vagrant/box_collection.rb +47 -0
  45. data/lib/vagrant/cli.rb +55 -0
  46. data/lib/vagrant/command/base.rb +106 -0
  47. data/lib/vagrant/command/box.rb +33 -0
  48. data/lib/vagrant/command/destroy.rb +17 -0
  49. data/lib/vagrant/command/group_base.rb +99 -0
  50. data/lib/vagrant/command/halt.rb +18 -0
  51. data/lib/vagrant/command/helpers.rb +33 -0
  52. data/lib/vagrant/command/init.rb +14 -0
  53. data/lib/vagrant/command/named_base.rb +14 -0
  54. data/lib/vagrant/command/package.rb +41 -0
  55. data/lib/vagrant/command/provision.rb +17 -0
  56. data/lib/vagrant/command/reload.rb +17 -0
  57. data/lib/vagrant/command/resume.rb +17 -0
  58. data/lib/vagrant/command/ssh.rb +41 -0
  59. data/lib/vagrant/command/ssh_config.rb +21 -0
  60. data/lib/vagrant/command/status.rb +23 -0
  61. data/lib/vagrant/command/suspend.rb +17 -0
  62. data/lib/vagrant/command/up.rb +20 -0
  63. data/lib/vagrant/command/upgrade_to_060.rb +45 -0
  64. data/lib/vagrant/command/version.rb +13 -0
  65. data/lib/vagrant/config.rb +107 -189
  66. data/lib/vagrant/config/base.rb +67 -0
  67. data/lib/vagrant/config/error_recorder.rb +19 -0
  68. data/lib/vagrant/config/nfs.rb +10 -0
  69. data/lib/vagrant/config/package.rb +9 -0
  70. data/lib/vagrant/config/ssh.rb +28 -0
  71. data/lib/vagrant/config/vagrant.rb +21 -0
  72. data/lib/vagrant/config/vm.rb +111 -0
  73. data/lib/vagrant/data_store.rb +68 -0
  74. data/lib/vagrant/downloaders/file.rb +3 -3
  75. data/lib/vagrant/downloaders/http.rb +5 -5
  76. data/lib/vagrant/environment.rb +246 -243
  77. data/lib/vagrant/errors.rb +306 -0
  78. data/lib/vagrant/hosts/base.rb +1 -1
  79. data/lib/vagrant/hosts/bsd.rb +3 -9
  80. data/lib/vagrant/hosts/linux.rb +3 -9
  81. data/lib/vagrant/plugin.rb +50 -0
  82. data/lib/vagrant/provisioners/base.rb +0 -6
  83. data/lib/vagrant/provisioners/chef.rb +63 -58
  84. data/lib/vagrant/provisioners/chef_server.rb +9 -11
  85. data/lib/vagrant/provisioners/chef_solo.rb +2 -2
  86. data/lib/vagrant/ssh.rb +34 -37
  87. data/lib/vagrant/systems/base.rb +0 -13
  88. data/lib/vagrant/systems/linux.rb +10 -33
  89. data/lib/vagrant/systems/solaris.rb +59 -0
  90. data/lib/vagrant/test_helpers.rb +109 -0
  91. data/lib/vagrant/ui.rb +65 -0
  92. data/lib/vagrant/util.rb +9 -19
  93. data/lib/vagrant/util/glob_loader.rb +19 -17
  94. data/lib/vagrant/util/hash_with_indifferent_access.rb +63 -0
  95. data/lib/vagrant/util/plain_logger.rb +2 -0
  96. data/lib/vagrant/util/platform.rb +2 -0
  97. data/lib/vagrant/util/resource_logger.rb +5 -70
  98. data/lib/vagrant/util/retryable.rb +25 -0
  99. data/lib/vagrant/util/template_renderer.rb +1 -1
  100. data/lib/vagrant/version.rb +1 -1
  101. data/lib/vagrant/vm.rb +27 -13
  102. data/templates/commands/init/Vagrantfile.erb +13 -0
  103. data/templates/config/validation_failed.erb +7 -0
  104. data/templates/locales/en.yml +402 -0
  105. data/templates/package_Vagrantfile.erb +1 -1
  106. data/test/locales/en.yml +8 -0
  107. data/test/test_helper.rb +19 -103
  108. data/test/vagrant/action/box/destroy_test.rb +7 -19
  109. data/test/vagrant/action/box/download_test.rb +9 -25
  110. data/test/vagrant/action/box/package_test.rb +2 -2
  111. data/test/vagrant/action/box/unpackage_test.rb +8 -34
  112. data/test/vagrant/action/box/verify_test.rb +10 -19
  113. data/test/vagrant/action/builder_test.rb +0 -15
  114. data/test/vagrant/action/env/set_test.rb +1 -1
  115. data/test/vagrant/action/environment_test.rb +8 -26
  116. data/test/vagrant/action/general/package_test.rb +53 -53
  117. data/test/vagrant/action/vm/boot_test.rb +5 -22
  118. data/test/vagrant/action/vm/check_box_test.rb +35 -25
  119. data/test/vagrant/action/vm/clean_machine_folder_test.rb +1 -1
  120. data/test/vagrant/action/vm/clear_forwarded_ports_test.rb +1 -1
  121. data/test/vagrant/action/vm/clear_nfs_exports_test.rb +1 -1
  122. data/test/vagrant/action/vm/clear_shared_folders_test.rb +1 -1
  123. data/test/vagrant/action/vm/customize_test.rb +2 -1
  124. data/test/vagrant/action/vm/destroy_test.rb +1 -2
  125. data/test/vagrant/action/vm/destroy_unused_network_interfaces_test.rb +1 -1
  126. data/test/vagrant/action/vm/disable_networks_test.rb +10 -1
  127. data/test/vagrant/action/vm/discard_state_test.rb +10 -1
  128. data/test/vagrant/action/vm/export_test.rb +9 -37
  129. data/test/vagrant/action/vm/forward_ports_helpers_test.rb +2 -2
  130. data/test/vagrant/action/vm/forward_ports_test.rb +19 -16
  131. data/test/vagrant/action/vm/halt_test.rb +11 -1
  132. data/test/vagrant/action/vm/import_test.rb +37 -21
  133. data/test/vagrant/action/vm/match_mac_address_test.rb +1 -1
  134. data/test/vagrant/action/vm/network_test.rb +8 -7
  135. data/test/vagrant/action/vm/nfs_helpers_test.rb +6 -3
  136. data/test/vagrant/action/vm/nfs_test.rb +20 -45
  137. data/test/vagrant/action/vm/package_test.rb +1 -1
  138. data/test/vagrant/action/vm/package_vagrantfile_test.rb +1 -1
  139. data/test/vagrant/action/vm/provision_test.rb +10 -17
  140. data/test/vagrant/action/vm/resume_test.rb +1 -1
  141. data/test/vagrant/action/vm/share_folders_test.rb +25 -106
  142. data/test/vagrant/action/vm/suspend_test.rb +1 -1
  143. data/test/vagrant/action/warden_test.rb +105 -0
  144. data/test/vagrant/action_test.rb +5 -27
  145. data/test/vagrant/box_collection_test.rb +44 -0
  146. data/test/vagrant/box_test.rb +5 -105
  147. data/test/vagrant/cli_test.rb +35 -0
  148. data/test/vagrant/command/base_test.rb +23 -0
  149. data/test/vagrant/command/group_base_test.rb +15 -0
  150. data/test/vagrant/command/helpers_test.rb +88 -0
  151. data/test/vagrant/config/base_test.rb +52 -0
  152. data/test/vagrant/config/error_recorder_test.rb +18 -0
  153. data/test/vagrant/config/ssh_test.rb +12 -0
  154. data/test/vagrant/config/vagrant_test.rb +11 -0
  155. data/test/vagrant/config/vm_test.rb +70 -0
  156. data/test/vagrant/config_test.rb +113 -206
  157. data/test/vagrant/data_store_test.rb +68 -0
  158. data/test/vagrant/downloaders/base_test.rb +1 -1
  159. data/test/vagrant/downloaders/file_test.rb +4 -3
  160. data/test/vagrant/downloaders/http_test.rb +14 -4
  161. data/test/vagrant/environment_test.rb +290 -590
  162. data/test/vagrant/errors_test.rb +42 -0
  163. data/test/vagrant/hosts/base_test.rb +1 -1
  164. data/test/vagrant/hosts/bsd_test.rb +3 -6
  165. data/test/vagrant/hosts/linux_test.rb +3 -5
  166. data/test/vagrant/plugin_test.rb +9 -0
  167. data/test/vagrant/provisioners/base_test.rb +1 -1
  168. data/test/vagrant/provisioners/chef_server_test.rb +31 -35
  169. data/test/vagrant/provisioners/chef_solo_test.rb +1 -1
  170. data/test/vagrant/provisioners/chef_test.rb +7 -7
  171. data/test/vagrant/ssh_session_test.rb +3 -10
  172. data/test/vagrant/ssh_test.rb +25 -33
  173. data/test/vagrant/systems/linux_test.rb +6 -71
  174. data/test/vagrant/ui_test.rb +29 -0
  175. data/test/vagrant/util/hash_with_indifferent_access_test.rb +39 -0
  176. data/test/vagrant/util/resource_logger_test.rb +14 -81
  177. data/test/vagrant/util/retryable_test.rb +38 -0
  178. data/test/vagrant/util/template_renderer_test.rb +4 -4
  179. data/test/vagrant/vm_test.rb +47 -26
  180. data/vagrant.gemspec +14 -12
  181. metadata +121 -89
  182. data/bin/.gitignore +0 -0
  183. data/lib/vagrant/action/action_exception.rb +0 -16
  184. data/lib/vagrant/action/env/error_halt.rb +0 -16
  185. data/lib/vagrant/action/exception_catcher.rb +0 -14
  186. data/lib/vagrant/action/vm/persist.rb +0 -22
  187. data/lib/vagrant/active_list.rb +0 -83
  188. data/lib/vagrant/command.rb +0 -27
  189. data/lib/vagrant/commands/base.rb +0 -181
  190. data/lib/vagrant/commands/box.rb +0 -16
  191. data/lib/vagrant/commands/box/add.rb +0 -30
  192. data/lib/vagrant/commands/box/list.rb +0 -30
  193. data/lib/vagrant/commands/box/remove.rb +0 -30
  194. data/lib/vagrant/commands/box/repackage.rb +0 -35
  195. data/lib/vagrant/commands/destroy.rb +0 -37
  196. data/lib/vagrant/commands/halt.rb +0 -43
  197. data/lib/vagrant/commands/init.rb +0 -36
  198. data/lib/vagrant/commands/package.rb +0 -81
  199. data/lib/vagrant/commands/provision.rb +0 -31
  200. data/lib/vagrant/commands/reload.rb +0 -36
  201. data/lib/vagrant/commands/resume.rb +0 -35
  202. data/lib/vagrant/commands/ssh.rb +0 -78
  203. data/lib/vagrant/commands/ssh_config.rb +0 -45
  204. data/lib/vagrant/commands/status.rb +0 -125
  205. data/lib/vagrant/commands/suspend.rb +0 -36
  206. data/lib/vagrant/commands/up.rb +0 -44
  207. data/lib/vagrant/exceptions/uncallable_action.rb +0 -17
  208. data/lib/vagrant/util/translator.rb +0 -35
  209. data/templates/strings.yml +0 -341
  210. data/templates/unison/crontab_entry.erb +0 -1
  211. data/templates/unison/script.erb +0 -71
  212. data/test/vagrant/action/env/error_halt_test.rb +0 -21
  213. data/test/vagrant/action/exception_catcher_test.rb +0 -30
  214. data/test/vagrant/action/vm/persist_test.rb +0 -50
  215. data/test/vagrant/active_list_test.rb +0 -173
  216. data/test/vagrant/command_test.rb +0 -53
  217. data/test/vagrant/commands/base_test.rb +0 -139
  218. data/test/vagrant/commands/box/add_test.rb +0 -34
  219. data/test/vagrant/commands/box/list_test.rb +0 -32
  220. data/test/vagrant/commands/box/remove_test.rb +0 -41
  221. data/test/vagrant/commands/box/repackage_test.rb +0 -52
  222. data/test/vagrant/commands/destroy_test.rb +0 -44
  223. data/test/vagrant/commands/halt_test.rb +0 -50
  224. data/test/vagrant/commands/init_test.rb +0 -71
  225. data/test/vagrant/commands/package_test.rb +0 -97
  226. data/test/vagrant/commands/provision_test.rb +0 -60
  227. data/test/vagrant/commands/reload_test.rb +0 -47
  228. data/test/vagrant/commands/resume_test.rb +0 -44
  229. data/test/vagrant/commands/ssh_config_test.rb +0 -77
  230. data/test/vagrant/commands/ssh_test.rb +0 -129
  231. data/test/vagrant/commands/status_test.rb +0 -40
  232. data/test/vagrant/commands/suspend_test.rb +0 -44
  233. data/test/vagrant/commands/up_test.rb +0 -49
  234. data/test/vagrant/util/translator_test.rb +0 -61
  235. data/test/vagrant/util_test.rb +0 -27
@@ -3,7 +3,7 @@ require "test_helper"
3
3
  class HaltVMActionTest < Test::Unit::TestCase
4
4
  setup do
5
5
  @klass = Vagrant::Action::VM::Halt
6
- @app, @env = mock_action_data
6
+ @app, @env = action_env
7
7
 
8
8
  @vm = mock("vm")
9
9
  @vm.stubs(:name).returns("foo")
@@ -26,6 +26,7 @@ class HaltVMActionTest < Test::Unit::TestCase
26
26
 
27
27
  context "calling" do
28
28
  setup do
29
+ @vm.stubs(:created?).returns(true)
29
30
  @internal_vm.stubs(:running?).returns(true)
30
31
 
31
32
  @vm.system.stubs(:halt)
@@ -33,6 +34,15 @@ class HaltVMActionTest < Test::Unit::TestCase
33
34
  @internal_vm.stubs(:state).returns(:powered_off)
34
35
  end
35
36
 
37
+ should "do nothing if VM is not created" do
38
+ @internal_vm.stubs(:created?).returns(false)
39
+ @vm.system.expects(:halt).never
40
+ @internal_vm.expects(:stop).never
41
+ @app.expects(:call).once
42
+
43
+ @instance.call(@env)
44
+ end
45
+
36
46
  should "do nothing if VM not running" do
37
47
  @internal_vm.stubs(:running?).returns(false)
38
48
  @vm.system.expects(:halt).never
@@ -2,49 +2,65 @@ require "test_helper"
2
2
 
3
3
  class ImportVMActionTest < Test::Unit::TestCase
4
4
  setup do
5
+ clean_paths
6
+ vagrant_box("foo")
7
+
5
8
  @klass = Vagrant::Action::VM::Import
6
- @app, @env = mock_action_data
7
- @instance = @klass.new(@app, @env)
9
+ @app, @env = action_env(vagrant_env(vagrantfile(<<-vf)))
10
+ config.vm.box = "foo"
11
+ vf
8
12
 
9
- ovf_file = "foo"
10
- @box = mock("box")
11
- @box.stubs(:ovf_file).returns(ovf_file)
12
- @env.env.stubs(:box).returns(@box)
13
+ @instance = @klass.new(@app, @env)
13
14
 
14
- @env.env.vm = Vagrant::VM.new
15
+ @env.env.vm = Vagrant::VM.new(:env => @env.env, :name => "foobar")
15
16
 
16
17
  VirtualBox::VM.stubs(:import)
18
+
19
+ @vm = mock("vm")
20
+ @vm.stubs(:uuid).returns("foobar")
17
21
  end
18
22
 
19
23
  should "call import on VirtualBox with proper base" do
20
- VirtualBox::VM.expects(:import).once.with(@env.env.box.ovf_file).returns("foo")
24
+ VirtualBox::VM.expects(:import).once.with(@env.env.box.ovf_file.to_s).returns(@vm)
21
25
  @instance.call(@env)
22
26
  end
23
27
 
24
28
  should "call next in chain on success and set VM" do
25
- vm = mock("vm")
26
- VirtualBox::VM.stubs(:import).returns(vm)
29
+ VirtualBox::VM.stubs(:import).returns(@vm)
27
30
  @app.expects(:call).with(@env).once
28
31
  @instance.call(@env)
29
32
 
30
- assert_equal vm, @env["vm"].vm
33
+ assert_equal @vm, @env["vm"].vm
31
34
  end
32
35
 
33
36
  should "mark environment erroneous and not continue chain on failure" do
34
37
  @app.expects(:call).never
35
- @instance.call(@env)
36
-
37
- assert @env.error?
38
+ assert_raises(Vagrant::Errors::VMImportFailure) {
39
+ @instance.call(@env)
40
+ }
38
41
  end
39
42
 
40
- should "run the destroy action if interrupted" do
41
- VirtualBox::VM.stubs(:import).returns(mock("vm"))
42
- @app.expects(:call).once.with() do |env|
43
- assert_equal @env, env
44
- @env.error!(:interrupt)
43
+ context "recovery" do
44
+ setup do
45
+ @env.env.vm.stubs(:created?).returns(true)
45
46
  end
46
- @env.env.actions.expects(:run).with(:destroy).once
47
47
 
48
- @instance.call(@env)
48
+ should "not run the destroy action on recover if error is a VagrantError" do
49
+ @env["vagrant.error"] = Vagrant::Errors::VMImportFailure.new
50
+ @env.env.actions.expects(:run).never
51
+ @instance.recover(@env)
52
+ end
53
+
54
+ should "not run the destroy action on recover if VM is not created" do
55
+ @env.env.vm.stubs(:created?).returns(false)
56
+ @env.env.actions.expects(:run).never
57
+ @instance.recover(@env)
58
+ end
59
+
60
+ should "run the destroy action on recover" do
61
+ @env.env.vm.stubs(:created?).returns(true)
62
+ @env.env.actions.expects(:run).with(:destroy).once
63
+ @instance.recover(@env)
64
+ end
49
65
  end
50
66
  end
@@ -3,7 +3,7 @@ require "test_helper"
3
3
  class MatchMACAddressVMActionTest < Test::Unit::TestCase
4
4
  setup do
5
5
  @klass = Vagrant::Action::VM::MatchMACAddress
6
- @app, @env = mock_action_data
6
+ @app, @env = action_env
7
7
 
8
8
  @vm = mock("vm")
9
9
  @env["vm"] = @vm
@@ -3,7 +3,7 @@ require "test_helper"
3
3
  class NetworkVMActionTest < Test::Unit::TestCase
4
4
  setup do
5
5
  @klass = Vagrant::Action::VM::Network
6
- @app, @env = mock_action_data
6
+ @app, @env = action_env
7
7
 
8
8
  @vm = mock("vm")
9
9
  @vm.stubs(:name).returns("foo")
@@ -18,7 +18,7 @@ class NetworkVMActionTest < Test::Unit::TestCase
18
18
  context "initializing" do
19
19
  should "verify no bridge collisions for each network enabled" do
20
20
  @env.env.config.vm.network("foo")
21
- @klass.any_instance.expects(:verify_no_bridge_collision).once.with() do |options|
21
+ @klass.any_instance.expects(:verify_no_bridge_collision).returns(true).once.with() do |options|
22
22
  assert_equal "foo", options[:ip]
23
23
  true
24
24
  end
@@ -139,8 +139,9 @@ class NetworkVMActionTest < Test::Unit::TestCase
139
139
  mock_interface(:name => @options[:name],
140
140
  :interface_type => :bridged)
141
141
 
142
- @instance.network_name(@options)
143
- assert @env.error?
142
+ assert_raises(Vagrant::Errors::NetworkNotFound) {
143
+ @instance.network_name(@options)
144
+ }
144
145
  end
145
146
 
146
147
  should "return the network which matches the name if given" do
@@ -154,9 +155,9 @@ class NetworkVMActionTest < Test::Unit::TestCase
154
155
  @options[:name] = "foo"
155
156
 
156
157
  @interfaces.expects(:create).never
157
- @instance.network_name(@options)
158
- assert @env.error?
159
- assert_equal :network_not_found, @env.error.first
158
+ assert_raises(Vagrant::Errors::NetworkNotFound) {
159
+ @instance.network_name(@options)
160
+ }
160
161
  end
161
162
 
162
163
  should "create a network for the IP and netmask" do
@@ -2,9 +2,11 @@ require "test_helper"
2
2
 
3
3
  class NFSHelpersVMActionTest < Test::Unit::TestCase
4
4
  setup do
5
- @klass = Class.new
6
- @klass.send(:include, Vagrant::Action::VM::NFSHelpers)
7
- @app, @env = mock_action_data
5
+ @klass = Class.new do
6
+ include Vagrant::Action::VM::NFSHelpers
7
+ end
8
+
9
+ @app, @env = action_env
8
10
 
9
11
  @instance = @klass.new
10
12
  end
@@ -18,6 +20,7 @@ class NFSHelpersVMActionTest < Test::Unit::TestCase
18
20
  end
19
21
 
20
22
  should "not do anything if host is nil" do
23
+ @env.env.stubs(:host).returns(nil)
21
24
  assert_nothing_raised { @instance.clear_nfs_exports(@env) }
22
25
  end
23
26
  end
@@ -3,7 +3,7 @@ require "test_helper"
3
3
  class NFSVMActionTest < Test::Unit::TestCase
4
4
  setup do
5
5
  @klass = Vagrant::Action::VM::NFS
6
- @app, @env = mock_action_data
6
+ @app, @env = action_env
7
7
 
8
8
  @vm = mock("vm")
9
9
  @vm.stubs(:system).returns(mock("system"))
@@ -65,32 +65,12 @@ class NFSVMActionTest < Test::Unit::TestCase
65
65
  @instance.expects(:mount_folders).never
66
66
  @instance.call(@env)
67
67
  end
68
+ end
68
69
 
69
- should "halt chain if environment error occured" do
70
- @env.error!(:foo)
71
-
72
- seq = sequence('seq')
73
- @instance.expects(:extract_folders).in_sequence(seq)
74
- @instance.expects(:prepare_folders).in_sequence(seq)
75
- @instance.expects(:clear_nfs_exports).in_sequence(seq)
76
- @instance.expects(:export_folders).in_sequence(seq)
77
- @app.expects(:call).never
78
- @instance.call(@env)
79
- end
80
-
81
- should "not mount folders if an error occured" do
82
- seq = sequence("seq")
83
- @app.expects(:call).in_sequence(seq).with() do
84
- # Use this mark the env as error
85
- @env.error!(:foo)
86
-
87
- true
88
- end
89
-
90
- @instance.expects(:clear_nfs_exports).with(@env).in_sequence(seq)
91
-
92
- @instance.expects(:mount_folders).never
93
- @instance.call(@env)
70
+ context "recovery" do
71
+ should "clear NFS exports" do
72
+ @instance.expects(:clear_nfs_exports).with(@env).once
73
+ @instance.recover(@env)
94
74
  end
95
75
  end
96
76
 
@@ -129,11 +109,12 @@ class NFSVMActionTest < Test::Unit::TestCase
129
109
  end
130
110
 
131
111
  should "return nil if the perm is not set" do
112
+ @env.env.config.nfs.map_uid = nil
132
113
  assert_nil @instance.prepare_permission(:uid, {:gid => 7})
133
114
  end
134
115
 
135
116
  should "return nil if the perm explicitly says nil" do
136
- assert_nil @instance.prepare_permission(:uid, {:uid => nil})
117
+ assert_nil @instance.prepare_permission(:uid, {:map_uid => nil})
137
118
  end
138
119
 
139
120
  should "return the set value if it is set" do
@@ -164,13 +145,6 @@ class NFSVMActionTest < Test::Unit::TestCase
164
145
  @env["host"].expects(:nfs_export).with(@instance.guest_ip, @instance.folders)
165
146
  @instance.export_folders
166
147
  end
167
-
168
- should "error the environment if exception is raised" do
169
- @env["host"].expects(:nfs_export).raises(Vagrant::Action::ActionException.new(:foo))
170
- @instance.export_folders
171
- assert @env.error?
172
- assert_equal :foo, @env.error.first
173
- end
174
148
  end
175
149
 
176
150
  context "mounting folders" do
@@ -240,29 +214,30 @@ class NFSVMActionTest < Test::Unit::TestCase
240
214
 
241
215
  should "error environment if host is nil" do
242
216
  @env.env.stubs(:host).returns(nil)
243
- @instance.verify_settings
244
- assert @env.error?
245
- assert_equal :nfs_host_required, @env.error.first
217
+ assert_raises(Vagrant::Errors::NFSHostRequired) {
218
+ @instance.verify_settings
219
+ }
246
220
  end
247
221
 
248
222
  should "error environment if host does not support NFS" do
249
223
  @env.env.host.stubs(:nfs?).returns(false)
250
- @instance.verify_settings
251
- assert @env.error?
252
- assert_equal :nfs_not_supported, @env.error.first
224
+ assert_raises(Vagrant::Errors::NFSNotSupported) {
225
+ @instance.verify_settings
226
+ }
253
227
  end
254
228
 
255
229
  should "error environment if host only networking is not enabled" do
256
230
  @env.env.config.vm.network_options.clear
257
- @instance.verify_settings
258
- assert @env.error?
259
- assert_equal :nfs_no_host_network, @env.error.first
231
+ assert_raises(Vagrant::Errors::NFSNoHostNetwork) {
232
+ @instance.verify_settings
233
+ }
260
234
  end
261
235
 
262
236
  should "be fine if everything passes" do
263
237
  @env.env.host.stubs(:nfs?).returns(true)
264
- @instance.verify_settings
265
- assert !@env.error?
238
+ assert_nothing_raised {
239
+ @instance.verify_settings
240
+ }
266
241
  end
267
242
  end
268
243
  end
@@ -3,7 +3,7 @@ require "test_helper"
3
3
  class PackageVMActionTest < Test::Unit::TestCase
4
4
  setup do
5
5
  @klass = Vagrant::Action::VM::Package
6
- @app, @env = mock_action_data
6
+ @app, @env = action_env
7
7
  @env["export.temp_dir"] = "foo"
8
8
 
9
9
  @instance = @klass.new(@app, @env)
@@ -3,7 +3,7 @@ require "test_helper"
3
3
  class PackageVagrantfileVMActionTest < Test::Unit::TestCase
4
4
  setup do
5
5
  @klass = Vagrant::Action::VM::PackageVagrantfile
6
- @app, @env = mock_action_data
6
+ @app, @env = action_env
7
7
 
8
8
  @vm = mock("vm")
9
9
  @env["vm"] = @vm
@@ -3,7 +3,7 @@ require "test_helper"
3
3
  class ProvisionVMActionTest < Test::Unit::TestCase
4
4
  setup do
5
5
  @klass = Vagrant::Action::VM::Provision
6
- @app, @env = mock_action_data
6
+ @app, @env = action_env
7
7
 
8
8
  @vm = mock("vm")
9
9
  @vm.stubs(:name).returns("foo")
@@ -65,9 +65,10 @@ class ProvisionVMActionTest < Test::Unit::TestCase
65
65
 
66
66
  should "error environment if the class is not a subclass of the provisioner base" do
67
67
  @prov.expects(:is_a?).with(Vagrant::Provisioners::Base).returns(false)
68
- @instance.load_provisioner
69
- assert @env.error?
70
- assert_equal :provisioner_invalid_class, @env.error.first
68
+
69
+ assert_raises(Vagrant::Errors::ProvisionInvalidClass) {
70
+ @instance.load_provisioner
71
+ }
71
72
  end
72
73
  end
73
74
 
@@ -81,11 +82,12 @@ class ProvisionVMActionTest < Test::Unit::TestCase
81
82
  assert_equal instance, @instance.load_provisioner
82
83
  end
83
84
 
84
- should "raise an ActionException if its an unknown symbol" do
85
+ should "raise an error if its an unknown symbol" do
85
86
  @env["config"].vm.provisioner = :this_will_never_exist
86
- @instance.load_provisioner
87
- assert @env.error?
88
- assert_equal :provisioner_unknown_type, @env.error.first
87
+
88
+ assert_raises(Vagrant::Errors::ProvisionUnknownType) {
89
+ @instance.load_provisioner
90
+ }
89
91
  end
90
92
 
91
93
  should "set :chef_solo to the ChefSolo provisioner" do
@@ -120,15 +122,6 @@ class ProvisionVMActionTest < Test::Unit::TestCase
120
122
 
121
123
  @instance.call(@env)
122
124
  end
123
-
124
- should "not provision if erroneous environment" do
125
- @env.error!(:foo)
126
-
127
- @prov.expects(:provision!).never
128
- @app.expects(:call).with(@env).once
129
-
130
- @instance.call(@env)
131
- end
132
125
  end
133
126
  end
134
127
  end
@@ -3,7 +3,7 @@ require "test_helper"
3
3
  class ResumeVMActionTest < Test::Unit::TestCase
4
4
  setup do
5
5
  @klass = Vagrant::Action::VM::Resume
6
- @app, @env = mock_action_data
6
+ @app, @env = action_env
7
7
 
8
8
  @vm = mock("vm")
9
9
  @env["vm"] = @vm
@@ -3,7 +3,7 @@ require "test_helper"
3
3
  class ShareFoldersVMActionTest < Test::Unit::TestCase
4
4
  setup do
5
5
  @klass = Vagrant::Action::VM::ShareFolders
6
- @app, @env = mock_action_data
6
+ @app, @env = action_env
7
7
 
8
8
  @vm = mock("vm")
9
9
  @vm.stubs(:name).returns("foo")
@@ -14,22 +14,18 @@ class ShareFoldersVMActionTest < Test::Unit::TestCase
14
14
  @internal_vm = mock("internal")
15
15
  @vm.stubs(:vm).returns(@internal_vm)
16
16
 
17
+ # No validation for this test since its a nightmare due to all the
18
+ # nonexistent shared folders.
19
+ Vagrant::Config::Top.any_instance.stubs(:validate!)
20
+
17
21
  @instance = @klass.new(@app, @env)
18
22
  end
19
23
 
20
- def stub_shared_folders
21
- env = mock_environment do |config|
24
+ def stub_shared_folders(contents)
25
+ env = vagrant_env(vagrantfile(<<-vf))
22
26
  config.vm.shared_folders.clear
23
-
24
- if block_given?
25
- yield config
26
- else
27
- folders = [%w{foo fooguest foohost}, %w{bar barguest barhost}]
28
- folders.each do |data|
29
- config.vm.share_folder(*data)
30
- end
31
- end
32
- end
27
+ #{contents}
28
+ vf
33
29
 
34
30
  @env.stubs(:env).returns(env)
35
31
  env.config.vm.shared_folders
@@ -41,40 +37,22 @@ class ShareFoldersVMActionTest < Test::Unit::TestCase
41
37
  @instance.expects(:create_metadata).once.in_sequence(before_seq)
42
38
  @app.expects(:call).with(@env).in_sequence(before_seq)
43
39
  @instance.expects(:mount_shared_folders).once.in_sequence(before_seq)
44
- @instance.expects(:setup_unison).once.in_sequence(before_seq)
45
-
46
- @instance.call(@env)
47
- end
48
-
49
- should "run only the metadata actions if erroneous environment" do
50
- @env.error!(:foo)
51
-
52
- before_seq = sequence("before")
53
- @instance.expects(:create_metadata).once.in_sequence(before_seq)
54
- @app.expects(:call).with(@env).in_sequence(before_seq)
55
- @instance.expects(:mount_shared_folders).never
56
- @instance.expects(:setup_unison).never
57
40
 
58
41
  @instance.call(@env)
59
42
  end
60
43
  end
61
44
 
62
45
  context "collecting shared folders" do
63
- setup do
64
- File.stubs(:expand_path).returns("baz")
65
- end
66
-
67
46
  should "return a hash of the shared folders" do
68
47
  data = {
69
48
  "foo" => %W[bar baz],
70
49
  "bar" => %W[foo baz]
71
50
  }
72
51
 
73
- stub_shared_folders do |config|
74
- data.each do |name, value|
75
- config.vm.share_folder(name, *value)
76
- end
77
- end
52
+ stub_shared_folders(<<-sf)
53
+ config.vm.share_folder("foo", "bar", "baz")
54
+ config.vm.share_folder("bar", "foo", "baz")
55
+ sf
78
56
 
79
57
  result = @instance.shared_folders
80
58
  assert_equal data.length, result.length
@@ -86,34 +64,20 @@ class ShareFoldersVMActionTest < Test::Unit::TestCase
86
64
  end
87
65
 
88
66
  should "ignore disabled shared folders" do
89
- stub_shared_folders do |config|
67
+ stub_shared_folders(<<-sf)
90
68
  config.vm.share_folder("v-foo", "/foo", "/foo")
91
69
  config.vm.share_folder("v-root", "/vagrant", ".", :disabled => true)
92
70
  config.vm.share_folder("v-bar", "/bar", "/bar")
93
- end
71
+ sf
94
72
 
95
73
  assert_equal 2, @instance.shared_folders.length
96
74
  assert_equal %W[v-bar v-foo], @instance.shared_folders.keys.sort
97
75
  end
98
76
 
99
- should "append sync suffix if sync enabled to a folder" do
100
- name = "foo"
101
- guest = "bar"
102
- host = "baz"
103
-
104
- stub_shared_folders do |config|
105
- config.vm.share_folder(name, guest, host, :sync => true)
106
- end
107
-
108
- result = @instance.shared_folders
109
- assert_equal "#{guest}#{@env.env.config.unison.folder_suffix}", result[name][:guestpath]
110
- assert_equal guest, result[name][:original][:guestpath]
111
- end
112
-
113
77
  should "not destroy original hash" do
114
- @folders = stub_shared_folders do |config|
78
+ @folders = stub_shared_folders(<<-sf)
115
79
  config.vm.share_folder("foo", "bar", "baz", :sync => true)
116
- end
80
+ sf
117
81
 
118
82
  folder = @folders["foo"].dup
119
83
 
@@ -122,25 +86,12 @@ class ShareFoldersVMActionTest < Test::Unit::TestCase
122
86
  end
123
87
  end
124
88
 
125
- context "unison shared folders" do
126
- setup do
127
- @folders = stub_shared_folders do |config|
128
- config.vm.share_folder("foo", "bar", "baz", :sync => true)
129
- config.vm.share_folder("bar", "foo", "baz")
130
- end
131
- end
132
-
133
- should "only return the folders marked for syncing" do
134
- result = @instance.unison_folders
135
- assert_equal 1, result.length
136
- assert result.has_key?("foo")
137
- assert !result.has_key?("bar")
138
- end
139
- end
140
-
141
89
  context "setting up shared folder metadata" do
142
90
  setup do
143
- stub_shared_folders
91
+ stub_shared_folders(<<-sf)
92
+ config.vm.share_folder("foo", "fooguest", "foohost")
93
+ config.vm.share_folder("bar", "barguest", "barhost")
94
+ sf
144
95
  end
145
96
 
146
97
  should "add all shared folders to the VM" do
@@ -162,7 +113,10 @@ class ShareFoldersVMActionTest < Test::Unit::TestCase
162
113
 
163
114
  context "mounting the shared folders" do
164
115
  setup do
165
- @folders = stub_shared_folders
116
+ @folders = stub_shared_folders(<<-sf)
117
+ config.vm.share_folder("foo", "fooguest", "foohost")
118
+ config.vm.share_folder("bar", "barguest", "barhost")
119
+ sf
166
120
  @ssh = mock("ssh")
167
121
  @vm.ssh.stubs(:execute).yields(@ssh)
168
122
  @vm.system.stubs(:mount_shared_folder)
@@ -177,39 +131,4 @@ class ShareFoldersVMActionTest < Test::Unit::TestCase
177
131
  @instance.mount_shared_folders
178
132
  end
179
133
  end
180
-
181
- context "setting up unison" do
182
- setup do
183
- @ssh = mock("ssh")
184
- @vm.ssh.stubs(:execute).yields(@ssh)
185
-
186
- @folders = stub_shared_folders do |config|
187
- config.vm.share_folder("foo", "bar", "baz", :sync => true)
188
- config.vm.share_folder("bar", "foo", "baz")
189
- end
190
- end
191
-
192
- should "do nothing if unison folders is empty" do
193
- @instance.stubs(:unison_folders).returns({})
194
- @vm.ssh.expects(:execute).never
195
- @instance.setup_unison
196
- end
197
-
198
- should "prepare unison then create for each folder" do
199
- seq = sequence("unison seq")
200
- @vm.system.expects(:prepare_unison).with(@ssh).once.in_sequence(seq)
201
- @instance.unison_folders.each do |name, data|
202
- if data[:sync]
203
- @vm.system.expects(:create_unison).with do |ssh, opts|
204
- assert_equal @ssh, ssh
205
- assert_equal data, opts
206
-
207
- true
208
- end
209
- end
210
- end
211
-
212
- @instance.setup_unison
213
- end
214
- end
215
134
  end