Remove util.rb and that logger

This commit is contained in:
Mitchell Hashimoto 2010-05-20 20:54:34 -07:00
parent 377fa1f7cc
commit 3cef90cfb9
14 changed files with 15 additions and 105 deletions

View File

@ -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})
provisioners/base provisioners/chef systems/base commands/base commands/box})

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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