vagrant-up and vagrant-halt no longer raise exceptions when the VM is not in the proper state.

This commit is contained in:
Mitchell Hashimoto 2010-03-02 22:19:13 -08:00
parent c7f040f14c
commit 8e7621061f
4 changed files with 26 additions and 0 deletions

View File

@ -3,6 +3,8 @@ module Vagrant
module VM
class Halt < Base
def execute!
raise ActionException.new("VM is not running! Nothing to shut down!") unless @runner.vm.running?
logger.info "Forcing shutdown of VM..."
@runner.vm.stop(true)
end

View File

@ -26,6 +26,8 @@ module Vagrant
end
def start
return if @vm.running?
actions = [Actions::VM::ForwardPorts, Actions::VM::SharedFolders, Actions::VM::Start]
actions.each do |action|
add_action(action)

View File

@ -7,9 +7,21 @@ class HaltActionTest < Test::Unit::TestCase
end
context "executing" do
setup do
@vm.stubs(:running?).returns(true)
end
should "force the VM to stop" do
@vm.expects(:stop).with(true).once
@action.execute!
end
should "raise an ActionException if VM is not running" do
@vm.stubs(:running?).returns(false)
@vm.expects(:stop).never
assert_raises(Vagrant::Actions::ActionException) {
@action.execute!
}
end
end
end

View File

@ -80,6 +80,16 @@ class VMTest < Test::Unit::TestCase
end
context "starting" do
setup do
@mock_vm.stubs(:running?).returns(false)
end
should "not do anything if the VM is already running" do
@mock_vm.stubs(:running?).returns(true)
@vm.expects(:execute!).never
@vm.start
end
should "add and execute the proper actions" do
actions = [Vagrant::Actions::VM::ForwardPorts, Vagrant::Actions::VM::SharedFolders, Vagrant::Actions::VM::Start]