From fb8f0c010b6c81574eefd1ca60f7e0410f439d7c Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 31 Dec 2010 21:41:05 -0600 Subject: [PATCH] Reload config after downloading box during `up` [closes GH-231] --- CHANGELOG.md | 2 ++ lib/vagrant/action/vm/check_box.rb | 1 + lib/vagrant/environment.rb | 7 +++++++ test/vagrant/action/vm/check_box_test.rb | 1 + test/vagrant/environment_test.rb | 15 +++++++++++++++ 5 files changed, 26 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e1e13b419..213645303 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ - HTTP downloading follows redirects. [GH-163] - Downloaders have clearer output to note what they're doing. - Shared folders with no guest path are not automounted. [GH-184] + - Boxes downloaded during `vagrant up` reload the Vagrantfile config, which + fixes a problem with box settings not being properly loaded. [GH-231] ## 0.7.0.beta (December 24, 2010) diff --git a/lib/vagrant/action/vm/check_box.rb b/lib/vagrant/action/vm/check_box.rb index c28171673..e9838a356 100644 --- a/lib/vagrant/action/vm/check_box.rb +++ b/lib/vagrant/action/vm/check_box.rb @@ -17,6 +17,7 @@ module Vagrant env.ui.info I18n.t("vagrant.actions.vm.check_box.not_found", :name => box_name) Vagrant::Box.add(env.env, box_name, box_url) env["boxes"].reload! + env.env.reload_config! end @app.call(env) diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index 74019d42a..58df82928 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -305,6 +305,13 @@ module Vagrant self end + # Reloads the configuration of this environment. + def reload_config! + @config = nil + load_config! + self + end + # Loads this environment's configuration and stores it in the {#config} # variable. The configuration loaded by this method is specified to # this environment, meaning that it will use the given root directory diff --git a/test/vagrant/action/vm/check_box_test.rb b/test/vagrant/action/vm/check_box_test.rb index 453e064b6..121554b38 100644 --- a/test/vagrant/action/vm/check_box_test.rb +++ b/test/vagrant/action/vm/check_box_test.rb @@ -45,6 +45,7 @@ class CheckBoxVMActionTest < Test::Unit::TestCase env.env.boxes.expects(:find).returns(nil) Vagrant::Box.expects(:add).with(env.env, env["config"].vm.box, env["config"].vm.box_url).in_sequence(seq) env.env.boxes.expects(:reload!).in_sequence(seq) + env.env.expects(:reload_config!).in_sequence(seq) app.expects(:call).with(env).once.in_sequence(seq) assert_nothing_raised { diff --git a/test/vagrant/environment_test.rb b/test/vagrant/environment_test.rb index 67d452340..7e1c3c6f8 100644 --- a/test/vagrant/environment_test.rb +++ b/test/vagrant/environment_test.rb @@ -425,6 +425,21 @@ class EnvironmentTest < Test::Unit::TestCase @env.load_config! assert @env.instance_variable_get(:@logger).nil? end + + should "be able to reload config" do + vagrantfile(@env.root_path, "config.vm.box = 'box'") + + # First load the config normally + @env.load_config! + assert_equal "box", @env.config.vm.box + assert_not_equal "set", @env.config.vm.base_mac + + # Modify the Vagrantfile and reload it, then verify new results + # are available + vagrantfile(@env.root_path, "config.vm.base_mac = 'set'") + @env.reload_config! + assert_equal "set", @env.config.vm.base_mac + end end context "loading home directory" do