core: if state ID is NOT_CREATED_ID, destroy machine state

This commit is contained in:
Mitchell Hashimoto 2014-05-05 21:44:34 -07:00
parent ff2f035f27
commit 5d94ab9e60
3 changed files with 24 additions and 0 deletions

View File

@ -421,6 +421,12 @@ module Vagrant
result = @provider.state
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
# master index.
uuid = index_uuid

View File

@ -14,6 +14,12 @@ module Vagrant
# The long description can span multiple lines describing what the
# state actually means.
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.
#
# @return [Symbol]

View File

@ -627,6 +627,18 @@ describe Vagrant::Machine do
expect(entry.state).to eq("short")
env.machine_index.release(entry)
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
describe "#with_ui" do