Finish replacement of "env.error!" with exceptions in VM actions
This commit is contained in:
parent
b72cf4c57c
commit
39663f6f11
|
@ -6,7 +6,7 @@ module Vagrant
|
||||||
@app = app
|
@app = app
|
||||||
|
|
||||||
# Error the environment if the dotfile is not valid
|
# Error the environment if the dotfile is not valid
|
||||||
env.error!(:dotfile_error, :env => env.env) if File.exist?(env.env.dotfile_path) &&
|
raise Errors::PersistDotfileExists.new(:dotfile_path => env.env.dotfile_path) if File.exist?(env.env.dotfile_path) &&
|
||||||
!File.file?(env.env.dotfile_path)
|
!File.file?(env.env.dotfile_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ module Vagrant
|
||||||
def call(env)
|
def call(env)
|
||||||
@app.call(env)
|
@app.call(env)
|
||||||
|
|
||||||
if !env.error? && provisioning_enabled?
|
if provisioning_enabled?
|
||||||
@env.ui.info "vagrant.actions.vm.provision.beginning"
|
@env.ui.info "vagrant.actions.vm.provision.beginning"
|
||||||
@provisioner.provision!
|
@provisioner.provision!
|
||||||
end
|
end
|
||||||
|
@ -27,7 +27,7 @@ module Vagrant
|
||||||
|
|
||||||
if provisioner.is_a?(Class)
|
if provisioner.is_a?(Class)
|
||||||
@provisioner = provisioner.new(@env)
|
@provisioner = provisioner.new(@env)
|
||||||
return @env.error!(:provisioner_invalid_class) unless @provisioner.is_a?(Provisioners::Base)
|
raise Errors::ProvisionInvalidClass.new if !@provisioner.is_a?(Provisioners::Base)
|
||||||
elsif provisioner.is_a?(Symbol)
|
elsif provisioner.is_a?(Symbol)
|
||||||
# We have a few hard coded provisioners for built-ins
|
# We have a few hard coded provisioners for built-ins
|
||||||
mapping = {
|
mapping = {
|
||||||
|
@ -36,7 +36,7 @@ module Vagrant
|
||||||
}
|
}
|
||||||
|
|
||||||
provisioner_klass = mapping[provisioner]
|
provisioner_klass = mapping[provisioner]
|
||||||
return @env.error!(:provisioner_unknown_type, :provisioner => provisioner.to_s) if provisioner_klass.nil?
|
raise Errors::ProvisionUnknownType.new(:provisioner => provisioner.to_s) if provisioner_klass.nil?
|
||||||
@provisioner = provisioner_klass.new(@env)
|
@provisioner = provisioner_klass.new(@env)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -16,14 +16,10 @@ module Vagrant
|
||||||
|
|
||||||
@app.call(env)
|
@app.call(env)
|
||||||
|
|
||||||
if !env.error?
|
|
||||||
catch_action_exception(env) do
|
catch_action_exception(env) do
|
||||||
# Only mount and setup shared folders in the absense of an
|
|
||||||
# error
|
|
||||||
mount_shared_folders
|
mount_shared_folders
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
# This method returns an actual list of VirtualBox shared
|
# This method returns an actual list of VirtualBox shared
|
||||||
# folders to create and their proper path.
|
# folders to create and their proper path.
|
||||||
|
|
|
@ -149,6 +149,21 @@ module Vagrant
|
||||||
error_key(:requires_directory, "vagrant.actions.general.package")
|
error_key(:requires_directory, "vagrant.actions.general.package")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class PersistDotfileExists < VagrantError
|
||||||
|
status_code(34)
|
||||||
|
error_key(:dotfile_error, "vagrant.actions.vm.persist")
|
||||||
|
end
|
||||||
|
|
||||||
|
class ProvisionInvalidClass < VagrantError
|
||||||
|
status_code(35)
|
||||||
|
error_key(:invalid_class, "vagrant.actions.vm.provision")
|
||||||
|
end
|
||||||
|
|
||||||
|
class ProvisionUnknownType < VagrantError
|
||||||
|
status_code(36)
|
||||||
|
error_key(:unknown_type, "vagrant.actions.vm.provision")
|
||||||
|
end
|
||||||
|
|
||||||
class SSHAuthenticationFailed < VagrantError
|
class SSHAuthenticationFailed < VagrantError
|
||||||
status_code(11)
|
status_code(11)
|
||||||
error_key(:ssh_authentication_failed)
|
error_key(:ssh_authentication_failed)
|
||||||
|
|
|
@ -216,10 +216,24 @@ en:
|
||||||
exporting: Exporting NFS shared folders...
|
exporting: Exporting NFS shared folders...
|
||||||
mounting: Mounting NFS shared folders...
|
mounting: Mounting NFS shared folders...
|
||||||
persist:
|
persist:
|
||||||
persisting: Persisting the VM UUID (%{uuid})...
|
dotfile_error: |-
|
||||||
|
The dotfile which Vagrant uses to store the UUID of the project's
|
||||||
|
virtual machine already exists and is not a file! The dotfile is
|
||||||
|
currently configured to be '%{dotfile_path}'
|
||||||
|
|
||||||
|
To change this value, please see `config.vagrant.dotfile_name`
|
||||||
|
|
||||||
|
Are you trying to use Vagrant from your home directory? This is the
|
||||||
|
leading cause of this error message. To resolve this, simply use a
|
||||||
|
different directory. Or, if you really want to run Vagrant from your
|
||||||
|
home directory, modify the `config.vagrant.dotfile_name` configuration
|
||||||
|
key.
|
||||||
|
persisting: "Persisting the VM UUID (%{uuid})..."
|
||||||
provision:
|
provision:
|
||||||
beginning: Beginning provisioning process...
|
beginning: "Beginning provisioning process..."
|
||||||
enabled: Provisioning enabled with %{provisioner}...
|
enabled: "Provisioning enabled with %{provisioner}..."
|
||||||
|
invalid_class: "Provisioners must be an instance of Vagrant::Provisioners::Base"
|
||||||
|
unknown_type: "Unknown provisioner type: %{provisioner}"
|
||||||
resume:
|
resume:
|
||||||
resuming: Resuming suspended VM...
|
resuming: Resuming suspended VM...
|
||||||
share_folders:
|
share_folders:
|
||||||
|
|
|
@ -52,28 +52,12 @@
|
||||||
vagrant box add name uri
|
vagrant box add name uri
|
||||||
vagrant box remove name
|
vagrant box remove name
|
||||||
vagrant box list
|
vagrant box list
|
||||||
:dotfile_error: |-
|
|
||||||
The dotfile which Vagrant uses to store the UUID of the project's
|
|
||||||
virtual machine already exists and is not a file! The dotfile is
|
|
||||||
currently configured to be `<%= env.dotfile_path %>`
|
|
||||||
|
|
||||||
To change this value, please see `config.vagrant.dotfile_name`
|
|
||||||
|
|
||||||
Are you trying to use Vagrant from your home directory? This is the
|
|
||||||
leading cause of this error message. To resolve this, simply use a
|
|
||||||
different directory. Or, if you really want to run Vagrant from your
|
|
||||||
home directory, modify the `config.vagrant.dotfile_name` configuration
|
|
||||||
key.
|
|
||||||
:downloader_file_doesnt_exist: |-
|
:downloader_file_doesnt_exist: |-
|
||||||
The given box does not exist on the file system:
|
The given box does not exist on the file system:
|
||||||
|
|
||||||
<%= source_url %>
|
<%= source_url %>
|
||||||
:package_requires_export: |-
|
:package_requires_export: |-
|
||||||
Package must be used in conjunction with export.
|
Package must be used in conjunction with export.
|
||||||
:provisioner_invalid_class: |-
|
|
||||||
Provisioners must be an instance of Vagrant::Provisioners::Base
|
|
||||||
:provisioner_unknown_type: |-
|
|
||||||
Unknown provisioner type: <%= provisioner %>
|
|
||||||
:ssh_bad_exit_status: |-
|
:ssh_bad_exit_status: |-
|
||||||
The following SSH command responded with a non-zero exit status.
|
The following SSH command responded with a non-zero exit status.
|
||||||
Vagrant assumes that this means the command failed!
|
Vagrant assumes that this means the command failed!
|
||||||
|
|
|
@ -20,9 +20,9 @@ class PersistVMActionTest < Test::Unit::TestCase
|
||||||
|
|
||||||
should "error environment if dotfile exists but is not a file" do
|
should "error environment if dotfile exists but is not a file" do
|
||||||
File.expects(:file?).with(@env.env.dotfile_path).returns(false)
|
File.expects(:file?).with(@env.env.dotfile_path).returns(false)
|
||||||
|
assert_raises(Vagrant::Errors::PersistDotfileExists) {
|
||||||
@klass.new(@app, @env)
|
@klass.new(@app, @env)
|
||||||
assert @env.error?
|
}
|
||||||
assert_equal :dotfile_error, @env.error.first
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "initialize properly if dotfiles doesn't exist" do
|
should "initialize properly if dotfiles doesn't exist" do
|
||||||
|
|
|
@ -65,9 +65,10 @@ class ProvisionVMActionTest < Test::Unit::TestCase
|
||||||
|
|
||||||
should "error environment if the class is not a subclass of the provisioner base" do
|
should "error environment if the class is not a subclass of the provisioner base" do
|
||||||
@prov.expects(:is_a?).with(Vagrant::Provisioners::Base).returns(false)
|
@prov.expects(:is_a?).with(Vagrant::Provisioners::Base).returns(false)
|
||||||
|
|
||||||
|
assert_raises(Vagrant::Errors::ProvisionInvalidClass) {
|
||||||
@instance.load_provisioner
|
@instance.load_provisioner
|
||||||
assert @env.error?
|
}
|
||||||
assert_equal :provisioner_invalid_class, @env.error.first
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -81,11 +82,12 @@ class ProvisionVMActionTest < Test::Unit::TestCase
|
||||||
assert_equal instance, @instance.load_provisioner
|
assert_equal instance, @instance.load_provisioner
|
||||||
end
|
end
|
||||||
|
|
||||||
should "raise an ActionException if its an unknown symbol" do
|
should "raise an error if its an unknown symbol" do
|
||||||
@env["config"].vm.provisioner = :this_will_never_exist
|
@env["config"].vm.provisioner = :this_will_never_exist
|
||||||
|
|
||||||
|
assert_raises(Vagrant::Errors::ProvisionUnknownType) {
|
||||||
@instance.load_provisioner
|
@instance.load_provisioner
|
||||||
assert @env.error?
|
}
|
||||||
assert_equal :provisioner_unknown_type, @env.error.first
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "set :chef_solo to the ChefSolo provisioner" do
|
should "set :chef_solo to the ChefSolo provisioner" do
|
||||||
|
@ -120,15 +122,6 @@ class ProvisionVMActionTest < Test::Unit::TestCase
|
||||||
|
|
||||||
@instance.call(@env)
|
@instance.call(@env)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "not provision if erroneous environment" do
|
|
||||||
@env.error!(:foo)
|
|
||||||
|
|
||||||
@prov.expects(:provision!).never
|
|
||||||
@app.expects(:call).with(@env).once
|
|
||||||
|
|
||||||
@instance.call(@env)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -44,17 +44,6 @@ class ShareFoldersVMActionTest < Test::Unit::TestCase
|
||||||
|
|
||||||
@instance.call(@env)
|
@instance.call(@env)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "run only the metadata actions if erroneous environment" do
|
|
||||||
@env.error!(:foo)
|
|
||||||
|
|
||||||
before_seq = sequence("before")
|
|
||||||
@instance.expects(:create_metadata).once.in_sequence(before_seq)
|
|
||||||
@app.expects(:call).with(@env).in_sequence(before_seq)
|
|
||||||
@instance.expects(:mount_shared_folders).never
|
|
||||||
|
|
||||||
@instance.call(@env)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "collecting shared folders" do
|
context "collecting shared folders" do
|
||||||
|
|
Loading…
Reference in New Issue