From a699122260bd0f1636086b9fb5196679cfa4dc4f Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 25 Aug 2010 22:38:24 -0700 Subject: [PATCH] No more logger usage for outputting to the shell --- lib/vagrant/action.rb | 4 ++-- lib/vagrant/downloaders/http.rb | 4 +--- lib/vagrant/hosts/bsd.rb | 2 +- lib/vagrant/hosts/linux.rb | 2 +- lib/vagrant/provisioners/base.rb | 6 ------ lib/vagrant/provisioners/chef.rb | 6 +++--- lib/vagrant/provisioners/chef_server.rb | 8 ++++---- lib/vagrant/provisioners/chef_solo.rb | 4 ++-- lib/vagrant/ssh.rb | 2 +- lib/vagrant/systems/base.rb | 6 ------ lib/vagrant/systems/linux.rb | 4 ++-- test/vagrant/action/box/destroy_test.rb | 16 +++++----------- test/vagrant/action/box/verify_test.rb | 4 ---- test/vagrant/hosts/bsd_test.rb | 1 - test/vagrant/hosts/linux_test.rb | 1 - 15 files changed, 22 insertions(+), 48 deletions(-) diff --git a/lib/vagrant/action.rb b/lib/vagrant/action.rb index 90f284ef8..ef8280e69 100644 --- a/lib/vagrant/action.rb +++ b/lib/vagrant/action.rb @@ -55,11 +55,11 @@ module Vagrant # chain has been run. int_callback = lambda do if action_environment.interrupted? - env.logger.info "Exiting immediately!" + env.ui.info "Exiting immediately!" abort end - env.logger.info "Waiting for cleanup before exiting..." + env.ui.info "Waiting for cleanup before exiting..." action_environment.error!(:interrupt) end diff --git a/lib/vagrant/downloaders/http.rb b/lib/vagrant/downloaders/http.rb index 05a67c0d7..d2b3baef1 100644 --- a/lib/vagrant/downloaders/http.rb +++ b/lib/vagrant/downloaders/http.rb @@ -36,7 +36,7 @@ module Vagrant # Progress reporting is limited to every 25 segments just so # we're not constantly updating if segment_count % 25 == 0 - env.logger.report_progress(progress, total) + env.ui.report_progress(progress, total) segment_count = 0 end @@ -45,8 +45,6 @@ module Vagrant end end end - - env.logger.clear_progress rescue SocketError env.error!(:box_download_http_socket_error, :box_url => source_url) end diff --git a/lib/vagrant/hosts/bsd.rb b/lib/vagrant/hosts/bsd.rb index 59fb0a92a..f3a76e38e 100644 --- a/lib/vagrant/hosts/bsd.rb +++ b/lib/vagrant/hosts/bsd.rb @@ -25,7 +25,7 @@ module Vagrant # The sleep ensures that the output is truly flushed before any `sudo` # commands are issued. - env.logger.info "Preparing to edit /etc/exports. Administrator priveleges will be required..." + env.ui.info "Preparing to edit /etc/exports. Administrator priveleges will be required..." sleep 0.5 output.split("\n").each do |line| diff --git a/lib/vagrant/hosts/linux.rb b/lib/vagrant/hosts/linux.rb index d0e0624c9..374bab918 100644 --- a/lib/vagrant/hosts/linux.rb +++ b/lib/vagrant/hosts/linux.rb @@ -24,7 +24,7 @@ module Vagrant :ip => ip, :folders => folders) - env.logger.info "Preparing to edit /etc/exports. Administrator priveleges will be required..." + env.ui.info "Preparing to edit /etc/exports. Administrator priveleges will be required..." sleep 0.5 output.split("\n").each do |line| diff --git a/lib/vagrant/provisioners/base.rb b/lib/vagrant/provisioners/base.rb index be2d450f0..637531230 100644 --- a/lib/vagrant/provisioners/base.rb +++ b/lib/vagrant/provisioners/base.rb @@ -30,12 +30,6 @@ module Vagrant env.vm end - # This method returns the environment's logger as a convenience - # method. - def logger - env.logger - end - # This is the method called to "prepare" the provisioner. This is called # before any actions are run by the action runner (see {Vagrant::Actions::Runner}). # This can be used to setup shared folders, forward ports, etc. Whatever is diff --git a/lib/vagrant/provisioners/chef.rb b/lib/vagrant/provisioners/chef.rb index 85781a8df..edc64249e 100644 --- a/lib/vagrant/provisioners/chef.rb +++ b/lib/vagrant/provisioners/chef.rb @@ -85,7 +85,7 @@ module Vagrant end def chown_provisioning_folder - logger.info "Setting permissions on chef provisioning folder..." + env.ui.info "Setting permissions on chef provisioning folder..." vm.ssh.execute do |ssh| ssh.exec!("sudo mkdir -p #{env.config.chef.provisioning_path}") ssh.exec!("sudo chown #{env.config.ssh.username} #{env.config.chef.provisioning_path}") @@ -97,12 +97,12 @@ module Vagrant :log_level => env.config.chef.log_level.to_sym }.merge(template_vars)) - logger.info "Uploading chef configuration script..." + env.ui.info "Uploading chef configuration script..." vm.ssh.upload!(StringIO.new(config_file), File.join(env.config.chef.provisioning_path, filename)) end def setup_json - logger.info "Generating chef JSON and uploading..." + env.ui.info "Generating chef JSON and uploading..." # Set up initial configuration data = { diff --git a/lib/vagrant/provisioners/chef_server.rb b/lib/vagrant/provisioners/chef_server.rb index 13826950c..d83a5dfd2 100644 --- a/lib/vagrant/provisioners/chef_server.rb +++ b/lib/vagrant/provisioners/chef_server.rb @@ -26,7 +26,7 @@ module Vagrant end def create_client_key_folder - logger.info "Creating folder to hold client key..." + env.ui.info "Creating folder to hold client key..." path = Pathname.new(env.config.chef.client_key_path) vm.ssh.execute do |ssh| @@ -35,7 +35,7 @@ module Vagrant end def upload_validation_key - logger.info "Uploading chef client validation key..." + env.ui.info "Uploading chef client validation key..." vm.ssh.upload!(validation_key_path, guest_validation_key_path) end @@ -52,13 +52,13 @@ module Vagrant def run_chef_client command = "cd #{env.config.chef.provisioning_path} && sudo -E chef-client -c client.rb -j dna.json" - logger.info "Running chef-client..." + env.ui.info "Running chef-client..." vm.ssh.execute do |ssh| ssh.exec!(command) do |channel, type, data| if type == :exit_status ssh.check_exit_status(data, command) else - logger.info("#{data}: #{type}") + env.ui.info("#{data}: #{type}") end end end diff --git a/lib/vagrant/provisioners/chef_solo.rb b/lib/vagrant/provisioners/chef_solo.rb index 34d062e35..1bcdac1dd 100644 --- a/lib/vagrant/provisioners/chef_solo.rb +++ b/lib/vagrant/provisioners/chef_solo.rb @@ -40,11 +40,11 @@ module Vagrant def run_chef_solo command = "cd #{env.config.chef.provisioning_path} && sudo -E chef-solo -c solo.rb -j dna.json" - logger.info "Running chef-solo..." + env.ui.info "Running chef-solo..." vm.ssh.execute do |ssh| ssh.exec!(command) do |channel, type, data| ssh.check_exit_status(data, command) if type == :exit_status - logger.info("#{data}: #{type}") if type != :exit_status + env.ui.info("#{data}: #{type}") if type != :exit_status end end end diff --git a/lib/vagrant/ssh.rb b/lib/vagrant/ssh.rb index 86daffd8a..be17126ae 100644 --- a/lib/vagrant/ssh.rb +++ b/lib/vagrant/ssh.rb @@ -118,7 +118,7 @@ module Vagrant stat = File.stat(key_path) if stat.owned? && file_perms(key_path) != "600" - env.logger.info "Permissions on private key incorrect, fixing..." + env.ui.info "Permissions on private key incorrect, fixing..." File.chmod(0600, key_path) error_and_exit(:ssh_bad_permissions, :key_path => key_path) if file_perms(key_path) != "600" diff --git a/lib/vagrant/systems/base.rb b/lib/vagrant/systems/base.rb index 113a58a50..383849730 100644 --- a/lib/vagrant/systems/base.rb +++ b/lib/vagrant/systems/base.rb @@ -27,12 +27,6 @@ module Vagrant @vm = vm end - # A convenience method to access the logger on the VM - # environment. - def logger - vm.env.logger - end - # Halt the machine. This method should gracefully shut down the # operating system. This method will cause `vagrant halt` and associated # commands to _block_, meaning that if the machine doesn't halt diff --git a/lib/vagrant/systems/linux.rb b/lib/vagrant/systems/linux.rb index 41f111647..623dd320e 100644 --- a/lib/vagrant/systems/linux.rb +++ b/lib/vagrant/systems/linux.rb @@ -29,7 +29,7 @@ module Vagrant # Overridden methods #------------------------------------------------------------------- def halt - logger.info "Attempting graceful shutdown of linux..." + vm.env.ui.info "Attempting graceful shutdown of linux..." vm.ssh.execute do |ssh| ssh.exec!("sudo halt") end @@ -66,7 +66,7 @@ module Vagrant def prepare_unison(ssh) ssh.exec!("which unison", :error_key => :unison_not_found) - logger.info "Preparing system for unison sync..." + vm.env.ui.info "Preparing system for unison sync..." vm.ssh.upload!(StringIO.new(TemplateRenderer.render('/unison/script')), config.unison.script) ssh.exec!("sudo chmod +x #{config.unison.script}") ssh.exec!("sudo rm #{config.unison.crontab_entry_file}", :error_check => false) diff --git a/test/vagrant/action/box/destroy_test.rb b/test/vagrant/action/box/destroy_test.rb index b8c9e7459..86eecb006 100644 --- a/test/vagrant/action/box/destroy_test.rb +++ b/test/vagrant/action/box/destroy_test.rb @@ -15,16 +15,10 @@ class DestroyBoxActionTest < Test::Unit::TestCase @instance = @klass.new(@app, @env) end - context "calling" do - setup do - @env.logger.stubs(:info) - end - - should "delete the box directory" do - seq = sequence("seq") - FileUtils.expects(:rm_rf).with(@env["box"].directory).in_sequence(seq) - @app.expects(:call).with(@env).once.in_sequence(seq) - @instance.call(@env) - end + should "delete the box directory" do + seq = sequence("seq") + FileUtils.expects(:rm_rf).with(@env["box"].directory).in_sequence(seq) + @app.expects(:call).with(@env).once.in_sequence(seq) + @instance.call(@env) end end diff --git a/test/vagrant/action/box/verify_test.rb b/test/vagrant/action/box/verify_test.rb index 3dbe608de..e50966ca9 100644 --- a/test/vagrant/action/box/verify_test.rb +++ b/test/vagrant/action/box/verify_test.rb @@ -16,10 +16,6 @@ class VerifyBoxActionTest < Test::Unit::TestCase end context "calling" do - setup do - @env.logger.stubs(:info) - end - should "continue fine if verification succeeds" do seq = sequence("seq") VirtualBox::Appliance.expects(:new).with(@env["box"].ovf_file).in_sequence(seq) diff --git a/test/vagrant/hosts/bsd_test.rb b/test/vagrant/hosts/bsd_test.rb index db86daab3..481808258 100644 --- a/test/vagrant/hosts/bsd_test.rb +++ b/test/vagrant/hosts/bsd_test.rb @@ -5,7 +5,6 @@ class BSDHostTest < Test::Unit::TestCase @klass = Vagrant::Hosts::BSD @env = mock_environment @env.stubs(:vm).returns(Vagrant::VM.new(:env => @env)) - @env.logger.stubs(:info) @instance = @klass.new(@env) end diff --git a/test/vagrant/hosts/linux_test.rb b/test/vagrant/hosts/linux_test.rb index b2c4d208f..31b267acd 100644 --- a/test/vagrant/hosts/linux_test.rb +++ b/test/vagrant/hosts/linux_test.rb @@ -5,7 +5,6 @@ class LinuxHostTest < Test::Unit::TestCase @klass = Vagrant::Hosts::Linux @env = mock_environment @env.stubs(:vm).returns(Vagrant::VM.new(:env => @env)) - @env.logger.stubs(:info) @instance = @klass.new(@env) end