Support refreshing the machine cache
This commit is contained in:
parent
64042a5d35
commit
7eec127704
|
@ -217,14 +217,21 @@ module Vagrant
|
|||
# Vagrantfile).
|
||||
# @param [Symbol] provider The provider that this machine should be
|
||||
# backed by.
|
||||
# @param [Boolean] refresh If true, then if there is a cached version
|
||||
# it is reloaded.
|
||||
# @return [Machine]
|
||||
def machine(name, provider)
|
||||
def machine(name, provider, refresh=false)
|
||||
@logger.info("Getting machine: #{name} (#{provider})")
|
||||
|
||||
# Compose the cache key of the name and provider, and return from
|
||||
# the cache if we have that.
|
||||
cache_key = [name, provider]
|
||||
@machines ||= {}
|
||||
if refresh
|
||||
@logger.info("Refreshing machine (busting cache): #{name} (#{provider})")
|
||||
@machines.delete(cache_key)
|
||||
end
|
||||
|
||||
if @machines.has_key?(cache_key)
|
||||
@logger.info("Returning cached machine: #{name} (#{provider})")
|
||||
return @machines[cache_key]
|
||||
|
|
|
@ -25,7 +25,7 @@ module VagrantPlugins
|
|||
|
||||
# Reload the environment and set the VM to be the new loaded VM.
|
||||
env[:machine] = env[:machine].env.machine(
|
||||
env[:machine].name, env[:machine].provider_name)
|
||||
env[:machine].name, env[:machine].provider_name, true)
|
||||
end
|
||||
|
||||
@app.call(env)
|
||||
|
|
|
@ -454,6 +454,30 @@ VF
|
|||
machine.config.ssh.port.should == 100
|
||||
end
|
||||
|
||||
it "should reload the cache if refresh is set" do
|
||||
# Create a provider
|
||||
foo_provider = register_provider("foo")
|
||||
|
||||
# Create the configuration
|
||||
isolated_env = isolated_environment do |e|
|
||||
e.vagrantfile(<<-VF)
|
||||
Vagrant.configure("2") do |config|
|
||||
config.vm.box = "base"
|
||||
end
|
||||
VF
|
||||
|
||||
e.box2("base", :foo)
|
||||
end
|
||||
|
||||
env = isolated_env.create_vagrant_env
|
||||
vm1 = env.machine(:default, :foo)
|
||||
vm2 = env.machine(:default, :foo, true)
|
||||
vm3 = env.machine(:default, :foo)
|
||||
|
||||
vm1.should_not eql(vm2)
|
||||
vm2.should eql(vm3)
|
||||
end
|
||||
|
||||
it "should raise an error if the VM is not found" do
|
||||
expect { instance.machine("i-definitely-dont-exist", :virtualbox) }.
|
||||
to raise_error(Vagrant::Errors::MachineNotFound)
|
||||
|
|
Loading…
Reference in New Issue