Show helpful error if importing VM fails

This commit is contained in:
Ewen Cheslack-Postava 2010-03-09 22:00:56 -08:00 committed by Mitchell Hashimoto
parent 47d46d4b12
commit 1bf70fd4c4
2 changed files with 11 additions and 3 deletions

View File

@ -8,6 +8,7 @@ module Vagrant
logger.info "Importing base VM (#{Vagrant::Env.box.ovf_file})..." logger.info "Importing base VM (#{Vagrant::Env.box.ovf_file})..."
# Use the first argument passed to the action # Use the first argument passed to the action
@runner.vm = VirtualBox::VM.import(Vagrant::Env.box.ovf_file) @runner.vm = VirtualBox::VM.import(Vagrant::Env.box.ovf_file)
raise ActionException.new("The VM import failed! Try running `VBoxManage import` on the box file manually for more verbose error output.") unless @runner.vm
end end
end end
end end

View File

@ -23,14 +23,21 @@ class ImportActionTest < Test::Unit::TestCase
end end
should "call import on VirtualBox::VM with the proper base" do should "call import on VirtualBox::VM with the proper base" do
VirtualBox::VM.expects(:import).once.with(@ovf_file) VirtualBox::VM.expects(:import).once.with(@ovf_file).returns("foo")
assert_nothing_raised { @import.execute! }
end
should "raise an exception if import is nil" do
@mock_vm.expects(:vm).returns(nil)
assert_raises(Vagrant::Actions::ActionException) {
@import.execute! @import.execute!
}
end end
should "set the resulting VM as the VM of the Vagrant VM object" do should "set the resulting VM as the VM of the Vagrant VM object" do
new_vm = mock("new_vm") new_vm = mock("new_vm")
@mock_vm.expects(:vm=).with(new_vm).once @mock_vm.expects(:vm=).with(new_vm).once
VirtualBox::VM.expects(:import).returns(new_vm) VirtualBox::VM.expects(:import).returns(new_vm).returns("foo")
@import.execute! @import.execute!
end end
end end