Environment attempts to upgrade box on config load.

If a V1 box is encountered when Vagrant loads the configuration, then it
will be upgraded on the fly.
This commit is contained in:
Mitchell Hashimoto 2012-07-09 19:46:22 -07:00
parent 7595f0078e
commit 623ecb3e3d
3 changed files with 34 additions and 5 deletions

View File

@ -72,13 +72,14 @@ module Vagrant
raise Errors::BoxUnpackageFailure raise Errors::BoxUnpackageFailure
end end
# Verify that the box we just added matches the provider # Get an instance of the box we just added before it is finalized
# we expected. # in the system so we can inspect and use its metadata.
box = Box.new(name, provider, Pathname.new(temp_dir)) box = Box.new(name, provider, Pathname.new(temp_dir))
# Verify that the provider matches. If not, then we error and never # Get the provider, since we'll need that to at the least add it
# move to the final location. # to the system or check that it matches what is given to us.
box_provider = box.metadata["provider"] box_provider = box.metadata["provider"]
if provider if provider
# Verify that the given provider matches what the box has. # Verify that the given provider matches what the box has.
if box_provider.to_sym != provider if box_provider.to_sym != provider

View File

@ -426,7 +426,16 @@ module Vagrant
# Second pass, with the box # Second pass, with the box
box = nil box = nil
box = boxes.find(config.vm.box, :virtualbox) if config.vm.box
begin
box = boxes.find(config.vm.box, :virtualbox) if config.vm.box
rescue Errors::BoxUpgradeRequired
# Upgrade the box if we must.
@logger.info("Upgrading box during config load: #{config.vm.box}")
boxes.upgrade(config.vm.box)
retry
end
inner_load[subvm, box] inner_load[subvm, box]
end end

View File

@ -183,6 +183,25 @@ VF
env.config.for_vm(:bar).ssh.port.should == 200 env.config.for_vm(:bar).ssh.port.should == 200
end end
it "should load a V1 vagrant box" do
environment = isolated_environment do |env|
env.vagrantfile(<<-VF)
Vagrant::Config.run do |config|
config.vm.box = "base"
end
VF
env.box("base", <<-VF)
Vagrant::Config.run do |config|
config.ssh.port = 100
end
VF
end
env = environment.create_vagrant_env
env.config.for_vm(:default).ssh.port.should == 100
end
it "should load box configuration" do it "should load box configuration" do
environment = isolated_environment do |env| environment = isolated_environment do |env|
env.vagrantfile(<<-VF) env.vagrantfile(<<-VF)