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
# of other actions in its place:
[Import, ForwardPorts, SharedFolders, Start].each do |action_klass|
@vm.actions << action_klass
@vm.add_action(action_klass)
end
# TODO: Move hard drive

View File

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

View File

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

View File

@ -31,7 +31,7 @@ class CommandsTest < Test::Unit::TestCase
context "up" do
setup do
Vagrant::Env.stubs(:persisted_vm).returns(nil)
Vagrant::VM.stubs(:up)
Vagrant::VM.stubs(:execute!)
end
should "require load the environment" do
@ -46,8 +46,8 @@ class CommandsTest < Test::Unit::TestCase
Vagrant::Commands.up
end
should "call up on VM" do
Vagrant::VM.expects(:up).once
should "call the up action on VM" do
Vagrant::VM.expects(:execute!).with(Vagrant::Actions::Up).once
Vagrant::Commands.up
end
end
@ -149,13 +149,13 @@ class CommandsTest < Test::Unit::TestCase
@persisted_vm.expects(:package).never
Vagrant::Commands.package
end
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
Vagrant::Commands.package
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
Vagrant::Commands.package('foo')
end

View File

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