Only halt if created and running

This commit is contained in:
Mitchell Hashimoto 2010-09-12 16:29:35 -06:00
parent 4335adc8f4
commit e11d3bd4f7
2 changed files with 11 additions and 1 deletions

View File

@ -8,7 +8,7 @@ module Vagrant
end
def call(env)
if env["vm"].vm.running?
if env["vm"].created? && env["vm"].vm.running?
env["vm"].system.halt if !env["force"]
if env["vm"].vm.state(true) != :powered_off

View File

@ -26,6 +26,7 @@ class HaltVMActionTest < Test::Unit::TestCase
context "calling" do
setup do
@vm.stubs(:created?).returns(true)
@internal_vm.stubs(:running?).returns(true)
@vm.system.stubs(:halt)
@ -33,6 +34,15 @@ class HaltVMActionTest < Test::Unit::TestCase
@internal_vm.stubs(:state).returns(:powered_off)
end
should "do nothing if VM is not created" do
@internal_vm.stubs(:created?).returns(false)
@vm.system.expects(:halt).never
@internal_vm.expects(:stop).never
@app.expects(:call).once
@instance.call(@env)
end
should "do nothing if VM not running" do
@internal_vm.stubs(:running?).returns(false)
@vm.system.expects(:halt).never