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
|
||||
|
||||
# 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)
|
||||
end
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ module Vagrant
|
|||
def call(env)
|
||||
@app.call(env)
|
||||
|
||||
if !env.error? && provisioning_enabled?
|
||||
if provisioning_enabled?
|
||||
@env.ui.info "vagrant.actions.vm.provision.beginning"
|
||||
@provisioner.provision!
|
||||
end
|
||||
|
@ -27,7 +27,7 @@ module Vagrant
|
|||
|
||||
if provisioner.is_a?(Class)
|
||||
@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)
|
||||
# We have a few hard coded provisioners for built-ins
|
||||
mapping = {
|
||||
|
@ -36,7 +36,7 @@ module Vagrant
|
|||
}
|
||||
|
||||
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)
|
||||
end
|
||||
|
||||
|
|
|
@ -16,14 +16,10 @@ module Vagrant
|
|||
|
||||
@app.call(env)
|
||||
|
||||
if !env.error?
|
||||
catch_action_exception(env) do
|
||||
# Only mount and setup shared folders in the absense of an
|
||||
# error
|
||||
mount_shared_folders
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# This method returns an actual list of VirtualBox shared
|
||||
# folders to create and their proper path.
|
||||
|
|
|
@ -149,6 +149,21 @@ module Vagrant
|
|||
error_key(:requires_directory, "vagrant.actions.general.package")
|
||||
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
|
||||
status_code(11)
|
||||
error_key(:ssh_authentication_failed)
|
||||
|
|
|
@ -216,10 +216,24 @@ en:
|
|||
exporting: Exporting NFS shared folders...
|
||||
mounting: Mounting NFS shared folders...
|
||||
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:
|
||||
beginning: Beginning provisioning process...
|
||||
enabled: Provisioning enabled with %{provisioner}...
|
||||
beginning: "Beginning provisioning process..."
|
||||
enabled: "Provisioning enabled with %{provisioner}..."
|
||||
invalid_class: "Provisioners must be an instance of Vagrant::Provisioners::Base"
|
||||
unknown_type: "Unknown provisioner type: %{provisioner}"
|
||||
resume:
|
||||
resuming: Resuming suspended VM...
|
||||
share_folders:
|
||||
|
|
|
@ -52,28 +52,12 @@
|
|||
vagrant box add name uri
|
||||
vagrant box remove name
|
||||
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: |-
|
||||
The given box does not exist on the file system:
|
||||
|
||||
<%= source_url %>
|
||||
:package_requires_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: |-
|
||||
The following SSH command responded with a non-zero exit status.
|
||||
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
|
||||
File.expects(:file?).with(@env.env.dotfile_path).returns(false)
|
||||
assert_raises(Vagrant::Errors::PersistDotfileExists) {
|
||||
@klass.new(@app, @env)
|
||||
assert @env.error?
|
||||
assert_equal :dotfile_error, @env.error.first
|
||||
}
|
||||
end
|
||||
|
||||
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
|
||||
@prov.expects(:is_a?).with(Vagrant::Provisioners::Base).returns(false)
|
||||
|
||||
assert_raises(Vagrant::Errors::ProvisionInvalidClass) {
|
||||
@instance.load_provisioner
|
||||
assert @env.error?
|
||||
assert_equal :provisioner_invalid_class, @env.error.first
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -81,11 +82,12 @@ class ProvisionVMActionTest < Test::Unit::TestCase
|
|||
assert_equal instance, @instance.load_provisioner
|
||||
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
|
||||
|
||||
assert_raises(Vagrant::Errors::ProvisionUnknownType) {
|
||||
@instance.load_provisioner
|
||||
assert @env.error?
|
||||
assert_equal :provisioner_unknown_type, @env.error.first
|
||||
}
|
||||
end
|
||||
|
||||
should "set :chef_solo to the ChefSolo provisioner" do
|
||||
|
@ -120,15 +122,6 @@ class ProvisionVMActionTest < Test::Unit::TestCase
|
|||
|
||||
@instance.call(@env)
|
||||
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
|
||||
|
|
|
@ -44,17 +44,6 @@ class ShareFoldersVMActionTest < Test::Unit::TestCase
|
|||
|
||||
@instance.call(@env)
|
||||
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
|
||||
|
||||
context "collecting shared folders" do
|
||||
|
|
Loading…
Reference in New Issue