core: if state ID is NOT_CREATED_ID, destroy machine state
This commit is contained in:
parent
ff2f035f27
commit
5d94ab9e60
|
@ -421,6 +421,12 @@ 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
|
||||||
|
|
|
@ -14,6 +14,12 @@ module Vagrant
|
||||||
# The long description can span multiple lines describing what the
|
# The long description can span multiple lines describing what the
|
||||||
# state actually means.
|
# state actually means.
|
||||||
class MachineState
|
class MachineState
|
||||||
|
# This is a special ID that can be set for the state ID that
|
||||||
|
# tells Vagrant that the machine is not created. If this is the
|
||||||
|
# case, then Vagrant will set the ID to nil which will automatically
|
||||||
|
# clean out the machine data directory.
|
||||||
|
NOT_CREATED_ID = :not_created
|
||||||
|
|
||||||
# Unique ID for this state.
|
# Unique ID for this state.
|
||||||
#
|
#
|
||||||
# @return [Symbol]
|
# @return [Symbol]
|
||||||
|
|
|
@ -627,6 +627,18 @@ 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
|
||||||
|
|
Loading…
Reference in New Issue