From e855ae99651b18c2edecd72c31f122e1062cf5b5 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 16 Feb 2010 15:48:03 -0800 Subject: [PATCH] vagrant-reload works --- lib/vagrant/actions/reload.rb | 8 ++++++++ lib/vagrant/commands.rb | 3 +-- test/vagrant/actions/reload_test.rb | 29 +++++++++++++++++++++++++++++ test/vagrant/commands_test.rb | 3 ++- 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/lib/vagrant/actions/reload.rb b/lib/vagrant/actions/reload.rb index 9bf0af5f5..62af500a8 100644 --- a/lib/vagrant/actions/reload.rb +++ b/lib/vagrant/actions/reload.rb @@ -1,6 +1,14 @@ module Vagrant module Actions class Reload < Base + def prepare + steps = [Stop, ForwardPorts, SharedFolders, Start] + steps << Provision if Vagrant.config.chef.enabled + + steps.each do |action_klass| + @vm.add_action(action_klass) + end + end end end end \ No newline at end of file diff --git a/lib/vagrant/commands.rb b/lib/vagrant/commands.rb index e28349520..325b2f20a 100644 --- a/lib/vagrant/commands.rb +++ b/lib/vagrant/commands.rb @@ -63,8 +63,7 @@ error def reload Env.load! Env.require_persisted_vm - - VM.execute!(Actions::Reload) + Env.persisted_vm.execute!(Actions::Reload) end # SSH into the vagrant instance. This will setup an SSH connection into diff --git a/test/vagrant/actions/reload_test.rb b/test/vagrant/actions/reload_test.rb index fcc23a053..ba06f412e 100644 --- a/test/vagrant/actions/reload_test.rb +++ b/test/vagrant/actions/reload_test.rb @@ -3,5 +3,34 @@ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper') class ReloadActionTest < Test::Unit::TestCase setup do @mock_vm, @vm, @action = mock_action(Vagrant::Actions::Reload) + mock_config + end + + context "sub-actions" do + setup do + @default_order = [Vagrant::Actions::Stop, Vagrant::Actions::ForwardPorts, Vagrant::Actions::SharedFolders, Vagrant::Actions::Start] + 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) + end + end + + should "do the proper actions by default" do + setup_action_expectations + @action.prepare + end + + should "add in the provisioning step if enabled" do + mock_config do |config| + config.chef.enabled = true + end + + @default_order.push(Vagrant::Actions::Provision) + setup_action_expectations + @action.prepare + end end end diff --git a/test/vagrant/commands_test.rb b/test/vagrant/commands_test.rb index 741a4fc6b..41c53ac83 100644 --- a/test/vagrant/commands_test.rb +++ b/test/vagrant/commands_test.rb @@ -5,6 +5,7 @@ class CommandsTest < Test::Unit::TestCase Vagrant::Env.stubs(:load!) @persisted_vm = mock("persisted_vm") + @persisted_vm.stubs(:execute!) Vagrant::Env.stubs(:persisted_vm).returns(@persisted_vm) end @@ -75,7 +76,7 @@ class CommandsTest < Test::Unit::TestCase end should "call the `reload` action on the VM" do - Vagrant::VM.expects(:execute!).with(Vagrant::Actions::Reload).once + @persisted_vm.expects(:execute!).with(Vagrant::Actions::Reload).once Vagrant::Commands.reload end end