Reload action only halts the machine if its running

This commit is contained in:
Mitchell Hashimoto 2010-03-05 18:03:08 -08:00
parent 06ff3a363c
commit 41b25e68ec
2 changed files with 13 additions and 4 deletions

View File

@ -3,7 +3,8 @@ module Vagrant
module VM module VM
class Reload < Base class Reload < Base
def prepare def prepare
steps = [Halt, ForwardPorts, SharedFolders, Start] steps = [ForwardPorts, SharedFolders, Start]
steps.unshift(Halt) if @runner.vm.running?
steps << Provision if Vagrant.config.chef.enabled steps << Provision if Vagrant.config.chef.enabled
steps.each do |action_klass| steps.each do |action_klass|

View File

@ -2,19 +2,20 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
class ReloadActionTest < Test::Unit::TestCase class ReloadActionTest < Test::Unit::TestCase
setup do setup do
@mock_vm, @vm, @action = mock_action(Vagrant::Actions::VM::Reload) @runner, @vm, @action = mock_action(Vagrant::Actions::VM::Reload)
mock_config mock_config
end end
context "sub-actions" do context "sub-actions" do
setup do setup do
@default_order = [Vagrant::Actions::VM::Halt, Vagrant::Actions::VM::ForwardPorts, Vagrant::Actions::VM::SharedFolders, Vagrant::Actions::VM::Start] @default_order = [Vagrant::Actions::VM::ForwardPorts, Vagrant::Actions::VM::SharedFolders, Vagrant::Actions::VM::Start]
@vm.stubs(:running?).returns(false)
end end
def setup_action_expectations def setup_action_expectations
default_seq = sequence("default_seq") default_seq = sequence("default_seq")
@default_order.each do |action| @default_order.each do |action|
@mock_vm.expects(:add_action).with(action).once.in_sequence(default_seq) @runner.expects(:add_action).with(action).once.in_sequence(default_seq)
end end
end end
@ -23,6 +24,13 @@ class ReloadActionTest < Test::Unit::TestCase
@action.prepare @action.prepare
end end
should "halt if the VM is running" do
@vm.expects(:running?).returns(true)
@default_order.unshift(Vagrant::Actions::VM::Halt)
setup_action_expectations
@action.prepare
end
should "add in the provisioning step if enabled" do should "add in the provisioning step if enabled" do
mock_config do |config| mock_config do |config|
config.chef.enabled = true config.chef.enabled = true