vagrant-up now uses pure actions rather than the hardcoded sequential instant methods. Provisioning not yet working, and moving hard drives not yet implemented.

This commit is contained in:
Mitchell Hashimoto 2010-02-14 23:12:36 -08:00
parent cb2f1ff402
commit 11f4876b9d
5 changed files with 20 additions and 28 deletions

View File

@ -5,7 +5,7 @@ module Vagrant
# Up is a "meta-action" so it really just queues up a bunch # Up is a "meta-action" so it really just queues up a bunch
# of other actions in its place: # of other actions in its place:
[Import, ForwardPorts, SharedFolders, Start].each do |action_klass| [Import, ForwardPorts, SharedFolders, Start].each do |action_klass|
@vm.actions << action_klass @vm.add_action(action_klass)
end end
# TODO: Move hard drive # TODO: Move hard drive

View File

@ -40,7 +40,7 @@ run `vagrant down` first.
error error
end end
VM.up VM.execute!(Actions::Up)
end end
# Tear down a vagrant instance. This not only shuts down the instance # Tear down a vagrant instance. This not only shuts down the instance

View File

@ -8,7 +8,7 @@ module Vagrant
# Executes a specific action # Executes a specific action
def execute!(action_klass) def execute!(action_klass)
vm = new vm = new
vm.actions << action_klass vm.add_action(action_klass)
vm.execute! vm.execute!
end end
@ -32,14 +32,11 @@ module Vagrant
@actions = [] @actions = []
end end
def execute! def add_action(action_klass)
# Initialize each action. Prepare is not done together with @actions << action_klass.new(self)
# this since initialization is a time which guarantees that end
# prepare has not been called for any other action yet.
@actions.collect! do |action_class|
action_class.new(self)
end
def execute!
# Call the prepare method on each once its # Call the prepare method on each once its
# initialized, then call the execute! method # initialized, then call the execute! method
[:prepare, :execute!].each do |method| [:prepare, :execute!].each do |method|

View File

@ -31,7 +31,7 @@ class CommandsTest < Test::Unit::TestCase
context "up" do context "up" do
setup do setup do
Vagrant::Env.stubs(:persisted_vm).returns(nil) Vagrant::Env.stubs(:persisted_vm).returns(nil)
Vagrant::VM.stubs(:up) Vagrant::VM.stubs(:execute!)
end end
should "require load the environment" do should "require load the environment" do
@ -46,8 +46,8 @@ class CommandsTest < Test::Unit::TestCase
Vagrant::Commands.up Vagrant::Commands.up
end end
should "call up on VM" do should "call the up action on VM" do
Vagrant::VM.expects(:up).once Vagrant::VM.expects(:execute!).with(Vagrant::Actions::Up).once
Vagrant::Commands.up Vagrant::Commands.up
end end
end end
@ -149,13 +149,13 @@ class CommandsTest < Test::Unit::TestCase
@persisted_vm.expects(:package).never @persisted_vm.expects(:package).never
Vagrant::Commands.package Vagrant::Commands.package
end end
should "package the vm with the default name and the current directory" do should "package the vm with the default name and the current directory" do
@persisted_vm.expects(:package).with(Vagrant.config[:package][:name], FileUtils.pwd).once @persisted_vm.expects(:package).with(Vagrant.config[:package][:name], FileUtils.pwd).once
Vagrant::Commands.package Vagrant::Commands.package
end end
should "package the vm with the specified name" do should "package the vm with the specified name" do
@persisted_vm.expects(:package).with('foo', FileUtils.pwd).once @persisted_vm.expects(:package).with('foo', FileUtils.pwd).once
Vagrant::Commands.package('foo') Vagrant::Commands.package('foo')
end end

View File

@ -58,12 +58,12 @@ class VMTest < Test::Unit::TestCase
assert @vm.actions.empty? assert @vm.actions.empty?
end end
should "be able to add actions" do should "initialize the action when added" do
assert_nothing_raised do action_klass = mock("action_class")
@vm.actions << "Foo" action_inst = mock("action_inst")
@vm.actions << "Bar" action_klass.expects(:new).once.returns(action_inst)
assert_equal 2, @vm.actions.length @vm.add_action(action_klass)
end assert_equal 1, @vm.actions.length
end end
should "run #prepare on all actions, then #execute!" do should "run #prepare on all actions, then #execute!" do
@ -71,11 +71,8 @@ class VMTest < Test::Unit::TestCase
actions = [] actions = []
5.times do |i| 5.times do |i|
action = mock("action#{i}") action = mock("action#{i}")
action_class = mock("action_class#{i}")
action_class.expects(:new).once.returns(action).in_sequence(action_seq) @vm.actions << action
@vm.actions << action_class
actions << action actions << action
end end
@ -90,11 +87,9 @@ class VMTest < Test::Unit::TestCase
should "run actions on class method execute!" do should "run actions on class method execute!" do
vm = mock("vm") vm = mock("vm")
actions = mock("actions")
execute_seq = sequence("execute_seq") execute_seq = sequence("execute_seq")
Vagrant::VM.expects(:new).returns(vm).in_sequence(execute_seq) Vagrant::VM.expects(:new).returns(vm).in_sequence(execute_seq)
vm.expects(:actions).returns(actions).in_sequence(execute_seq) vm.expects(:add_action).with("foo").in_sequence(execute_seq)
actions.expects(:<<).with("foo").once.in_sequence(execute_seq)
vm.expects(:execute!).once.in_sequence(execute_seq) vm.expects(:execute!).once.in_sequence(execute_seq)
Vagrant::VM.execute!("foo") Vagrant::VM.execute!("foo")