Properly handle the case that VM doesn't exist for the VB driver.

This commit is contained in:
Mitchell Hashimoto 2012-08-14 20:27:28 -07:00
parent 0cc63c05e2
commit 85a499ffb8
2 changed files with 25 additions and 1 deletions

View File

@ -1,11 +1,24 @@
require "log4r"
module VagrantPlugins
module ProviderVirtualBox
class Provider < Vagrant.plugin("1", :provider)
attr_reader :driver
def initialize(machine)
@logger = Log4r::Logger.new("vagrant::provider::virtualbox")
@machine = machine
begin
@logger.debug("Instantiating the driver for machine ID: #{@machine.id.inspect}")
@driver = Driver::Meta.new(@machine.id)
rescue Driver::Meta::VMNotFound
# The virtual machine doesn't exist, so we probably have a stale
# ID. Just clear the id out of the machine and reload it.
@logger.debug("VM not found! Clearing saved machine ID and reloading.")
@machine.id = nil
retry
end
end
# @see Vagrant::Plugin::V1::Provider#action

View File

@ -283,6 +283,17 @@ describe Vagrant::Machine do
instance.id = "foo"
new_instance.id.should == "foo"
end
it "should delete the ID" do
instance.id = "foo"
second = new_instance
second.id.should == "foo"
second.id = nil
third = new_instance
third.id.should be_nil
end
end
describe "ssh info" do