From 41b25e68ec6801d45abdb93a5347c0e05f2776f0 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 5 Mar 2010 18:03:08 -0800 Subject: [PATCH] Reload action only halts the machine if its running --- lib/vagrant/actions/vm/reload.rb | 3 ++- test/vagrant/actions/vm/reload_test.rb | 14 +++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/vagrant/actions/vm/reload.rb b/lib/vagrant/actions/vm/reload.rb index 12e2d22e5..bb6eaa356 100644 --- a/lib/vagrant/actions/vm/reload.rb +++ b/lib/vagrant/actions/vm/reload.rb @@ -3,7 +3,8 @@ module Vagrant module VM class Reload < Base 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.each do |action_klass| diff --git a/test/vagrant/actions/vm/reload_test.rb b/test/vagrant/actions/vm/reload_test.rb index 568ea7e41..b00ecd7bb 100644 --- a/test/vagrant/actions/vm/reload_test.rb +++ b/test/vagrant/actions/vm/reload_test.rb @@ -2,19 +2,20 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper') class ReloadActionTest < Test::Unit::TestCase setup do - @mock_vm, @vm, @action = mock_action(Vagrant::Actions::VM::Reload) + @runner, @vm, @action = mock_action(Vagrant::Actions::VM::Reload) mock_config end context "sub-actions" 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 def setup_action_expectations default_seq = sequence("default_seq") @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 @@ -23,6 +24,13 @@ class ReloadActionTest < Test::Unit::TestCase @action.prepare 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 mock_config do |config| config.chef.enabled = true