From 3cef90cfb9f382f2aa6fd8ead57d12ce07c9d5ec Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 20 May 2010 20:54:34 -0700 Subject: [PATCH] Remove util.rb and that logger --- lib/vagrant.rb | 4 +- lib/vagrant/busy.rb | 6 +-- lib/vagrant/commands/destroy.rb | 2 +- lib/vagrant/commands/halt.rb | 2 +- lib/vagrant/commands/reload.rb | 2 +- lib/vagrant/commands/resume.rb | 2 +- lib/vagrant/commands/suspend.rb | 2 +- lib/vagrant/util.rb | 31 ------------- test/vagrant/commands/destroy_test.rb | 1 + test/vagrant/commands/halt_test.rb | 1 + test/vagrant/commands/reload_test.rb | 1 + test/vagrant/commands/resume_test.rb | 1 + test/vagrant/commands/suspend_test.rb | 1 + test/vagrant/util_test.rb | 64 --------------------------- 14 files changed, 15 insertions(+), 105 deletions(-) delete mode 100644 lib/vagrant/util.rb delete mode 100644 test/vagrant/util_test.rb diff --git a/lib/vagrant.rb b/lib/vagrant.rb index 6272dedb6..4e1bb23c1 100644 --- a/lib/vagrant.rb +++ b/lib/vagrant.rb @@ -11,6 +11,6 @@ end require File.expand_path("util/glob_loader", libdir) # Load them up -Vagrant::GlobLoader.glob_require(libdir, %w{util util/stacked_proc_runner util/progress_meter +Vagrant::GlobLoader.glob_require(libdir, %w{util/stacked_proc_runner util/progress_meter actions/base downloaders/base actions/collection actions/runner config - provisioners/base provisioners/chef systems/base commands/base commands/box}) \ No newline at end of file + provisioners/base provisioners/chef systems/base commands/base commands/box}) diff --git a/lib/vagrant/busy.rb b/lib/vagrant/busy.rb index 47cecb031..de670b63f 100644 --- a/lib/vagrant/busy.rb +++ b/lib/vagrant/busy.rb @@ -45,7 +45,7 @@ module Vagrant def wait_for_not_busy(sleeptime=5) if @@trap_thread - logger.info "Exiting vagrant immediately!" + # logger.info "Exiting vagrant immediately!" Thread.kill(@@trap_thread) abort return # for tests @@ -55,12 +55,12 @@ module Vagrant # Wait while the app is busy loop do break unless busy? - logger.info "Waiting for vagrant to clean itself up..." + # logger.info "Waiting for vagrant to clean itself up..." sleep sleeptime end # Exit out of the entire script - logger.info "Exiting vagrant..." + # logger.info "Exiting vagrant..." exit end end diff --git a/lib/vagrant/commands/destroy.rb b/lib/vagrant/commands/destroy.rb index 55c601950..485b85193 100644 --- a/lib/vagrant/commands/destroy.rb +++ b/lib/vagrant/commands/destroy.rb @@ -31,7 +31,7 @@ module Vagrant if vm.created? vm.destroy else - logger.info "VM '#{name}' not created. Ignoring." + vm.env.logger.info "VM '#{name}' not created. Ignoring." end end diff --git a/lib/vagrant/commands/halt.rb b/lib/vagrant/commands/halt.rb index 337dff2b5..82faab086 100644 --- a/lib/vagrant/commands/halt.rb +++ b/lib/vagrant/commands/halt.rb @@ -30,7 +30,7 @@ module Vagrant if vm.created? vm.halt(options[:force]) else - logger.info "VM '#{name}' not created. Ignoring." + vm.env.logger.info "VM '#{name}' not created. Ignoring." end end diff --git a/lib/vagrant/commands/reload.rb b/lib/vagrant/commands/reload.rb index f541142d1..fc32a931c 100644 --- a/lib/vagrant/commands/reload.rb +++ b/lib/vagrant/commands/reload.rb @@ -29,7 +29,7 @@ module Vagrant if vm.created? vm.reload else - logger.info "VM '#{name}' not created. Ignoring." + vm.env.logger.info "VM '#{name}' not created. Ignoring." end end diff --git a/lib/vagrant/commands/resume.rb b/lib/vagrant/commands/resume.rb index 937c3c5cc..79bef1dfa 100644 --- a/lib/vagrant/commands/resume.rb +++ b/lib/vagrant/commands/resume.rb @@ -29,7 +29,7 @@ module Vagrant if vm.created? vm.resume else - logger.info "VM '#{name}' not created. Ignoring." + vm.env.logger.info "VM '#{name}' not created. Ignoring." end end diff --git a/lib/vagrant/commands/suspend.rb b/lib/vagrant/commands/suspend.rb index f45410cbd..fd29483a4 100644 --- a/lib/vagrant/commands/suspend.rb +++ b/lib/vagrant/commands/suspend.rb @@ -30,7 +30,7 @@ module Vagrant if vm.created? vm.suspend else - logger.info "VM '#{name}' not created. Ignoring." + vm.env.logger.info "VM '#{name}' not created. Ignoring." end end diff --git a/lib/vagrant/util.rb b/lib/vagrant/util.rb deleted file mode 100644 index 35a83f37f..000000000 --- a/lib/vagrant/util.rb +++ /dev/null @@ -1,31 +0,0 @@ -module Vagrant - module Util - def logger - Logger.singleton_logger - end - end - - class Logger < ::Logger - @@singleton_logger = nil - - class << self - def singleton_logger - # TODO: Buffer messages until config is loaded, then output them? - if Vagrant.config.loaded? - @@singleton_logger ||= Vagrant::Logger.new(Vagrant.config.vagrant.log_output) - else - Vagrant::Logger.new(nil) - end - end - - def reset_logger! - @@singleton_logger = nil - end - end - - def format_message(level, time, progname, msg) - "[#{level} #{time.strftime('%m-%d-%Y %X')}] Vagrant: #{msg}\n" - end - end -end - diff --git a/test/vagrant/commands/destroy_test.rb b/test/vagrant/commands/destroy_test.rb index 561695deb..f75795c5b 100644 --- a/test/vagrant/commands/destroy_test.rb +++ b/test/vagrant/commands/destroy_test.rb @@ -37,6 +37,7 @@ class CommandsDestroyTest < Test::Unit::TestCase context "destroying a single VM" do setup do @foo_vm = mock("vm") + @foo_vm.stubs(:env).returns(@env) vms = { :foo => @foo_vm } @env.stubs(:vms).returns(vms) end diff --git a/test/vagrant/commands/halt_test.rb b/test/vagrant/commands/halt_test.rb index 3cbe61b45..569aa5767 100644 --- a/test/vagrant/commands/halt_test.rb +++ b/test/vagrant/commands/halt_test.rb @@ -36,6 +36,7 @@ class CommandsHaltTest < Test::Unit::TestCase context "halting a single VM" do setup do @foo_vm = mock("vm") + @foo_vm.stubs(:env).returns(@env) vms = { :foo => @foo_vm } @env.stubs(:vms).returns(vms) end diff --git a/test/vagrant/commands/reload_test.rb b/test/vagrant/commands/reload_test.rb index 6ab2fa42a..9de1411bf 100644 --- a/test/vagrant/commands/reload_test.rb +++ b/test/vagrant/commands/reload_test.rb @@ -36,6 +36,7 @@ class CommandsReloadTest < Test::Unit::TestCase context "reloading a single VM" do setup do @foo_vm = mock("vm") + @foo_vm.stubs(:env).returns(@env) vms = { :foo => @foo_vm } @env.stubs(:vms).returns(vms) end diff --git a/test/vagrant/commands/resume_test.rb b/test/vagrant/commands/resume_test.rb index 0671a34ff..6d6b5b864 100644 --- a/test/vagrant/commands/resume_test.rb +++ b/test/vagrant/commands/resume_test.rb @@ -36,6 +36,7 @@ class CommandsResumeTest < Test::Unit::TestCase context "resuming a single VM" do setup do @foo_vm = mock("vm") + @foo_vm.stubs(:env).returns(@env) vms = { :foo => @foo_vm } @env.stubs(:vms).returns(vms) end diff --git a/test/vagrant/commands/suspend_test.rb b/test/vagrant/commands/suspend_test.rb index 84a9feaad..2a00d75f7 100644 --- a/test/vagrant/commands/suspend_test.rb +++ b/test/vagrant/commands/suspend_test.rb @@ -36,6 +36,7 @@ class CommandsSuspendTest < Test::Unit::TestCase context "suspending a single VM" do setup do @foo_vm = mock("vm") + @foo_vm.stubs(:env).returns(@env) vms = { :foo => @foo_vm } @env.stubs(:vms).returns(vms) end diff --git a/test/vagrant/util_test.rb b/test/vagrant/util_test.rb deleted file mode 100644 index 46f3a271f..000000000 --- a/test/vagrant/util_test.rb +++ /dev/null @@ -1,64 +0,0 @@ -require File.join(File.dirname(__FILE__), '..', 'test_helper') - -class UtilTest < Test::Unit::TestCase - class RegUtil - extend Vagrant::Util - end - - context "erroring" do - # TODO: Any way to stub Kernel.exit? Can't test nicely - # otherwise - end - - context "logger" do - class OtherUtil - extend Vagrant::Util - end - - setup do - @config = Vagrant::Config::Top.new - @config.stubs(:loaded?).returns(true) - @config.vagrant.log_output = STDOUT - Vagrant::Config.stubs(:config).returns(@config) - Vagrant::Logger.reset_logger! - end - - teardown do - Vagrant::Logger.reset_logger! - end - - should "return a logger to nil if config is not loaded" do - @config.expects(:loaded?).returns(false) - logger = RegUtil.logger - assert_nil logger.instance_variable_get(:@logdev) - end - - should "return a logger using the configured output" do - logger = RegUtil.logger - logdev = logger.instance_variable_get(:@logdev) - assert logger - assert !logdev.nil? - assert_equal STDOUT, logdev.dev - end - - should "only instantiate a logger once" do - Vagrant::Logger.expects(:new).once.returns("GOOD") - RegUtil.logger - RegUtil.logger - end - - should "be able to reset the logger" do - Vagrant::Logger.expects(:new).twice - RegUtil.logger - Vagrant::Logger.reset_logger! - RegUtil.logger - end - - should "return the same logger across classes" do - logger = RegUtil.logger - other = OtherUtil.logger - - assert logger.equal?(other) - end - end -end