Halt checks if VM is running. No more error messages
This commit is contained in:
parent
77cca19b7e
commit
cfc87d4ce3
|
@ -7,13 +7,13 @@ module Vagrant
|
|||
end
|
||||
|
||||
def call(env)
|
||||
return env.error!(:vm_not_running) unless env["vm"].vm.running?
|
||||
if env["vm"].vm.running?
|
||||
env["vm"].system.halt if !env["force"]
|
||||
|
||||
env["vm"].system.halt if !env["force"]
|
||||
|
||||
if env["vm"].vm.state(true) != :powered_off
|
||||
env.logger.info "Forcing shutdown of VM..."
|
||||
env["vm"].vm.stop
|
||||
if env["vm"].vm.state(true) != :powered_off
|
||||
env.logger.info "Forcing shutdown of VM..."
|
||||
env["vm"].vm.stop
|
||||
end
|
||||
end
|
||||
|
||||
@app.call(env)
|
||||
|
|
|
@ -250,8 +250,6 @@
|
|||
Failed to connect to VM! Failed to boot?
|
||||
:vm_base_not_found: |-
|
||||
The specified base VM "<%= name %>" was not found.
|
||||
:vm_not_running: |-
|
||||
VM is not running! Nothing to shut down!
|
||||
:vm_not_running_for_suspend: |-
|
||||
The vagrant virtual environment you are trying to suspend must be running to be suspended.
|
||||
:vm_not_suspended: |-
|
||||
|
|
|
@ -26,6 +26,15 @@ class HaltVMActionTest < Test::Unit::TestCase
|
|||
@internal_vm.stubs(:state).returns(:powered_off)
|
||||
end
|
||||
|
||||
should "do nothing if VM not running" do
|
||||
@internal_vm.stubs(:running?).returns(false)
|
||||
@vm.system.expects(:halt).never
|
||||
@internal_vm.expects(:stop).never
|
||||
@app.expects(:call).once
|
||||
|
||||
@instance.call(@env)
|
||||
end
|
||||
|
||||
should "halt with the system and NOT force VM to stop if powered off" do
|
||||
@internal_vm.expects(:state).with(true).returns(:powered_off)
|
||||
@vm.system.expects(:halt).once
|
||||
|
@ -49,14 +58,5 @@ class HaltVMActionTest < Test::Unit::TestCase
|
|||
@vm.system.expects(:halt).never
|
||||
@instance.call(@env)
|
||||
end
|
||||
|
||||
should "raise an ActionException if VM is not running" do
|
||||
@internal_vm.stubs(:running?).returns(false)
|
||||
@internal_vm.expects(:stop).never
|
||||
@app.expects(:call).never
|
||||
@instance.call(@env)
|
||||
assert @env.error?
|
||||
assert_equal :vm_not_running, @env.error.first
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue