Merge pull request #6535 from mitchellh/f-prune-index
core: prune machine if non-existent CWD from index [GH-4742]
This commit is contained in:
commit
6602d06266
|
@ -78,7 +78,7 @@ module Vagrant
|
|||
@machines.delete(entry.id)
|
||||
unlocked_save
|
||||
|
||||
# Release acccess on this machine
|
||||
# Release access on this machine
|
||||
unlocked_release(entry.id)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -133,8 +133,17 @@ module Vagrant
|
|||
# machine in that environment. We silence warnings here because
|
||||
# Vagrantfiles often have constants, so people would otherwise
|
||||
# constantly (heh) get "already initialized constant" warnings.
|
||||
env = entry.vagrant_env(
|
||||
@env.home_path, ui_class: @env.ui_class)
|
||||
begin
|
||||
env = entry.vagrant_env(
|
||||
@env.home_path, ui_class: @env.ui_class)
|
||||
rescue Vagrant::Errors::EnvironmentNonExistentCWD
|
||||
# This means that this environment working directory
|
||||
# no longer exists, so delete this entry.
|
||||
entry = @env.machine_index.get(name.to_s)
|
||||
@env.machine_index.delete(entry) if entry
|
||||
raise
|
||||
end
|
||||
|
||||
next env.machine(entry.name.to_sym, entry.provider.to_sym)
|
||||
end
|
||||
|
||||
|
|
|
@ -263,6 +263,35 @@ describe Vagrant::Plugin::V2::Command do
|
|||
expect(results.length).to eq(1)
|
||||
expect(results[0].id).to eq(other_machine.id)
|
||||
end
|
||||
|
||||
it "should yield machines from another environment" do
|
||||
iso_env = isolated_environment
|
||||
iso_env.vagrantfile("")
|
||||
other_env = iso_env.create_vagrant_env(
|
||||
home_path: environment.home_path)
|
||||
other_machine = other_env.machine(
|
||||
other_env.machine_names[0], other_env.default_provider)
|
||||
|
||||
# Set an ID on it so that it is "created" in the index
|
||||
other_machine.id = "foo"
|
||||
|
||||
# Grab the uuid so we know what it is
|
||||
index_uuid = other_machine.index_uuid
|
||||
|
||||
# Remove the working directory
|
||||
FileUtils.rm_rf(iso_env.workdir)
|
||||
|
||||
# Make sure we don't have a root path, to test
|
||||
environment.stub(root_path: nil)
|
||||
|
||||
# Run the command
|
||||
expect {
|
||||
subject.with_target_vms(index_uuid) { |*args| }
|
||||
}.to raise_error(Vagrant::Errors::EnvironmentNonExistentCWD)
|
||||
|
||||
# Verify that it no longer exists in the index
|
||||
expect(other_env.machine_index.get(index_uuid)).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe "splitting the main and subcommand args" do
|
||||
|
|
Loading…
Reference in New Issue