diff --git a/config/default.rb b/config/default.rb index fc380eb12..ed3e6d887 100644 --- a/config/default.rb +++ b/config/default.rb @@ -1,5 +1,7 @@ Vagrant::Config.run do |config| # default config goes here + config.vagrant.log_output = STDOUT + config.ssh.username = "vagrant" config.ssh.password = "vagrant" config.ssh.host = "localhost" diff --git a/lib/vagrant.rb b/lib/vagrant.rb index 2959edf13..4db47b9e2 100644 --- a/lib/vagrant.rb +++ b/lib/vagrant.rb @@ -16,8 +16,4 @@ require 'vagrant/config' require 'vagrant/env' require 'vagrant/provisioning' require 'vagrant/ssh' -require 'vagrant/vm' - -# TODO: Make this configurable -log_output = ENV['VAGRANT_ENV'] == 'test' ? nil : STDOUT -VAGRANT_LOGGER = Vagrant::Logger.new(log_output) +require 'vagrant/vm' \ No newline at end of file diff --git a/lib/vagrant/config.rb b/lib/vagrant/config.rb index ec68ed6e8..a86427890 100644 --- a/lib/vagrant/config.rb +++ b/lib/vagrant/config.rb @@ -24,6 +24,8 @@ module Vagrant config_runners.each do |block| block.call(config) end + + config.loaded! end end end @@ -74,16 +76,32 @@ module Vagrant attr_accessor :json end + class VagrantConfig < Base + attr_accessor :log_output + end + class Top < Base attr_accessor :dotfile_name attr_reader :ssh attr_reader :vm attr_reader :chef + attr_reader :vagrant def initialize @ssh = SSHConfig.new @vm = VMConfig.new @chef = ChefConfig.new + @vagrant = VagrantConfig.new + + @loaded = false + end + + def loaded? + @loaded + end + + def loaded! + @loaded = true end end end diff --git a/lib/vagrant/env.rb b/lib/vagrant/env.rb index 5a17ef85c..19a917f4d 100644 --- a/lib/vagrant/env.rb +++ b/lib/vagrant/env.rb @@ -26,7 +26,7 @@ module Vagrant ] load_paths.each do |path| - VAGRANT_LOGGER.info "Loading config from #{path}..." + logger.info "Loading config from #{path}..." load path if File.exist?(path) end diff --git a/lib/vagrant/util.rb b/lib/vagrant/util.rb index 12f619237..c36197d8b 100644 --- a/lib/vagrant/util.rb +++ b/lib/vagrant/util.rb @@ -12,7 +12,12 @@ error end def logger - VAGRANT_LOGGER + # TODO: Buffer messages until config is loaded, then output them? + if Vagrant.config.loaded? + @logger ||= Vagrant::Logger.new(Vagrant.config.vagrant.log_output) + else + Vagrant::Logger.new(nil) + end end end diff --git a/lib/vagrant/vm.rb b/lib/vagrant/vm.rb index 8d6cedebb..615f734e8 100644 --- a/lib/vagrant/vm.rb +++ b/lib/vagrant/vm.rb @@ -134,7 +134,7 @@ error end end - def start + def start(sleep_interval = 5) logger.info "Booting VM..." @vm.start(:headless, true) @@ -149,7 +149,7 @@ error return true end - sleep 5 unless ENV['VAGRANT_ENV'] == 'test' + sleep sleep_interval end logger.info "Failed to connect to VM! Failed to boot?" diff --git a/test/test_helper.rb b/test/test_helper.rb index 525cb4cdf..ffe38f2fe 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -7,9 +7,6 @@ rescue LoadError Bundler.setup end -# This silences logger output -ENV['VAGRANT_ENV'] = 'test' - # ruby-debug, not necessary, but useful if we have it begin require 'ruby-debug' diff --git a/test/vagrant/config_test.rb b/test/vagrant/config_test.rb index 508649dfc..a43b44cc9 100644 --- a/test/vagrant/config_test.rb +++ b/test/vagrant/config_test.rb @@ -35,12 +35,19 @@ class ConfigTest < Test::Unit::TestCase end should "run the blocks with the same config object" do - config = mock("config") - config.expects(:foo).twice - Vagrant::Config.stubs(:config).returns(config) - Vagrant::Config.run { |config| config.foo } - Vagrant::Config.run { |config| config.foo } + Vagrant::Config.run { |config| assert config } + Vagrant::Config.run { |config| assert config } Vagrant::Config.execute! end + + should "not be loaded, initially" do + assert !Vagrant::Config.config.loaded? + end + + should "be loaded after running" do + Vagrant::Config.run {} + Vagrant::Config.execute! + assert Vagrant::Config.config.loaded? + end end end diff --git a/test/vagrant/vm_test.rb b/test/vagrant/vm_test.rb index 82ba383c3..7d4b43e2a 100644 --- a/test/vagrant/vm_test.rb +++ b/test/vagrant/vm_test.rb @@ -82,19 +82,19 @@ class VMTest < Test::Unit::TestCase should "start the VM in headless mode" do @mock_vm.expects(:start).with(:headless, true).once Vagrant::SSH.expects(:up?).once.returns(true) - @vm.start + @vm.start(0) end should "repeatedly ping the SSH port and return false with no response" do seq = sequence('pings') Vagrant::SSH.expects(:up?).times(Vagrant.config[:ssh][:max_tries].to_i - 1).returns(false).in_sequence(seq) Vagrant::SSH.expects(:up?).once.returns(true).in_sequence(seq) - assert @vm.start + assert @vm.start(0) end should "ping the max number of times then just return" do Vagrant::SSH.expects(:up?).times(Vagrant.config[:ssh][:max_tries].to_i).returns(false) - assert !@vm.start + assert !@vm.start(0) end end