vagrantup 0.6.3 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +25 -2
  3. data/Gemfile.lock +1 -1
  4. data/README.md +1 -1
  5. data/config/default.rb +1 -1
  6. data/keys/vagrant.pub +1 -1
  7. data/lib/vagrant/action/box/unpackage.rb +1 -1
  8. data/lib/vagrant/action/vm/check_box.rb +0 -1
  9. data/lib/vagrant/action/vm/nfs.rb +1 -1
  10. data/lib/vagrant/action/vm/provision.rb +2 -1
  11. data/lib/vagrant/action/warden.rb +4 -0
  12. data/lib/vagrant/box.rb +1 -0
  13. data/lib/vagrant/command/box.rb +2 -2
  14. data/lib/vagrant/command/group_base.rb +9 -1
  15. data/lib/vagrant/command/ssh.rb +3 -2
  16. data/lib/vagrant/command/ssh_config.rb +2 -2
  17. data/lib/vagrant/command/up.rb +2 -3
  18. data/lib/vagrant/config.rb +1 -0
  19. data/lib/vagrant/config/base.rb +5 -1
  20. data/lib/vagrant/errors.rb +10 -0
  21. data/lib/vagrant/hosts/bsd.rb +8 -5
  22. data/lib/vagrant/provisioners/chef.rb +18 -0
  23. data/lib/vagrant/ssh.rb +2 -0
  24. data/lib/vagrant/test_helpers.rb +13 -0
  25. data/lib/vagrant/version.rb +1 -1
  26. data/lib/vagrant/vm.rb +2 -2
  27. data/templates/commands/init/Vagrantfile.erb +44 -6
  28. data/templates/locales/en.yml +9 -2
  29. data/test/test_helper.rb +0 -18
  30. data/test/vagrant/action/box/unpackage_test.rb +7 -0
  31. data/test/vagrant/action/vm/check_box_test.rb +0 -1
  32. data/test/vagrant/action/vm/nfs_test.rb +10 -0
  33. data/test/vagrant/action/vm/provision_test.rb +14 -0
  34. data/test/vagrant/action/warden_test.rb +14 -0
  35. data/test/vagrant/box_test.rb +8 -0
  36. data/test/vagrant/config/base_test.rb +6 -0
  37. data/test/vagrant/config/vagrant_test.rb +33 -1
  38. data/test/vagrant/config_test.rb +5 -0
  39. data/test/vagrant/downloaders/file_test.rb +1 -1
  40. data/test/vagrant/downloaders/http_test.rb +1 -1
  41. data/test/vagrant/provisioners/chef_server_test.rb +1 -2
  42. data/test/vagrant/provisioners/chef_solo_test.rb +1 -2
  43. data/test/vagrant/provisioners/chef_test.rb +74 -3
  44. data/test/vagrant/ssh_test.rb +14 -3
  45. data/test/vagrant/vm_test.rb +12 -4
  46. metadata +1 -2
  47. data/templates/Vagrantfile.erb +0 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 14d0ef8ef3866fc0f16173c54a94f3e245233a26
4
- data.tar.gz: e0ada417bb811328e47365823c4e93db9d2d0f0b
3
+ metadata.gz: c7774d56a146be915ab2c003c58eef8852a73926
4
+ data.tar.gz: 6afffeaa05b58333156897f908a4c59dca62954e
5
5
  SHA512:
6
- metadata.gz: 5c9a1c752d0ea9a904e8daf13c939f7627b9fc960defaae85be43ed61bc11eabdeb8cdc1ca9dec967e64edc99a58eb5109a898de7459d0145eb222fd6cae7fa0
7
- data.tar.gz: b1dc538455a7d7a297028a39d9d34148651234c1a64da4c9ced099dcc79487d3d09ed6114b7a9a054fbfdb89b4e7e1ae6576fdcd206a3796c5f78a0a6d11d5c7
6
+ metadata.gz: a94e8319dd6a3ca3c68989db0d701003ac5cde3acc0d202129460beff3e4327f6452d485236d89cde5f1ef16aea6d9c5e9b04cf9974fe552eb687808de37f226
7
+ data.tar.gz: c1f01a2da554d695a8550573416e917ab53ba219835c794fda60ca8314a71348802ccf4c98d98105cb312a7f80983a8ebbf50872cb1315f827e777b8270cff54
data/CHANGELOG.md CHANGED
@@ -1,6 +1,29 @@
1
- ## 0.6.1 (September 27, 2010)
1
+ ## 0.6.4 (October 4, 2010)
2
2
 
3
- - Fix issues with Ruby 1.8.7 where Vagrant simply failed.
3
+ - Default VM name is now properly the parent folder of the working directory
4
+ of the environment.
5
+ - Added method to `TestHelpers` to assist with testing new downloaders.
6
+ - `up --no-provision` works again. This disables provisioning during the
7
+ boot process.
8
+ - Action warden doesn't do recovery process on `SystemExit` exceptions,
9
+ allowing the double ctrl-C to work properly again. [related to GH-166]
10
+ - Initial Vagrantfile is now heavily commented with various available
11
+ options. [GH-171]
12
+ - Box add checks if a box already exists before the download. [GH-170]
13
+ - NFS no longer attempts to clean exports file if VM is not created,
14
+ which was causing a stack trace during recovery. [related to GH-166]
15
+ - Basic validation added for Chef configuration (both solo and server).
16
+ - Top config class is now available in all `Vagrant::Config::Base`
17
+ subclasses, which is useful for config validation.
18
+ - Subcommand help shows proper full command in task listing. [GH-168]
19
+ - SSH gives error message if `ssh` binary is not found. [GH-161]
20
+ - SSH gives proper error message if VM is not running. [GH-167]
21
+ - Fix some issues with undefined constants in command errors.
22
+
23
+ ## 0.6.1, 0.6.2, 0.6.3 (September 27, 2010)
24
+
25
+ A lot of quick releases which all were to fix issues with Ruby 1.8.7
26
+ compatibility.
4
27
 
5
28
  ## 0.6.0 (September 27, 2010)
6
29
 
data/Gemfile.lock CHANGED
@@ -8,7 +8,7 @@ GIT
8
8
  PATH
9
9
  remote: .
10
10
  specs:
11
- vagrant (0.6.3)
11
+ vagrant (0.6.4)
12
12
  archive-tar-minitar (= 0.5.2)
13
13
  erubis (~> 2.6.6)
14
14
  i18n (~> 0.4.1)
data/README.md CHANGED
@@ -10,7 +10,7 @@ Vagrant is a tool for building and distributing virtualized development environm
10
10
  By providing automated creation and provisioning of virtual machines using [Oracle’s VirtualBox](http://www.virtualbox.org),
11
11
  Vagrant provides the tools to create and configure lightweight, reproducible, and portable
12
12
  virtual environments. For more information, see the part of the getting started guide
13
- on [Why Vagrant?](http://vagrantup.com/docs/getting-started/index.html)”
13
+ on [Why Vagrant?](http://vagrantup.com/docs/getting-started/index.html)”
14
14
 
15
15
  ## Quick Start
16
16
 
data/config/default.rb CHANGED
@@ -27,7 +27,7 @@ Vagrant::Config.run do |config|
27
27
 
28
28
  config.vm.customize do |vm|
29
29
  # Make VM name the name of the containing folder by default
30
- vm.name = File.basename(File.expand_path("../", Vagrant.source_root)) + "_#{Time.now.to_i}"
30
+ vm.name = File.basename(config.env.cwd) + "_#{Time.now.to_i}"
31
31
  end
32
32
 
33
33
  # Share the root folder. This can then be overridden by
data/keys/vagrant.pub CHANGED
@@ -1 +1 @@
1
- ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== johnbender@vagrant.local
1
+ ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key
@@ -31,7 +31,7 @@ module Vagrant
31
31
  end
32
32
 
33
33
  def recover(env)
34
- if File.directory?(box_directory)
34
+ if box_directory && File.directory?(box_directory)
35
35
  FileUtils.rm_rf(box_directory)
36
36
  end
37
37
  end
@@ -16,7 +16,6 @@ module Vagrant
16
16
 
17
17
  env.ui.info I18n.t("vagrant.actions.vm.check_box.not_found", :name => box_name)
18
18
  Vagrant::Box.add(env.env, box_name, box_url)
19
- env.env.load_box!
20
19
  end
21
20
 
22
21
  @app.call(env)
@@ -42,7 +42,7 @@ module Vagrant
42
42
  end
43
43
 
44
44
  def recover(env)
45
- clear_nfs_exports(env)
45
+ clear_nfs_exports(env) if env["vm"].created?
46
46
  end
47
47
 
48
48
  # Returns the folders which are to be synced via NFS.
@@ -5,6 +5,7 @@ module Vagrant
5
5
  def initialize(app, env)
6
6
  @app = app
7
7
  @env = env
8
+ @env["provision.enabled"] = true if !@env.has_key?("provision.enabled")
8
9
 
9
10
  load_provisioner if provisioning_enabled?
10
11
  end
@@ -19,7 +20,7 @@ module Vagrant
19
20
  end
20
21
 
21
22
  def provisioning_enabled?
22
- !@env["config"].vm.provisioner.nil?
23
+ !@env["config"].vm.provisioner.nil? && @env["provision.enabled"]
23
24
  end
24
25
 
25
26
  def load_provisioner
@@ -26,6 +26,10 @@ module Vagrant
26
26
  raise Errors::VagrantInterrupt.new if env.interrupted?
27
27
  @stack.unshift(@actions.shift).first.call(env)
28
28
  raise Errors::VagrantInterrupt.new if env.interrupted?
29
+ rescue SystemExit
30
+ # This means that an "exit" or "abort" was called. In these cases,
31
+ # we just exit immediately.
32
+ raise
29
33
  rescue Exception => e
30
34
  env["vagrant.error"] = e
31
35
 
data/lib/vagrant/box.rb CHANGED
@@ -57,6 +57,7 @@ module Vagrant
57
57
  # method requires that `name` and `uri` be set. The logic of this method
58
58
  # is kicked out to the `box_add` registered middleware.
59
59
  def add
60
+ raise Errors::BoxAlreadyExists.new(:name => name) if File.directory?(directory)
60
61
  env.actions.run(:box_add, { "box" => self })
61
62
  end
62
63
 
@@ -11,14 +11,14 @@ module Vagrant
11
11
  desc "remove NAME", "Remove a box from the system"
12
12
  def remove(name)
13
13
  b = env.boxes.find(name)
14
- raise BoxNotFound.new(:name => name) if !b
14
+ raise Errors::BoxNotFound.new(:name => name) if !b
15
15
  b.destroy
16
16
  end
17
17
 
18
18
  desc "repackage NAME", "Repackage an installed box into a `.box` file."
19
19
  def repackage(name)
20
20
  b = env.boxes.find(name)
21
- raise BoxNotFound.new(:name => name) if !b
21
+ raise Errors::BoxNotFound.new(:name => name) if !b
22
22
  b.repackage
23
23
  end
24
24
 
@@ -87,13 +87,21 @@ module Vagrant
87
87
  # @param [String] description
88
88
  # @param [Hash] opts
89
89
  def self.register(usage, description, opts=nil)
90
- CLI.register(self, Base.extract_name_from_usage(usage), usage, description, opts)
90
+ @_name = Base.extract_name_from_usage(usage)
91
+ CLI.register(self, @_name, usage, description, opts)
91
92
  end
92
93
 
93
94
  def initialize(*args)
94
95
  super
95
96
  initialize_environment(*args)
96
97
  end
98
+
99
+ protected
100
+
101
+ # Override the basename to include the subcommand name.
102
+ def self.basename
103
+ "#{super} #{@_name}"
104
+ end
97
105
  end
98
106
  end
99
107
  end
@@ -24,14 +24,15 @@ module Vagrant
24
24
  end
25
25
 
26
26
  def ssh_connect
27
- raise VMNotCreatedError.new if !ssh_vm.created?
27
+ raise Errors::VMNotCreatedError.new if !ssh_vm.created?
28
+ raise Errors::VMNotRunningError.new if !ssh_vm.vm.running?
28
29
  ssh_vm.ssh.connect
29
30
  end
30
31
 
31
32
  def ssh_vm
32
33
  @ssh_vm ||= begin
33
34
  vm = self.name.nil? && env.multivm? ? env.primary_vm : nil
34
- raise MultiVMTargetRequired.new(:command => "ssh") if !vm && target_vms.length > 1
35
+ raise Errors::MultiVMTargetRequired.new(:command => "ssh") if !vm && target_vms.length > 1
35
36
  vm = target_vms.first if !vm
36
37
  vm
37
38
  end
@@ -5,9 +5,9 @@ module Vagrant
5
5
  register "ssh_config", "outputs .ssh/config valid syntax for connecting to this environment via ssh"
6
6
 
7
7
  def execute
8
- raise MultiVMTargetRequired.new(:command => "ssh_config") if target_vms.length > 1
8
+ raise Errors::MultiVMTargetRequired.new(:command => "ssh_config") if target_vms.length > 1
9
9
  vm = target_vms.first
10
- raise VMNotCreatedError.new if !vm.created?
10
+ raise Errors::VMNotCreatedError.new if !vm.created?
11
11
 
12
12
  env.ui.info(Util::TemplateRenderer.render("ssh_config", {
13
13
  :host_key => options[:host] || "vagrant",
@@ -5,13 +5,12 @@ module Vagrant
5
5
  register "up", "Creates the Vagrant environment"
6
6
 
7
7
  def execute
8
- # TODO: Make the options[:provision] actually mean something
9
8
  target_vms.each do |vm|
10
9
  if vm.created?
11
10
  vm.env.ui.info I18n.t("vagrant.commands.up.vm_created")
12
- vm.start
11
+ vm.start("provision.enabled" => options[:provision])
13
12
  else
14
- vm.up
13
+ vm.up("provision.enabled" => options[:provision])
15
14
  end
16
15
  end
17
16
  end
@@ -137,6 +137,7 @@ module Vagrant
137
137
  self.class.configures_list.each do |key, klass|
138
138
  config = klass.new
139
139
  config.env = env
140
+ config.top = self
140
141
  instance_variable_set("@#{key}".to_sym, config)
141
142
  end
142
143
 
@@ -4,8 +4,12 @@ module Vagrant
4
4
  # basic things such as the environment instance variable which all
5
5
  # config classes need as well as a basic `to_json` implementation.
6
6
  class Base
7
+ # {Environment} that this config belongs to
7
8
  attr_accessor :env
8
9
 
10
+ # {Top} of this configuration stack
11
+ attr_accessor :top
12
+
9
13
  # Registers a subclass with the Vagrant configuration system so
10
14
  # that it can then be used in Vagrantfiles.
11
15
  #
@@ -58,7 +62,7 @@ module Vagrant
58
62
  # Returns the instance variables as a hash of key-value pairs.
59
63
  def instance_variables_hash
60
64
  instance_variables.inject({}) do |acc, iv|
61
- acc[iv.to_s[1..-1]] = instance_variable_get(iv) unless iv.to_sym == :@env
65
+ acc[iv.to_s[1..-1]] = instance_variable_get(iv) unless [:@env, :@top].include?(iv.to_sym)
62
66
  acc
63
67
  end
64
68
  end
@@ -243,6 +243,11 @@ module Vagrant
243
243
  error_key(:ssh_key_bad_permissions)
244
244
  end
245
245
 
246
+ class SSHUnavailable < VagrantError
247
+ status_code(45)
248
+ error_key(:ssh_unavailable)
249
+ end
250
+
246
251
  class SSHUnavailableWindows < VagrantError
247
252
  status_code(10)
248
253
  error_key(:ssh_unavailable_windows)
@@ -293,6 +298,11 @@ module Vagrant
293
298
  error_key(:vm_not_found)
294
299
  end
295
300
 
301
+ class VMNotRunningError < VagrantError
302
+ status_code(44)
303
+ error_key(:vm_not_running)
304
+ end
305
+
296
306
  class VMPowerOffToPackage < VagrantError
297
307
  status_code(24)
298
308
  error_key(:power_off, "vagrant.actions.vm.export")
@@ -35,12 +35,15 @@ module Vagrant
35
35
 
36
36
  def nfs_cleanup
37
37
  return if !File.exist?("/etc/exports")
38
- system("cat /etc/exports | grep 'VAGRANT-BEGIN: #{env.vm.uuid}' > /dev/null 2>&1")
39
38
 
40
- if $?.to_i == 0
41
- # Use sed to just strip out the block of code which was inserted
42
- # by Vagrant
43
- system("sudo sed -e '/^# VAGRANT-BEGIN: #{env.vm.uuid}/,/^# VAGRANT-END: #{env.vm.uuid}/ d' -i bak /etc/exports")
39
+ retryable(:tries => 10, :on => TypeError) do
40
+ system("cat /etc/exports | grep 'VAGRANT-BEGIN: #{env.vm.uuid}' > /dev/null 2>&1")
41
+
42
+ if $?.to_i == 0
43
+ # Use sed to just strip out the block of code which was inserted
44
+ # by Vagrant
45
+ system("sudo sed -e '/^# VAGRANT-BEGIN: #{env.vm.uuid}/,/^# VAGRANT-END: #{env.vm.uuid}/ d' -i bak /etc/exports")
46
+ end
44
47
  end
45
48
  end
46
49
  end
@@ -125,6 +125,24 @@ module Vagrant
125
125
  result.delete("json")
126
126
  result
127
127
  end
128
+
129
+ def validate(errors)
130
+ if top.vm.provisioner == :chef_solo
131
+ # Validate chef solo settings
132
+ errors.add(I18n.t("vagrant.config.chef.cookbooks_path_empty")) if !cookbooks_path || [cookbooks_path].flatten.empty?
133
+ end
134
+
135
+ if top.vm.provisioner == :chef_server
136
+ # Validate chef server settings
137
+ errors.add(I18n.t("vagrant.config.chef.server_url_empty")) if !chef_server_url || chef_server_url.strip == ""
138
+ errors.add(I18n.t("vagrant.config.chef.validation_key_path")) if !validation_key_path
139
+ end
140
+
141
+ if [:chef_solo, :chef_server].include?(top.vm.provisioner)
142
+ # Validations shared by both chef solo and server
143
+ errors.add(I18n.t("vagrant.config.chef.run_list_empty")) if !run_list || run_list.empty?
144
+ end
145
+ end
128
146
  end
129
147
  end
130
148
  end
data/lib/vagrant/ssh.rb CHANGED
@@ -26,6 +26,8 @@ module Vagrant
26
26
  :ssh_port => port(opts))
27
27
  end
28
28
 
29
+ raise Errors::SSHUnavailable.new if !Kernel.system("which ssh > /dev/null 2>&1")
30
+
29
31
  options = {}
30
32
  options[:port] = port(opts)
31
33
  [:host, :username, :private_key_path].each do |param|
@@ -55,6 +55,19 @@ module Vagrant
55
55
  result
56
56
  end
57
57
 
58
+ # Returns an instantiated downloader with a mocked tempfile
59
+ # which can be passed into it.
60
+ #
61
+ # @param [Class] klass The downloader class
62
+ # @return [Array] Returns an array of `downloader` `tempfile`
63
+ def vagrant_mock_downloader(klass)
64
+ tempfile = mock("tempfile")
65
+ tempfile.stubs(:write)
66
+
67
+ _, env = action_env
68
+ [klass.new(env), tempfile]
69
+ end
70
+
58
71
  # Returns a blank app (callable) and action environment with the
59
72
  # given vagrant environment. This allows for testing of middlewares.
60
73
  def action_env(v_env = nil)
@@ -2,5 +2,5 @@ module Vagrant
2
2
  # This will always be up to date with the current version of Vagrant,
3
3
  # since it is used to generate the gemspec and is also the source of
4
4
  # the version for `vagrant -v`
5
- VERSION = "0.6.3"
5
+ VERSION = "0.6.4"
6
6
  end
data/lib/vagrant/vm.rb CHANGED
@@ -115,11 +115,11 @@ module Vagrant
115
115
  env.actions.run(:up, options)
116
116
  end
117
117
 
118
- def start
118
+ def start(options=nil)
119
119
  return if @vm.running?
120
120
  return resume if @vm.saved?
121
121
 
122
- env.actions.run(:start)
122
+ env.actions.run(:start, options)
123
123
  end
124
124
 
125
125
  def halt(options=nil)
@@ -1,13 +1,51 @@
1
1
  Vagrant::Config.run do |config|
2
- # All Vagrant configuration is done here. For a detailed explanation
3
- # and listing of configuration options, please view the documentation
4
- # online.
2
+ # All Vagrant configuration is done here. The most common configuration
3
+ # options are documented and commented below. For a complete reference,
4
+ # please see the online documentation at vagrantup.com.
5
5
 
6
6
  # Every Vagrant virtual environment requires a box to build off of.
7
7
  config.vm.box = "<%= box_name %>"
8
- <% if !box_url.nil? %>
9
8
 
10
9
  # The url from where the 'config.vm.box' box will be fetched if it
11
- # doesn't already exist on the user's system
12
- config.vm.box_url = "<%= box_url %>"<% end %>
10
+ # doesn't already exist on the user's system.
11
+ <% if box_url.nil? %># <% end %>config.vm.box_url = "<%= box_url || "http://domain.com/path/to/above.box" %>"
12
+
13
+ # Boot with a GUI so you can see the screen. (Default is headless)
14
+ # config.vm.boot_mode = :gui
15
+
16
+ # Assign this VM to a host only network IP, allowing you to access it
17
+ # via the IP.
18
+ # config.vm.network "33.33.33.10"
19
+
20
+ # Forward a port from the guest to the host, which allows for outside
21
+ # computers to access the VM, whereas host only networking does not.
22
+ # config.vm.forward_port "http", 80, 8080
23
+
24
+ # Share an additional folder to the guest VM. The first argument is
25
+ # an identifier, the second is the path on the guest to mount the
26
+ # folder, and the third is the path on the host to the actual folder.
27
+ # config.vm.share_folder "v-data", "/vagrant_data", "../data")
28
+
29
+ # Enable provisioning with chef solo, specifying a cookbooks path (relative
30
+ # to this Vagrantfile), and adding some recipes and/or roles.
31
+ #
32
+ # config.vm.provisioner = :chef_solo
33
+ # config.chef.cookbooks_path = "cookbooks"
34
+ # config.chef.add_recipe "mysql"
35
+ # config.chef.add_role "web"
36
+ #
37
+ # You may also specify custom JSON attributes:
38
+ # config.chef.json = { :mysql_password => "foo" }
39
+
40
+ # Enable provisioning with chef server, specifying the chef server URL,
41
+ # and the path to the validation key (relative to this Vagrantfile).
42
+ #
43
+ # config.vm.provisioner = :chef_server
44
+ # config.chef.chef_server_url = "http://api.opscode.com/organizations/organization"
45
+ # config.chef.validation_key_path = "kiip-validator.pem"
46
+ #
47
+ # If you're using the OpsCode platform, you'll have to set this as well.
48
+ # If you're using your own chef server, you may have to set it, but it depends
49
+ # on how your Chef server is configured.
50
+ # config.chef.validation_client_name = "organization-validator"
13
51
  end
@@ -43,6 +43,7 @@ en:
43
43
  permissions on the following file to 0600 and then try running this command again:
44
44
 
45
45
  %{key_path}
46
+ ssh_unavailable: "`ssh` binary could not be found. Is an SSH client installed?"
46
47
  ssh_unavailable_windows: |-
47
48
  `vagrant ssh` isn't available on the Windows platform. The
48
49
  vagrant.ppk file for use with Putty is available at:
@@ -88,8 +89,9 @@ en:
88
89
  Vagrant could not detect VirtualBox! Make sure VirtualBox is properly installed.
89
90
  If VirtualBox is installed, it may be an incorrect version. Vagrant currently
90
91
  requires VirtualBox 3.2.x. Please install the proper version to continue.
91
- vm_creation_required: VM must be created before running this command. Run `vagrant up` first.
92
- vm_not_found: A VM by the name of %{name} was not found.
92
+ vm_creation_required: "VM must be created before running this command. Run `vagrant up` first."
93
+ vm_not_found: "A VM by the name of %{name} was not found."
94
+ vm_not_running: "VM must be running to open SSH connection."
93
95
 
94
96
  #-------------------------------------------------------------------------------
95
97
  # Translations for config validation errors
@@ -97,6 +99,11 @@ en:
97
99
  config:
98
100
  common:
99
101
  error_empty: `%{field}` must be filled in.
102
+ chef:
103
+ run_list_empty: "Run list must not be empty."
104
+ cookbooks_path_empty: "Must specify a cookbooks path for chef solo."
105
+ server_url_empty: "Chef server URL must be populated."
106
+ validation_key_path: "Validation key path must be valid path to your chef server validation key."
100
107
  ssh:
101
108
  private_key_missing: "`private_key_path` file must exist: %{path}"
102
109
  vm:
data/test/test_helper.rb CHANGED
@@ -22,23 +22,5 @@ I18n.load_path << File.expand_path("../locales/en.yml", __FILE__)
22
22
 
23
23
  class Test::Unit::TestCase
24
24
  include Vagrant::TestHelpers
25
-
26
- # Sets up the mocks for a VM
27
- def mock_vm(env=nil)
28
- env ||= vagrant_env
29
- vm = Vagrant::VM.new
30
- vm.stubs(:env).returns(env)
31
- vm.stubs(:ssh).returns(Vagrant::SSH.new(vm.env))
32
- vm
33
- end
34
-
35
- # Sets up the mocks and stubs for a downloader
36
- def mock_downloader(downloader_klass)
37
- tempfile = mock("tempfile")
38
- tempfile.stubs(:write)
39
-
40
- _, env = action_env
41
- [downloader_klass.new(env), tempfile]
42
- end
43
25
  end
44
26
 
@@ -26,6 +26,13 @@ class UnpackageBoxActionTest < Test::Unit::TestCase
26
26
  FileUtils.stubs(:rm_rf)
27
27
  end
28
28
 
29
+ should "do nothing if box directory is not set" do
30
+ @instance.stubs(:box_directory).returns(nil)
31
+ File.expects(:directory?).never
32
+ FileUtils.expects(:rm_rf).never
33
+ @instance.recover(nil)
34
+ end
35
+
29
36
  should "do nothing if not a directory" do
30
37
  FileUtils.expects(:rm_rf).never
31
38
  @instance.recover(nil)
@@ -47,7 +47,6 @@ class CheckBoxVMActionTest < Test::Unit::TestCase
47
47
  seq = sequence("seq")
48
48
  env.env.boxes.expects(:find).returns(nil)
49
49
  Vagrant::Box.expects(:add).with(env.env, env["config"].vm.box, env["config"].vm.box_url).in_sequence(seq)
50
- env.env.expects(:load_box!).in_sequence(seq)
51
50
  app.expects(:call).with(env).once.in_sequence(seq)
52
51
 
53
52
  assert_nothing_raised {
@@ -68,10 +68,20 @@ class NFSVMActionTest < Test::Unit::TestCase
68
68
  end
69
69
 
70
70
  context "recovery" do
71
+ setup do
72
+ @vm.stubs(:created?).returns(true)
73
+ end
74
+
71
75
  should "clear NFS exports" do
72
76
  @instance.expects(:clear_nfs_exports).with(@env).once
73
77
  @instance.recover(@env)
74
78
  end
79
+
80
+ should "do nothing if VM is not created" do
81
+ @vm.stubs(:created?).returns(false)
82
+ @instance.expects(:clear_nfs_exports).never
83
+ @instance.recover(@env)
84
+ end
75
85
  end
76
86
 
77
87
  context "extracting folders" do
@@ -31,6 +31,12 @@ class ProvisionVMActionTest < Test::Unit::TestCase
31
31
  @klass.any_instance.expects(:load_provisioner).never
32
32
  @klass.new(@app, @env)
33
33
  end
34
+
35
+ should "not load provisioner if disabled through env hash" do
36
+ @env["provision.enabled"] = false
37
+ @klass.any_instance.expects(:load_provisioner).never
38
+ @klass.new(@app, @env)
39
+ end
34
40
  end
35
41
 
36
42
  context "with an instance" do
@@ -122,6 +128,14 @@ class ProvisionVMActionTest < Test::Unit::TestCase
122
128
 
123
129
  @instance.call(@env)
124
130
  end
131
+
132
+ should "continue chain and not provision if not enabled through env hash" do
133
+ @env["provision.enabled"] = false
134
+ @prov.expects(:provision!).never
135
+ @app.expects(:call).with(@env).once
136
+
137
+ @instance.call(@env)
138
+ end
125
139
  end
126
140
  end
127
141
  end
@@ -70,6 +70,20 @@ class ActionWardenTest < Test::Unit::TestCase
70
70
  assert_raises(RuntimeError) { @instance.call(new_env) }
71
71
  end
72
72
 
73
+ should "not begin recovery sequence if a SystemExit is raised" do
74
+ class Foo
75
+ def initialize(*args); end
76
+ def call(env)
77
+ # Raises a system exit
78
+ abort
79
+ end
80
+ end
81
+
82
+ @instance.actions << Foo.new
83
+ @instance.expects(:begin_rescue).never
84
+ assert_raises(SystemExit) { @instance.call(new_env) }
85
+ end
86
+
73
87
  should "raise interrupt if the environment is interupted" do
74
88
  env = new_env
75
89
  env.expects(:interrupted?).returns(true)
@@ -27,6 +27,14 @@ class BoxTest < Test::Unit::TestCase
27
27
  @box = Vagrant::Box.new(vagrant_env, "foo")
28
28
  end
29
29
 
30
+ should "raise an exception if a box exists with the name we're attempting to add" do
31
+ vagrant_box(@box.name)
32
+
33
+ assert_raises(Vagrant::Errors::BoxAlreadyExists) {
34
+ @box.add
35
+ }
36
+ end
37
+
30
38
  should "execute the Add action when add is called" do
31
39
  @box.env.actions.expects(:run).with(:box_add, { "box" => @box })
32
40
  @box.add
@@ -47,6 +47,12 @@ class ConfigBaseTest < Test::Unit::TestCase
47
47
  hash = @base.instance_variables_hash
48
48
  assert !hash.has_key?(:env)
49
49
  end
50
+
51
+ should "not include top in the JSON hash" do
52
+ @base.top = "FOO"
53
+ hash = @base.instance_variables_hash
54
+ assert !hash.has_key?(:top)
55
+ end
50
56
  end
51
57
  end
52
58
  end
@@ -6,6 +6,38 @@ class ConfigVagrantTest < Test::Unit::TestCase
6
6
  end
7
7
 
8
8
  context "validation" do
9
- # TODO
9
+ setup do
10
+ @config.dotfile_name = "foo"
11
+ @config.home = "foo"
12
+ @config.host = "foo"
13
+
14
+ @errors = Vagrant::Config::ErrorRecorder.new
15
+ end
16
+
17
+ should "be valid with given set of values" do
18
+ @config.validate(@errors)
19
+ assert @errors.errors.empty?
20
+ end
21
+
22
+ should "be invalid with no dotfile" do
23
+ @config.dotfile_name = nil
24
+
25
+ @config.validate(@errors)
26
+ assert !@errors.errors.empty?
27
+ end
28
+
29
+ should "be invalid with no home" do
30
+ @config.home = nil
31
+
32
+ @config.validate(@errors)
33
+ assert !@errors.errors.empty?
34
+ end
35
+
36
+ should "be invalid with no host" do
37
+ @config.host = nil
38
+
39
+ @config.validate(@errors)
40
+ assert !@errors.errors.empty?
41
+ end
10
42
  end
11
43
  end
@@ -167,6 +167,10 @@ class ConfigTest < Test::Unit::TestCase
167
167
  klass = mock("klass#{i}")
168
168
  instance = mock("instance#{i}")
169
169
  instance.expects(:env=).with(env)
170
+ instance.expects(:top=).with() do |top|
171
+ assert top.is_a?(@klass::Top)
172
+ true
173
+ end
170
174
  klass.expects(:new).returns(instance)
171
175
  @configures_list[key] = klass
172
176
  end
@@ -179,6 +183,7 @@ class ConfigTest < Test::Unit::TestCase
179
183
  klass = mock("klass")
180
184
  instance = mock("instance")
181
185
  instance.stubs(:env=)
186
+ instance.stubs(:top=)
182
187
  klass.expects(:new).returns(instance)
183
188
  @klass::Top.configures(key, klass)
184
189
 
@@ -2,7 +2,7 @@ require "test_helper"
2
2
 
3
3
  class FileDownloaderTest < Test::Unit::TestCase
4
4
  setup do
5
- @downloader, @tempfile = mock_downloader(Vagrant::Downloaders::File)
5
+ @downloader, @tempfile = vagrant_mock_downloader(Vagrant::Downloaders::File)
6
6
  @uri = "foo.box"
7
7
  end
8
8
 
@@ -2,7 +2,7 @@ require "test_helper"
2
2
 
3
3
  class HttpDownloaderTest < Test::Unit::TestCase
4
4
  setup do
5
- @downloader, @tempfile = mock_downloader(Vagrant::Downloaders::HTTP)
5
+ @downloader, @tempfile = vagrant_mock_downloader(Vagrant::Downloaders::HTTP)
6
6
  @downloader.stubs(:report_progress)
7
7
  @downloader.stubs(:complete_progress)
8
8
  @uri = "http://google.com/"
@@ -2,8 +2,7 @@ require "test_helper"
2
2
 
3
3
  class ChefServerProvisionerTest < Test::Unit::TestCase
4
4
  setup do
5
- @action_env = Vagrant::Action::Environment.new(vagrant_env)
6
- @action_env.env.vm = mock_vm
5
+ @action_env = Vagrant::Action::Environment.new(vagrant_env.vms[:default].env)
7
6
 
8
7
  @action = Vagrant::Provisioners::ChefServer.new(@action_env)
9
8
  @env = @action.env
@@ -2,8 +2,7 @@ require "test_helper"
2
2
 
3
3
  class ChefSoloProvisionerTest < Test::Unit::TestCase
4
4
  setup do
5
- @action_env = Vagrant::Action::Environment.new(vagrant_env)
6
- @action_env.env.vm = mock_vm
5
+ @action_env = Vagrant::Action::Environment.new(vagrant_env.vms[:default].env)
7
6
 
8
7
  @action = Vagrant::Provisioners::ChefSolo.new(@action_env)
9
8
  @env = @action.env
@@ -2,8 +2,7 @@ require "test_helper"
2
2
 
3
3
  class ChefProvisionerTest < Test::Unit::TestCase
4
4
  setup do
5
- @action_env = Vagrant::Action::Environment.new(vagrant_env)
6
- @action_env.env.vm = mock_vm
5
+ @action_env = Vagrant::Action::Environment.new(vagrant_env.vms[:default].env)
7
6
 
8
7
  @action = Vagrant::Provisioners::Chef.new(@action_env)
9
8
  @env = @action.env
@@ -21,7 +20,6 @@ class ChefProvisionerTest < Test::Unit::TestCase
21
20
  context "config" do
22
21
  setup do
23
22
  @config = Vagrant::Provisioners::Chef::ChefConfig.new
24
- @config.run_list.clear
25
23
  end
26
24
 
27
25
  should "not include the 'json' key in the config dump" do
@@ -44,6 +42,10 @@ class ChefProvisionerTest < Test::Unit::TestCase
44
42
  }
45
43
  end
46
44
 
45
+ should "have an empty run list to begin with" do
46
+ assert @config.run_list.empty?
47
+ end
48
+
47
49
  should "add a recipe to the run list" do
48
50
  @config.add_recipe("foo")
49
51
  assert_equal "recipe[foo]", @config.run_list[0]
@@ -63,6 +65,74 @@ class ChefProvisionerTest < Test::Unit::TestCase
63
65
  @config.add_role("role[user]")
64
66
  assert_equal "role[user]", @config.run_list[0]
65
67
  end
68
+
69
+ context "validation" do
70
+ setup do
71
+ @errors = Vagrant::Config::ErrorRecorder.new
72
+ @top = @config.top = Vagrant::Config::Top.new(@env)
73
+ end
74
+
75
+ context "chef solo" do
76
+ setup do
77
+ @top.vm.provisioner = :chef_solo
78
+
79
+ @config.run_list = ["foo"]
80
+ @config.cookbooks_path = "cookbooks"
81
+ end
82
+
83
+ should "be valid if provisioner is not chef solo" do
84
+ @top.vm.provisioner = nil
85
+ @config.validate(@errors)
86
+ assert @errors.errors.empty?
87
+ end
88
+
89
+ should "be invalid if run list is empty" do
90
+ @config.run_list = []
91
+ @config.validate(@errors)
92
+ assert !@errors.errors.empty?
93
+ end
94
+
95
+ should "be invalid if cookbooks path is empty" do
96
+ @config.cookbooks_path = nil
97
+ @config.validate(@errors)
98
+ assert !@errors.errors.empty?
99
+ end
100
+ end
101
+
102
+ context "chef server" do
103
+ setup do
104
+ @top.vm.provisioner = :chef_server
105
+
106
+ @config.run_list = ["foo"]
107
+ @config.chef_server_url = "foo"
108
+ @config.validation_key_path = "foo"
109
+ end
110
+
111
+ should "be valid if provisioner is not chef solo" do
112
+ @top.vm.provisioner = nil
113
+ @config.validate(@errors)
114
+ assert @errors.errors.empty?
115
+ end
116
+
117
+ should "be invalid if run list is empty" do
118
+ @config.run_list = []
119
+ @config.validate(@errors)
120
+ assert !@errors.errors.empty?
121
+ end
122
+
123
+ should "be invalid if run list is empty" do
124
+ @config.chef_server_url = nil
125
+ @config.validate(@errors)
126
+ assert !@errors.errors.empty?
127
+ end
128
+
129
+ should "be invalid if run list is empty" do
130
+ @config.validation_key_path = nil
131
+ @config.validate(@errors)
132
+ assert !@errors.errors.empty?
133
+ end
134
+ end
135
+ end
66
136
  end
67
137
 
68
138
  context "verifying binary" do
@@ -77,6 +147,7 @@ class ChefProvisionerTest < Test::Unit::TestCase
77
147
  @action.verify_binary(binary)
78
148
  end
79
149
  end
150
+
80
151
  context "permissions on provisioning folder" do
81
152
  should "create and chown the folder to the ssh user" do
82
153
  ssh_seq = sequence("ssh_seq")
@@ -2,12 +2,10 @@ require "test_helper"
2
2
 
3
3
  class SshTest < Test::Unit::TestCase
4
4
  def mock_ssh
5
- @env = vagrant_env
5
+ @env = vagrant_env.vms[:default].env
6
6
  @network_adapters = []
7
7
  @vm = mock("vm")
8
8
  @vm.stubs(:network_adapters).returns(@network_adapters)
9
-
10
- @env.stubs(:vm).returns(mock_vm(@env))
11
9
  @env.vm.stubs(:vm).returns(@vm)
12
10
 
13
11
  @ssh = Vagrant::SSH.new(@env)
@@ -22,10 +20,23 @@ class SshTest < Test::Unit::TestCase
22
20
  mock_ssh
23
21
  @ssh.stubs(:check_key_permissions)
24
22
  Kernel.stubs(:exec)
23
+ Kernel.stubs(:system).returns(true)
25
24
 
26
25
  Vagrant::Util::Platform.stubs(:leopard?).returns(false)
27
26
  end
28
27
 
28
+ should "raise an exception if SSH is not found" do
29
+ Kernel.stubs(:system).returns(false)
30
+ Kernel.expects(:system).returns(false).with() do |command|
31
+ assert command =~ /^which ssh/
32
+ true
33
+ end
34
+
35
+ assert_raises(Vagrant::Errors::SSHUnavailable) {
36
+ @ssh.connect
37
+ }
38
+ end
39
+
29
40
  should "check key permissions prior to exec" do
30
41
  exec_seq = sequence("exec_seq")
31
42
  @ssh.expects(:check_key_permissions).with(@env.config.ssh.private_key_path).once.in_sequence(exec_seq)
@@ -3,8 +3,6 @@ require "test_helper"
3
3
  class VMTest < Test::Unit::TestCase
4
4
  setup do
5
5
  @env = vagrant_env
6
-
7
- Net::SSH.stubs(:start)
8
6
  end
9
7
 
10
8
  context "finding a VM" do
@@ -177,6 +175,11 @@ class VMTest < Test::Unit::TestCase
177
175
  @vm.env.actions.expects(:run).with(:up, nil).once
178
176
  @vm.up
179
177
  end
178
+
179
+ should "forward options to the action sequence" do
180
+ @vm.env.actions.expects(:run).with(:up, :foo => :bar).once
181
+ @vm.up(:foo => :bar)
182
+ end
180
183
  end
181
184
 
182
185
  context "halting" do
@@ -236,14 +239,19 @@ class VMTest < Test::Unit::TestCase
236
239
  should "execute the resume action if saved" do
237
240
  @mock_vm.expects(:saved?).returns(true)
238
241
  @vm.expects(:resume).once
239
- @vm.env.actions.expects(:run).with(:start).never
242
+ @vm.env.actions.expects(:run).with(:start, nil).never
240
243
  @vm.start
241
244
  end
242
245
 
243
246
  should "execute the start action" do
244
- @vm.env.actions.expects(:run).with(:start).once
247
+ @vm.env.actions.expects(:run).with(:start, nil).once
245
248
  @vm.start
246
249
  end
250
+
251
+ should "forward options to the action sequence" do
252
+ @vm.env.actions.expects(:run).with(:start, :foo => :bar).once
253
+ @vm.start(:foo => :bar)
254
+ end
247
255
  end
248
256
  end
249
257
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrantup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 0.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mitchell Hashimoto
@@ -333,7 +333,6 @@ files:
333
333
  - lib/vagrant/util/template_renderer.rb
334
334
  - lib/vagrant/version.rb
335
335
  - lib/vagrant/vm.rb
336
- - templates/Vagrantfile.erb
337
336
  - templates/chef_server_client.erb
338
337
  - templates/chef_solo_solo.erb
339
338
  - templates/commands/init/Vagrantfile.erb
@@ -1,14 +0,0 @@
1
- Vagrant::Config.run do |config|
2
- # All Vagrant configuration is done here. For a detailed explanation
3
- # and listing of configuration options, please view the documentation
4
- # online.
5
-
6
- # Every Vagrant virtual environment requires a box to build off of.
7
- config.vm.box = "<%= default_box %>"
8
- <% if !default_box_url.nil? -%>
9
-
10
- # The url from where the 'config.vm.box' box will be fetched if it
11
- # doesn't already exist on the user's system
12
- config.vm.box_url = "<%= default_box_url %>"
13
- <% end -%>
14
- end