vagrantup 0.5.4 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -1,16 +1,14 @@
1
+ require 'pathname'
2
+
1
3
  module Vagrant
2
4
  module Provisioners
3
5
  # This class implements provisioning via chef-client, allowing provisioning
4
6
  # with a chef server.
5
7
  class ChefServer < Chef
6
8
  def prepare
7
- if env.config.chef.validation_key_path.nil?
8
- action_env.error!(:chef_server_validation_key_required)
9
- elsif !File.file?(validation_key_path)
10
- action_env.error!(:chef_server_validation_key_doesnt_exist)
11
- elsif env.config.chef.chef_server_url.nil?
12
- action_env.error!(:chef_server_url_required)
13
- end
9
+ raise ChefError.new(:server_validation_key_required) if env.config.chef.validation_key_path.nil?
10
+ raise ChefError.new(:server_validation_key_doesnt_exist) if !File.file?(validation_key_path)
11
+ raise ChefError.new(:server_url_required) if env.config.chef.chef_server_url.nil?
14
12
  end
15
13
 
16
14
  def provision!
@@ -24,7 +22,7 @@ module Vagrant
24
22
  end
25
23
 
26
24
  def create_client_key_folder
27
- logger.info "Creating folder to hold client key..."
25
+ env.ui.info I18n.t("vagrant.provisioners.chef.client_key_folder")
28
26
  path = Pathname.new(env.config.chef.client_key_path)
29
27
 
30
28
  vm.ssh.execute do |ssh|
@@ -33,7 +31,7 @@ module Vagrant
33
31
  end
34
32
 
35
33
  def upload_validation_key
36
- logger.info "Uploading chef client validation key..."
34
+ env.ui.info I18n.t("vagrant.provisioners.chef.upload_validation_key")
37
35
  vm.ssh.upload!(validation_key_path, guest_validation_key_path)
38
36
  end
39
37
 
@@ -50,13 +48,13 @@ module Vagrant
50
48
  def run_chef_client
51
49
  command = "cd #{env.config.chef.provisioning_path} && sudo -E chef-client -c client.rb -j dna.json"
52
50
 
53
- logger.info "Running chef-client..."
51
+ env.ui.info I18n.t("vagrant.provisioners.chef.running_client")
54
52
  vm.ssh.execute do |ssh|
55
53
  ssh.exec!(command) do |channel, type, data|
56
54
  if type == :exit_status
57
55
  ssh.check_exit_status(data, command)
58
56
  else
59
- logger.info("#{data}: #{type}")
57
+ env.ui.info("#{data}: #{type}")
60
58
  end
61
59
  end
62
60
  end
@@ -40,11 +40,11 @@ module Vagrant
40
40
  def run_chef_solo
41
41
  command = "cd #{env.config.chef.provisioning_path} && sudo -E chef-solo -c solo.rb -j dna.json"
42
42
 
43
- logger.info "Running chef-solo..."
43
+ env.ui.info I18n.t("vagrant.provisioners.chef.running_solo")
44
44
  vm.ssh.execute do |ssh|
45
45
  ssh.exec!(command) do |channel, type, data|
46
46
  ssh.check_exit_status(data, command) if type == :exit_status
47
- logger.info("#{data}: #{type}") if type != :exit_status
47
+ env.ui.info("#{data}: #{type}") if type != :exit_status
48
48
  end
49
49
  end
50
50
  end
data/lib/vagrant/ssh.rb CHANGED
@@ -1,9 +1,13 @@
1
+ require 'net/ssh'
2
+ require 'net/scp'
3
+ require 'mario'
4
+
1
5
  module Vagrant
2
6
  # Manages SSH access to a specific environment. Allows an environment to
3
7
  # replace the process with SSH itself, run a specific set of commands,
4
8
  # upload files, or even check if a host is up.
5
9
  class SSH
6
- include Vagrant::Util
10
+ include Util::Retryable
7
11
 
8
12
  # Reference back up to the environment which this SSH object belongs
9
13
  # to
@@ -18,9 +22,8 @@ module Vagrant
18
22
  # of options which override the configuration values.
19
23
  def connect(opts={})
20
24
  if Mario::Platform.windows?
21
- error_and_exit(:ssh_unavailable_windows,
22
- :key_path => env.config.ssh.private_key_path,
23
- :ssh_port => port(opts))
25
+ raise Errors::SSHUnavailableWindows.new(:key_path => env.config.ssh.private_key_path,
26
+ :ssh_port => port(opts))
24
27
  end
25
28
 
26
29
  options = {}
@@ -56,31 +59,30 @@ module Vagrant
56
59
  opts = opts.dup
57
60
  opts[:forward_agent] = true if env.config.ssh.forward_agent
58
61
 
59
- Net::SSH.start(env.config.ssh.host,
60
- env.config[:ssh][:username],
61
- opts.merge( :port => port,
62
- :keys => [env.config.ssh.private_key_path],
63
- :user_known_hosts_file => [],
64
- :paranoid => false,
65
- :config => false)) do |ssh|
66
- yield SSH::Session.new(ssh)
62
+ retryable(:tries => 5, :on => Errno::ECONNREFUSED) do
63
+ Net::SSH.start(env.config.ssh.host,
64
+ env.config.ssh.username,
65
+ opts.merge( :port => port,
66
+ :keys => [env.config.ssh.private_key_path],
67
+ :user_known_hosts_file => [],
68
+ :paranoid => false,
69
+ :config => false)) do |ssh|
70
+ yield SSH::Session.new(ssh)
71
+ end
67
72
  end
73
+ rescue Errno::ECONNREFUSED
74
+ raise Errors::SSHConnectionRefused.new
68
75
  end
69
76
 
70
77
  # Uploads a file from `from` to `to`. `from` is expected to be a filename
71
78
  # or StringIO, and `to` is expected to be a path. This method simply forwards
72
79
  # the arguments to `Net::SCP#upload!` so view that for more information.
73
80
  def upload!(from, to)
74
- tries = 5
75
-
76
- begin
81
+ retryable(:tries => 5, :on => IOError) do
77
82
  execute do |ssh|
78
83
  scp = Net::SCP.new(ssh.session)
79
84
  scp.upload!(from, to)
80
85
  end
81
- rescue IOError
82
- retry if (tries -= 1) > 0
83
- raise
84
86
  end
85
87
  end
86
88
 
@@ -94,7 +96,7 @@ module Vagrant
94
96
  execute(:timeout => env.config.ssh.timeout) do |ssh|
95
97
  Thread.current[:result] = true
96
98
  end
97
- rescue Errno::ECONNREFUSED, Net::SSH::Disconnect
99
+ rescue Errno::ECONNREFUSED, Net::SSH::Disconnect, Errors::SSHConnectionRefused
98
100
  # False, its defaulted above
99
101
  end
100
102
  end
@@ -102,7 +104,7 @@ module Vagrant
102
104
  check_thread.join(env.config.ssh.timeout)
103
105
  return check_thread[:result]
104
106
  rescue Net::SSH::AuthenticationFailed
105
- error_and_exit(:vm_ssh_auth_failed)
107
+ raise Errors::SSHAuthenticationFailed.new
106
108
  end
107
109
 
108
110
  # Checks the file permissions for the private key, resetting them
@@ -114,15 +116,14 @@ module Vagrant
114
116
  stat = File.stat(key_path)
115
117
 
116
118
  if stat.owned? && file_perms(key_path) != "600"
117
- env.logger.info "Permissions on private key incorrect, fixing..."
118
119
  File.chmod(0600, key_path)
119
120
 
120
- error_and_exit(:ssh_bad_permissions, :key_path => key_path) if file_perms(key_path) != "600"
121
+ raise Errors::SSHKeyBadPermissions.new(:key_path => key_path) if file_perms(key_path) != "600"
121
122
  end
122
123
  rescue Errno::EPERM
123
124
  # This shouldn't happen since we verify we own the file, but just
124
125
  # in case.
125
- error_and_exit(:ssh_bad_permissions, :key_path => key_path)
126
+ raise Errors::SSHKeyBadPermissions.new(:key_path => key_path)
126
127
  end
127
128
 
128
129
  # Returns the file permissions of a given file. This is fairly unix specific
@@ -163,6 +164,8 @@ module Vagrant
163
164
  # in order to provide basic command error checking while still
164
165
  # providing access to the actual session object.
165
166
  class Session
167
+ include Util::Retryable
168
+
166
169
  attr_reader :session
167
170
 
168
171
  def initialize(session)
@@ -185,9 +188,7 @@ module Vagrant
185
188
  ch[:result] << data if [:stdout, :stderr].include?(type)
186
189
  end
187
190
 
188
- tries = 5
189
-
190
- begin
191
+ retryable(:tries => 5, :on => IOError, :sleep => 0.5) do
191
192
  metach = session.open_channel do |channel|
192
193
  channel.exec(command) do |ch, success|
193
194
  raise "could not execute command: #{command.inspect}" unless success
@@ -208,13 +209,10 @@ module Vagrant
208
209
  end
209
210
  end
210
211
  end
211
- rescue IOError
212
- retry if (tries -= 1) > 0
213
- raise
214
- end
215
212
 
216
- metach.wait
217
- metach[:result]
213
+ metach.wait
214
+ metach[:result]
215
+ end
218
216
  end
219
217
 
220
218
  # Checks for an erroroneous exit status and raises an exception
@@ -222,13 +220,12 @@ module Vagrant
222
220
  def check_exit_status(exit_status, command, options=nil)
223
221
  if exit_status != 0
224
222
  options = {
225
- :error_key => :ssh_bad_exit_status,
226
- :error_data => {
227
- :command => command
228
- }
223
+ :_error_class => Errors::VagrantError,
224
+ :_key => :ssh_bad_exit_status,
225
+ :command => command
229
226
  }.merge(options || {})
230
227
 
231
- raise Action::ActionException.new(options[:error_key], options[:error_data])
228
+ raise options[:_error_class].new(options)
232
229
  end
233
230
  end
234
231
  end
@@ -27,12 +27,6 @@ module Vagrant
27
27
  @vm = vm
28
28
  end
29
29
 
30
- # A convenience method to access the logger on the VM
31
- # environment.
32
- def logger
33
- vm.env.logger
34
- end
35
-
36
30
  # Halt the machine. This method should gracefully shut down the
37
31
  # operating system. This method will cause `vagrant halt` and associated
38
32
  # commands to _block_, meaning that if the machine doesn't halt
@@ -59,13 +53,6 @@ module Vagrant
59
53
  # via the host are already done.
60
54
  def mount_nfs(ip, folders); end
61
55
 
62
- # Prepares the system for unison folder syncing. This is called
63
- # once once prior to any `create_unison` calls.
64
- def prepare_unison(ssh); end
65
-
66
- # Creates an entry for folder syncing via unison.
67
- def create_unison(ssh, options); end
68
-
69
56
  # Prepares the system for host only networks. This is called
70
57
  # once prior to any `enable_host_only_network` calls.
71
58
  def prepare_host_only_network; end
@@ -13,6 +13,8 @@ module Vagrant
13
13
  # generally, Vagrant tries to make almost every aspect of its execution
14
14
  # configurable, and this assists that goal.
15
15
  class LinuxConfig < Vagrant::Config::Base
16
+ configures :linux
17
+
16
18
  attr_accessor :halt_timeout
17
19
  attr_accessor :halt_check_interval
18
20
 
@@ -22,14 +24,11 @@ module Vagrant
22
24
  end
23
25
  end
24
26
 
25
- # Register config class
26
- Config.configures :linux, LinuxConfig
27
-
28
27
  #-------------------------------------------------------------------
29
28
  # Overridden methods
30
29
  #-------------------------------------------------------------------
31
30
  def halt
32
- logger.info "Attempting graceful shutdown of linux..."
31
+ vm.env.ui.info I18n.t("vagrant.systems.linux.attempting_halt")
33
32
  vm.ssh.execute do |ssh|
34
33
  ssh.exec!("sudo halt")
35
34
  end
@@ -49,7 +48,7 @@ module Vagrant
49
48
  def mount_shared_folder(ssh, name, guestpath)
50
49
  ssh.exec!("sudo mkdir -p #{guestpath}")
51
50
  mount_folder(ssh, name, guestpath)
52
- ssh.exec!("sudo chown #{config.ssh.username} #{guestpath}")
51
+ ssh.exec!("sudo chown #{vm.env.config.ssh.username} #{guestpath}")
53
52
  end
54
53
 
55
54
  def mount_nfs(ip, folders)
@@ -63,36 +62,12 @@ module Vagrant
63
62
  end
64
63
  end
65
64
 
66
- def prepare_unison(ssh)
67
- ssh.exec!("which unison", :error_key => :unison_not_found)
68
-
69
- logger.info "Preparing system for unison sync..."
70
- vm.ssh.upload!(StringIO.new(TemplateRenderer.render('/unison/script')), config.unison.script)
71
- ssh.exec!("sudo chmod +x #{config.unison.script}")
72
- ssh.exec!("sudo rm #{config.unison.crontab_entry_file}", :error_check => false)
73
- end
74
-
75
- def create_unison(ssh, opts)
76
- sanitized_string = opts[:original][:guestpath].gsub(/[^a-zA-Z0-9_-]/, '-')
77
- crontab_entry = TemplateRenderer.render('/unison/crontab_entry',
78
- :from => opts[:guestpath],
79
- :to => opts[:original][:guestpath],
80
- :options => config.unison.options,
81
- :script => config.unison.script,
82
- :log_file => (config.unison.log_file % sanitized_string))
83
-
84
- ssh.exec!("sudo rm -rf ~/.unison")
85
- ssh.exec!("sudo rm -rf #{opts[:original][:guestpath]}")
86
- ssh.exec!("sudo echo \"#{crontab_entry}\" >> #{config.unison.crontab_entry_file}")
87
- ssh.exec!("crontab #{config.unison.crontab_entry_file}")
88
- end
89
-
90
65
  def prepare_host_only_network
91
66
  # Remove any previous host only network additions to the
92
67
  # interface file.
93
68
  vm.ssh.execute do |ssh|
94
69
  # Verify debian/ubuntu
95
- ssh.exec!("cat /etc/debian_version", :error_key => :network_not_debian)
70
+ ssh.exec!("cat /etc/debian_version", :error_class => LinuxError, :_key => :network_not_debian)
96
71
 
97
72
  # Clear out any previous entries
98
73
  ssh.exec!("sudo sed -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' /etc/network/interfaces > /tmp/vagrant-network-interfaces")
@@ -130,13 +105,15 @@ module Vagrant
130
105
  break unless result
131
106
 
132
107
  attempts += 1
133
- raise Action::ActionException.new(:vm_mount_fail) if attempts >= 10
108
+ raise LinuxError.new(:mount_fail) if attempts >= 10
134
109
  sleep sleeptime
135
110
  end
136
111
  end
112
+ end
137
113
 
138
- def config
139
- vm.env.config
114
+ class Linux < Base
115
+ class LinuxError < Errors::VagrantError
116
+ error_namespace("vagrant.systems.linux")
140
117
  end
141
118
  end
142
119
  end
@@ -0,0 +1,59 @@
1
+ module Vagrant
2
+ module Systems
3
+ # A general Vagrant system implementation for "solaris".
4
+ #
5
+ # Contributed by Blake Irvin <b.irvin@modcloth.com>
6
+ class Solaris < Base
7
+ # A custom config class which will be made accessible via `config.solaris`
8
+ # This is not necessary for all system implementers, of course. However,
9
+ # generally, Vagrant tries to make almost every aspect of its execution
10
+ # configurable, and this assists that goal.
11
+ class SolarisConfig < Vagrant::Config::Base
12
+ configures :solaris
13
+
14
+ attr_accessor :halt_timeout
15
+ attr_accessor :halt_check_interval
16
+
17
+ def initialize
18
+ @halt_timeout = 30
19
+ @halt_check_interval = 1
20
+ end
21
+ end
22
+
23
+ # Here for whenever it may be used.
24
+ class SolarisError < Errors::VagrantError
25
+ error_namespace("vagrant.systems.solaris")
26
+ end
27
+
28
+ # There should be an exception raised if the line
29
+ #
30
+ # vagrant::::profiles=Primary Administrator
31
+ #
32
+ # does not exist in /etc/user_attr. TODO
33
+ def halt
34
+ vm.env.ui.info I18n.t("vagrant.systems.solaris.attempting_halt")
35
+ vm.ssh.execute do |ssh|
36
+ ssh.exec!("pfexec poweroff")
37
+ end
38
+
39
+ # Wait until the VM's state is actually powered off. If this doesn't
40
+ # occur within a reasonable amount of time (15 seconds by default),
41
+ # then simply return and allow Vagrant to kill the machine.
42
+ count = 0
43
+ while vm.vm.state != :powered_off
44
+ count += 1
45
+
46
+ return if count >= vm.env.config.solaris.halt_timeout
47
+ sleep vm.env.config.solaris.halt_check_interval
48
+ end
49
+ end
50
+
51
+ def mount_shared_folder(ssh, name, guestpath)
52
+ ssh.exec!("pfexec mkdir -p #{guestpath}")
53
+ # Using a custom mount method here; could use improvement.
54
+ ssh.exec!("pfexec mount -F vboxfs v-root #{guestpath}")
55
+ ssh.exec!("pfexec chown #{vm.env.config.ssh.username} #{guestpath}")
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,109 @@
1
+ module Vagrant
2
+ # Test helpers provided by Vagrant to allow for plugin developers
3
+ # to write automated tests for their code. This module simply provides
4
+ # methods which can be included into any test framework (`test/unit`,
5
+ # RSpec, Shoulda, etc.)
6
+ module TestHelpers
7
+ #------------------------------------------------------------
8
+ # Environment creation helpers
9
+ #------------------------------------------------------------
10
+ # Creates a "vagrant_app" directory in the test tmp folder
11
+ # which can be used for creating test Vagrant environments.
12
+ # Returns the root directory of the app. This typically doesn't need
13
+ # to be called directly unless you're setting up a custom application.
14
+ # See the examples for common use cases.
15
+ def vagrant_app(*path)
16
+ root = tmp_path.join("vagrant_app")
17
+ FileUtils.rm_rf(root)
18
+ FileUtils.mkdir_p(root)
19
+ root.join(*path)
20
+ end
21
+
22
+ # Creates a Vagrantfile with the given contents in the given
23
+ # app directory. If no app directory is specified, then a default
24
+ # Vagrant app is used.
25
+ def vagrantfile(*args)
26
+ path = args.shift.join("Vagrantfile") if Pathname === args.first
27
+ path ||= vagrant_app("Vagrantfile")
28
+ str = args.shift || ""
29
+ File.open(path.to_s, "w") do |f|
30
+ f.puts "Vagrant::Config.run do |config|"
31
+ f.puts "config.vagrant.home = '#{home_path}'"
32
+ f.puts str
33
+ f.puts "end"
34
+ end
35
+
36
+ path.parent
37
+ end
38
+
39
+ # Creates and _loads_ a Vagrant environment at the given path.
40
+ # If no path is given, then a default {#vagrantfile} is used.
41
+ def vagrant_env(*args)
42
+ path = args.shift if Pathname === args.first
43
+ path ||= vagrantfile
44
+ Vagrant::Environment.new(:cwd => path).load!
45
+ end
46
+
47
+ # Creates the folder to contain a vagrant box. This allows for
48
+ # "fake" boxes to be made with the specified name.
49
+ #
50
+ # @param [String] name
51
+ # @return [Pathname]
52
+ def vagrant_box(name)
53
+ result = boxes_path.join(name)
54
+ FileUtils.mkdir_p(result)
55
+ result
56
+ end
57
+
58
+ # Returns a blank app (callable) and action environment with the
59
+ # given vagrant environment. This allows for testing of middlewares.
60
+ def action_env(v_env = nil)
61
+ v_env ||= vagrant_env
62
+ app = lambda { |env| }
63
+ env = Vagrant::Action::Environment.new(v_env)
64
+ env["vagrant.test"] = true
65
+ [app, env]
66
+ end
67
+
68
+ #------------------------------------------------------------
69
+ # Path helpers
70
+ #------------------------------------------------------------
71
+ # Path to the tmp directory for the tests.
72
+ #
73
+ # @return [Pathname]
74
+ def tmp_path
75
+ result = Vagrant.source_root.join("test", "tmp")
76
+ FileUtils.mkdir_p(result)
77
+ result
78
+ end
79
+
80
+ # Path to the "home" directory for the tests
81
+ #
82
+ # @return [Pathname]
83
+ def home_path
84
+ result = tmp_path.join("home")
85
+ FileUtils.mkdir_p(result)
86
+ result
87
+ end
88
+
89
+ # Path to the boxes directory in the home directory
90
+ #
91
+ # @return [Pathname]
92
+ def boxes_path
93
+ result = home_path.join("boxes")
94
+ FileUtils.mkdir_p(result)
95
+ result
96
+ end
97
+
98
+ # Cleans all the test temp paths, which includes the boxes path,
99
+ # home path, etc. This allows for cleaning between tests.
100
+ def clean_paths
101
+ FileUtils.rm_rf(tmp_path)
102
+
103
+ # Call these methods only to rebuild the directories
104
+ tmp_path
105
+ home_path
106
+ boxes_path
107
+ end
108
+ end
109
+ end