From 623ecb3e3d8c3dd341403b4beab4f7fe949dab0f Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 9 Jul 2012 19:46:22 -0700 Subject: [PATCH] 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. --- lib/vagrant/box_collection.rb | 9 +++++---- lib/vagrant/environment.rb | 11 ++++++++++- test/unit/vagrant/environment_test.rb | 19 +++++++++++++++++++ 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/lib/vagrant/box_collection.rb b/lib/vagrant/box_collection.rb index 4e4afceba..d90bf42f1 100644 --- a/lib/vagrant/box_collection.rb +++ b/lib/vagrant/box_collection.rb @@ -72,13 +72,14 @@ module Vagrant raise Errors::BoxUnpackageFailure end - # Verify that the box we just added matches the provider - # we expected. + # Get an instance of the box we just added before it is finalized + # in the system so we can inspect and use its metadata. box = Box.new(name, provider, Pathname.new(temp_dir)) - # Verify that the provider matches. If not, then we error and never - # move to the final location. + # Get the provider, since we'll need that to at the least add it + # to the system or check that it matches what is given to us. box_provider = box.metadata["provider"] + if provider # Verify that the given provider matches what the box has. if box_provider.to_sym != provider diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index ef8b8b461..fa66702a3 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -426,7 +426,16 @@ module Vagrant # Second pass, with the box 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] end diff --git a/test/unit/vagrant/environment_test.rb b/test/unit/vagrant/environment_test.rb index ad302da34..bba1fa57b 100644 --- a/test/unit/vagrant/environment_test.rb +++ b/test/unit/vagrant/environment_test.rb @@ -183,6 +183,25 @@ VF env.config.for_vm(:bar).ssh.port.should == 200 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 environment = isolated_environment do |env| env.vagrantfile(<<-VF)