Get rid of Environment#create_vm. VMs instances are now always available

This commit is contained in:
Mitchell Hashimoto 2010-05-08 20:31:12 -07:00
parent 14bb07e08f
commit c8e36274d6
4 changed files with 25 additions and 32 deletions

View File

@ -243,13 +243,6 @@ module Vagrant
# Methods to manage VM # Methods to manage VM
#--------------------------------------------------------------- #---------------------------------------------------------------
# Sets the VM to a new VM. This is not too useful but is used
# in {Command.up}. This will very likely be refactored at a later
# time.
def create_vm
@vm = VM.new(:env => self)
end
# Persists this environment's VM to the dotfile so it can be # Persists this environment's VM to the dotfile so it can be
# re-loaded at a later time. # re-loaded at a later time.
def persist_vm def persist_vm

View File

@ -11,7 +11,6 @@ module Vagrant
# a Vagrant::VM object or returns nil. # a Vagrant::VM object or returns nil.
def find(uuid, env=nil, vm_name=nil) def find(uuid, env=nil, vm_name=nil)
vm = VirtualBox::VM.find(uuid) vm = VirtualBox::VM.find(uuid)
return nil if vm.nil?
new(:vm => vm, :env => env, :vm_name => vm_name) new(:vm => vm, :env => env, :vm_name => vm_name)
end end
end end
@ -71,6 +70,14 @@ module Vagrant
@ssh ||= SSH.new(env) @ssh ||= SSH.new(env)
end end
# Returns a boolean true if the VM has been created, otherwise
# returns false.
#
# @return [Boolean]
def created?
!vm.nil?
end
def uuid def uuid
vm ? vm.uuid : nil vm ? vm.uuid : nil
end end

View File

@ -552,27 +552,6 @@ class EnvironmentTest < Test::Unit::TestCase
@env.stubs(:vm).returns(@vm) @env.stubs(:vm).returns(@vm)
end end
context "creating a new VM" do
should "create a new VM with the given environment" do
result = mock("result")
Vagrant::VM.expects(:new).with(:env => @env).once.returns(result)
@env.create_vm
assert_equal result, @env.vm
end
should "create a new VM" do
assert_nil @env.vm
@env.create_vm
assert !@env.vm.nil?
assert @env.vm.is_a?(Vagrant::VM)
end
should "return the new VM" do
result = @env.create_vm
assert result.is_a?(Vagrant::VM)
end
end
context "persisting the VM into a file" do context "persisting the VM into a file" do
setup do setup do
mock_vm mock_vm

View File

@ -20,12 +20,14 @@ class VMTest < Test::Unit::TestCase
end end
context "finding a VM" do context "finding a VM" do
should "return nil if the VM is not found" do should "return return an uncreated VM object if the VM is not found" do
VirtualBox::VM.expects(:find).returns(nil) VirtualBox::VM.expects(:find).returns(nil)
assert_nil Vagrant::VM.find("foo") result = Vagrant::VM.find("foo")
assert result.is_a?(Vagrant::VM)
assert !result.created?
end end
should "return a Vagrant::VM object for that VM otherwise" do should "return a Vagrant::VM object for that VM if found" do
VirtualBox::VM.expects(:find).with("foo").returns("bar") VirtualBox::VM.expects(:find).with("foo").returns("bar")
result = Vagrant::VM.find("foo", mock_environment) result = Vagrant::VM.find("foo", mock_environment)
assert result.is_a?(Vagrant::VM) assert result.is_a?(Vagrant::VM)
@ -39,6 +41,18 @@ class VMTest < Test::Unit::TestCase
@mock_vm.stubs(:uuid).returns("foo") @mock_vm.stubs(:uuid).returns("foo")
end end
context "checking if created" do
should "return true if the VM object is not nil" do
@vm.stubs(:vm).returns(:foo)
assert @vm.created?
end
should "return false if the VM object is nil" do
@vm.stubs(:vm).returns(nil)
assert !@vm.created?
end
end
context "accessing the SSH object" do context "accessing the SSH object" do
setup do setup do
# Reset this to nil to force the reload # Reset this to nil to force the reload