`vagrant reload` works with multi-vm

This commit is contained in:
Mitchell Hashimoto 2010-05-17 10:41:19 -07:00
parent 38d485c29b
commit 586a56b5b5
4 changed files with 83 additions and 14 deletions

View File

@ -10,8 +10,33 @@ module Vagrant
description "Reload the vagrant environment"
def execute(args=[])
env.require_persisted_vm
env.vm.execute!(Actions::VM::Reload)
args = parse_options(args)
if args[0]
reload_single(args[0])
else
reload_all
end
end
def reload_single(name)
vm = env.vms[name.to_sym]
if vm.nil?
error_and_exit(:unknown_vm, :vm => name)
return # for tests
end
if vm.created?
vm.reload
else
logger.info "VM '#{name}' not created. Ignoring."
end
end
def reload_all
env.vms.keys.each do |name|
reload_single(name)
end
end
def options_spec(opts)
@ -19,4 +44,4 @@ module Vagrant
end
end
end
end
end

View File

@ -113,6 +113,10 @@ module Vagrant
execute!(Actions::VM::Halt, force)
end
def reload
execute!(Actions::VM::Reload)
end
def destroy
execute!(Actions::VM::Down)
end

View File

@ -4,25 +4,58 @@ class CommandsReloadTest < Test::Unit::TestCase
setup do
@klass = Vagrant::Commands::Reload
@persisted_vm = mock("persisted_vm")
@persisted_vm.stubs(:execute!)
@env = mock_environment
@env.stubs(:require_persisted_vm)
@env.stubs(:vm).returns(@persisted_vm)
@instance = @klass.new(@env)
end
context "executing" do
should "require a persisted VM" do
@env.expects(:require_persisted_vm).once
should "call on all if no name is given" do
@instance.expects(:reload_all).once
@instance.execute
end
should "call the `reload` action on the VM" do
@persisted_vm.expects(:execute!).with(Vagrant::Actions::VM::Reload).once
@instance.execute
should "call on single if a name is given" do
@instance.expects(:reload_single).with("foo").once
@instance.execute(["foo"])
end
end
context "reloading all" do
should "reload each VM" do
vms = { :foo => nil, :bar => nil, :baz => nil }
@env.stubs(:vms).returns(vms)
vms.each do |name, value|
@instance.expects(:reload_single).with(name).once
end
@instance.reload_all
end
end
context "reloading a single VM" do
setup do
@foo_vm = mock("vm")
vms = { :foo => @foo_vm }
@env.stubs(:vms).returns(vms)
end
should "error and exit if the VM doesn't exist" do
@env.stubs(:vms).returns({})
@instance.expects(:error_and_exit).with(:unknown_vm, :vm => :foo).once
@instance.reload_single(:foo)
end
should "reload if its created" do
@foo_vm.stubs(:created?).returns(true)
@foo_vm.expects(:reload).once
@instance.execute(["foo"])
end
should "do nothing if its not created" do
@foo_vm.stubs(:created?).returns(false)
@foo_vm.expects(:reload).never
@instance.reload_single(:foo)
end
end
end

View File

@ -180,6 +180,13 @@ class VMTest < Test::Unit::TestCase
end
end
context "reloading" do
should "execute the reload action" do
@vm.expects(:execute!).with(Vagrant::Actions::VM::Reload).once
@vm.reload
end
end
context "destroying" do
should "execute the down action" do
@vm.expects(:execute!).with(Vagrant::Actions::VM::Down).once