core: only delete state if not created on initialize only
/cc @sethvargo
This commit is contained in:
parent
5b1211fc63
commit
f8a2322459
|
@ -135,6 +135,12 @@ module Vagrant
|
||||||
@logger.debug("Eager loading WinRM communicator to avoid GH-3390")
|
@logger.debug("Eager loading WinRM communicator to avoid GH-3390")
|
||||||
communicate
|
communicate
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# If the ID is the special not created ID, then set our ID to
|
||||||
|
# nil so that we destroy all our data.
|
||||||
|
if state.id == MachineState::NOT_CREATED_ID
|
||||||
|
self.id = nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# This calls an action on the provider. The provider may or may not
|
# This calls an action on the provider. The provider may or may not
|
||||||
|
@ -472,12 +478,6 @@ module Vagrant
|
||||||
result = @provider.state
|
result = @provider.state
|
||||||
raise Errors::MachineStateInvalid if !result.is_a?(MachineState)
|
raise Errors::MachineStateInvalid if !result.is_a?(MachineState)
|
||||||
|
|
||||||
# If the ID is the special not created ID, then set our ID to
|
|
||||||
# nil so that we destroy all our data.
|
|
||||||
if result.id == MachineState::NOT_CREATED_ID
|
|
||||||
self.id = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
# Update our state cache if we have a UUID and an entry in the
|
# Update our state cache if we have a UUID and an entry in the
|
||||||
# master index.
|
# master index.
|
||||||
uuid = index_uuid
|
uuid = index_uuid
|
||||||
|
|
|
@ -22,8 +22,13 @@ module VagrantTests
|
||||||
end
|
end
|
||||||
|
|
||||||
def state
|
def state
|
||||||
state_id = :running
|
if !state_file.file?
|
||||||
state_id = state_file.read.to_sym if state_file.file?
|
new_state = @machine.id
|
||||||
|
new_state = Vagrant::MachineState::NOT_CREATED_ID if !new_state
|
||||||
|
self.state = new_state
|
||||||
|
end
|
||||||
|
|
||||||
|
state_id = state_file.read.to_sym
|
||||||
Vagrant::MachineState.new(state_id, state_id.to_s, state_id.to_s)
|
Vagrant::MachineState.new(state_id, state_id.to_s, state_id.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -253,7 +253,7 @@ describe Vagrant::Environment do
|
||||||
describe "#machine" do
|
describe "#machine" do
|
||||||
# A helper to register a provider for use in tests.
|
# A helper to register a provider for use in tests.
|
||||||
def register_provider(name, config_class=nil, options=nil)
|
def register_provider(name, config_class=nil, options=nil)
|
||||||
provider_cls = Class.new(Vagrant.plugin("2", :provider))
|
provider_cls = Class.new(VagrantTests::DummyProvider)
|
||||||
|
|
||||||
register_plugin("2") do |p|
|
register_plugin("2") do |p|
|
||||||
p.provider(name, options) { provider_cls }
|
p.provider(name, options) { provider_cls }
|
||||||
|
|
|
@ -7,11 +7,7 @@ describe Vagrant::Machine do
|
||||||
include_context "unit"
|
include_context "unit"
|
||||||
|
|
||||||
let(:name) { "foo" }
|
let(:name) { "foo" }
|
||||||
let(:provider) do
|
let(:provider) { new_provider_mock }
|
||||||
double("provider").tap do |obj|
|
|
||||||
obj.stub(_initialize: nil)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
let(:provider_cls) do
|
let(:provider_cls) do
|
||||||
obj = double("provider_cls")
|
obj = double("provider_cls")
|
||||||
obj.stub(new: provider)
|
obj.stub(new: provider)
|
||||||
|
@ -46,6 +42,15 @@ describe Vagrant::Machine do
|
||||||
|
|
||||||
subject { instance }
|
subject { instance }
|
||||||
|
|
||||||
|
def new_provider_mock
|
||||||
|
double("provider").tap do |obj|
|
||||||
|
obj.stub(_initialize: nil)
|
||||||
|
obj.stub(machine_id_changed: nil)
|
||||||
|
allow(obj).to receive(:state).and_return(Vagrant::MachineState.new(
|
||||||
|
:created, "", ""))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Returns a new instance with the test data
|
# Returns a new instance with the test data
|
||||||
def new_instance
|
def new_instance
|
||||||
described_class.new(name, provider_name, provider_cls, provider_config,
|
described_class.new(name, provider_name, provider_cls, provider_config,
|
||||||
|
@ -54,6 +59,17 @@ describe Vagrant::Machine do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "initialization" do
|
describe "initialization" do
|
||||||
|
it "should set the ID to nil if the state is not created" do
|
||||||
|
subject.id = "foo"
|
||||||
|
|
||||||
|
allow(provider).to receive(:state).and_return(Vagrant::MachineState.new(
|
||||||
|
Vagrant::MachineState::NOT_CREATED_ID, "short", "long"))
|
||||||
|
|
||||||
|
subject = new_instance
|
||||||
|
expect(subject.state.id).to eq(Vagrant::MachineState::NOT_CREATED_ID)
|
||||||
|
expect(subject.id).to be_nil
|
||||||
|
end
|
||||||
|
|
||||||
describe "communicator loading" do
|
describe "communicator loading" do
|
||||||
it "doesn't eager load SSH" do
|
it "doesn't eager load SSH" do
|
||||||
config.vm.communicator = :ssh
|
config.vm.communicator = :ssh
|
||||||
|
@ -86,8 +102,7 @@ describe Vagrant::Machine do
|
||||||
received_machine = nil
|
received_machine = nil
|
||||||
|
|
||||||
if !instance
|
if !instance
|
||||||
instance = double("instance")
|
instance = new_provider_mock
|
||||||
instance.stub(_initialize: nil)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
provider_cls = double("provider_cls")
|
provider_cls = double("provider_cls")
|
||||||
|
@ -166,7 +181,7 @@ describe Vagrant::Machine do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should initialize the capabilities" do
|
it "should initialize the capabilities" do
|
||||||
instance = double("instance")
|
instance = new_provider_mock
|
||||||
expect(instance).to receive(:_initialize).with { |p, m|
|
expect(instance).to receive(:_initialize).with { |p, m|
|
||||||
expect(p).to eq(provider_name)
|
expect(p).to eq(provider_name)
|
||||||
expect(m.name).to eq(name)
|
expect(m.name).to eq(name)
|
||||||
|
@ -410,6 +425,10 @@ describe Vagrant::Machine do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "is set one when setting an ID" do
|
it "is set one when setting an ID" do
|
||||||
|
# Stub the message we want
|
||||||
|
allow(provider).to receive(:state).and_return(Vagrant::MachineState.new(
|
||||||
|
:preparing, "preparing", "preparing"))
|
||||||
|
|
||||||
# Setup the box information
|
# Setup the box information
|
||||||
box = double("box")
|
box = double("box")
|
||||||
box.stub(name: "foo")
|
box.stub(name: "foo")
|
||||||
|
@ -657,7 +676,7 @@ describe Vagrant::Machine do
|
||||||
it "should query state from the provider" do
|
it "should query state from the provider" do
|
||||||
state = Vagrant::MachineState.new(:id, "short", "long")
|
state = Vagrant::MachineState.new(:id, "short", "long")
|
||||||
|
|
||||||
expect(provider).to receive(:state).and_return(state)
|
allow(provider).to receive(:state).and_return(state)
|
||||||
expect(instance.state.id).to eq(:id)
|
expect(instance.state.id).to eq(:id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -681,18 +700,6 @@ describe Vagrant::Machine do
|
||||||
expect(entry.state).to eq("short")
|
expect(entry.state).to eq("short")
|
||||||
env.machine_index.release(entry)
|
env.machine_index.release(entry)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should set the ID to nil if the state is not created" do
|
|
||||||
state = Vagrant::MachineState.new(
|
|
||||||
Vagrant::MachineState::NOT_CREATED_ID, "short", "long")
|
|
||||||
|
|
||||||
allow(provider).to receive(:machine_id_changed)
|
|
||||||
subject.id = "foo"
|
|
||||||
|
|
||||||
expect(provider).to receive(:state).and_return(state)
|
|
||||||
expect(subject.state.id).to eq(Vagrant::MachineState::NOT_CREATED_ID)
|
|
||||||
expect(subject.id).to be_nil
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#with_ui" do
|
describe "#with_ui" do
|
||||||
|
|
|
@ -26,7 +26,7 @@ describe Vagrant::Vagrantfile do
|
||||||
|
|
||||||
# A helper to register a provider for use in tests.
|
# A helper to register a provider for use in tests.
|
||||||
def register_provider(name, config_class=nil, options=nil)
|
def register_provider(name, config_class=nil, options=nil)
|
||||||
provider_cls = Class.new(Vagrant.plugin("2", :provider)) do
|
provider_cls = Class.new(VagrantTests::DummyProvider) do
|
||||||
if options && options[:unusable]
|
if options && options[:unusable]
|
||||||
def self.usable?(raise_error=false)
|
def self.usable?(raise_error=false)
|
||||||
raise Vagrant::Errors::VagrantError if raise_error
|
raise Vagrant::Errors::VagrantError if raise_error
|
||||||
|
|
Loading…
Reference in New Issue