Don't try to recover machine without a uuid
This commit is contained in:
parent
e619a6a930
commit
5607428a66
@ -263,7 +263,7 @@ module Vagrant
|
||||
#
|
||||
# @return [Hash]
|
||||
def find_by_prefix(prefix)
|
||||
return nil if prefix.nil?
|
||||
return if !prefix
|
||||
@machines.each do |uuid, data|
|
||||
return data.merge("id" => uuid) if uuid.start_with?(prefix)
|
||||
end
|
||||
|
||||
@ -230,7 +230,8 @@ module Vagrant
|
||||
color_index = 0
|
||||
|
||||
machines.each do |machine|
|
||||
if machine.state && machine.state.id != :not_created && !@env.machine_index.include?(machine.index_uuid)
|
||||
if (machine.state && machine.state.id != :not_created &&
|
||||
!machine.index_uuid.nil? && !@env.machine_index.include?(machine.index_uuid))
|
||||
machine.recover_machine(machine.state.id)
|
||||
end
|
||||
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
require File.expand_path("../../../../base", __FILE__)
|
||||
require 'optparse'
|
||||
require 'vagrant/machine_index'
|
||||
|
||||
describe Vagrant::Plugin::V2::Command do
|
||||
include_context "unit"
|
||||
@ -151,6 +152,40 @@ describe Vagrant::Plugin::V2::Command do
|
||||
instance.with_target_vms("foo") { |vm| vms << vm }
|
||||
end
|
||||
|
||||
it "does not recover the vm if it has no uuid" do
|
||||
foo_vm = double("foo")
|
||||
provider = :foobarbaz
|
||||
state_id = :some_state
|
||||
allow(foo_vm).to receive(:name).and_return("foo")
|
||||
allow(foo_vm).to receive(:provider).and_return(provider)
|
||||
allow(foo_vm).to receive(:ui).and_return(Vagrant::UI::Silent.new)
|
||||
allow(foo_vm).to receive(:state).and_return(double("state", id: state_id))
|
||||
allow(foo_vm).to receive(:index_uuid).and_return(nil)
|
||||
allow(environment).to receive(:machine).with(:foo, provider).and_return(foo_vm)
|
||||
|
||||
expect(foo_vm).not_to receive(:recover_machine).with(state_id)
|
||||
vms = []
|
||||
instance.with_target_vms("foo", provider: provider) { |vm| vms << vm }
|
||||
expect(vms).to eq([foo_vm])
|
||||
end
|
||||
|
||||
it "recovers the vm" do
|
||||
foo_vm = double("foo")
|
||||
provider = :foobarbaz
|
||||
state_id = :some_state
|
||||
allow(foo_vm).to receive(:name).and_return("foo")
|
||||
allow(foo_vm).to receive(:provider).and_return(provider)
|
||||
allow(foo_vm).to receive(:ui).and_return(Vagrant::UI::Silent.new)
|
||||
allow(foo_vm).to receive(:state).and_return(double("state", id: state_id))
|
||||
allow(foo_vm).to receive(:index_uuid).and_return("someuuid")
|
||||
allow(environment).to receive(:machine).with(:foo, provider).and_return(foo_vm)
|
||||
|
||||
expect(foo_vm).to receive(:recover_machine).with(state_id)
|
||||
vms = []
|
||||
instance.with_target_vms("foo", provider: provider) { |vm| vms << vm }
|
||||
expect(vms).to eq([foo_vm])
|
||||
end
|
||||
|
||||
it "yields the given VM with proper provider if given" do
|
||||
foo_vm = double("foo")
|
||||
provider = :foobarbaz
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user