Warning if guest additions version mismatches [closes GH-96]

This commit is contained in:
Mitchell Hashimoto 2010-06-15 21:58:27 -07:00
parent 3532f6368c
commit 3be88f44fa
6 changed files with 54 additions and 18 deletions

View File

@ -21,6 +21,7 @@ module Vagrant
def after_import
update_dotfile
setup_mac_address
check_guest_additions
end
def update_dotfile
@ -33,6 +34,19 @@ module Vagrant
@runner.vm.network_adapters.first.mac_address = @runner.env.config.vm.base_mac
@runner.vm.save
end
def check_guest_additions
# Use the raw interface for now, while the virtualbox gem
# doesn't support guest properties (due to cross platform issues)
version = @runner.vm.interface.get_guest_property_value("/VirtualBox/GuestAdd/Version")
if version.empty?
logger.error Translator.t(:vm_additions_not_detected)
elsif version != VirtualBox.version
logger.error Translator.t(:vm_additions_version_mismatch,
:guest_additions_version => version,
:virtualbox_version => VirtualBox.version)
end
end
end
end
end

View File

@ -61,19 +61,19 @@ module Vagrant
@logger = self.class.singleton_logger(env)
end
# TODO: The other logging methods.
[:debug, :info, :error, :fatal].each do |method|
define_method(method) do |message|
@@writer_lock.synchronize do
# We clear the line in case progress reports have been going
# out.
print(cl_reset)
logger.send(method, "[#{resource}] #{message}")
end
def info(message)
@@writer_lock.synchronize do
# We clear the line in case progress reports have been going
# out.
print(cl_reset)
logger.info("[#{resource}] #{message}")
# Once again flush the progress reporters since we probably
# cleared any existing ones.
flush_progress
end
# Once again flush the progress reporters since we probably
# cleared any existing ones.
flush_progress
end
# Sets a progress report for the resource that this logger

View File

@ -6,7 +6,7 @@ module Vagrant
class Translator
@@strings = nil
class <<self
class << self
# Resets the internal strings hash to nil, forcing a reload on the next
# access of {strings}.
def reset!
@ -32,4 +32,4 @@ module Vagrant
end
end
end
end
end

View File

@ -40,6 +40,26 @@
Path: <%= data["path"] %>
Created at: <%= Time.at(data["created_at"]) %>
#---------------------------------------------------------------------
# CATEGORY: Warning Messages
#---------------------------------------------------------------------
:vm_additions_not_detected: |-
WARNING!
No guest additions were detected on the base box for this VM! Guest
additions are required for forwarded ports, shared folders, host only
networking, and more. If SSH fails on this machine, please install
the guest additions and repackage the box to continue.
:vm_additions_version_mismatch: |-
WARNING!
The guest additions on this VM do not match the install version of
VirtualBox! This often causes things such as forwared ports, shared
folders, and more to not work properly. If any of those things fail on
this machine, please update the guest additions and repackage the
box.
Guest Additions Version: <%= guest_additions_version %>
VirtualBox Version: <%= virtualbox_version %>
#---------------------------------------------------------------------
# CATEGORY: Error Messages
#---------------------------------------------------------------------

View File

@ -69,6 +69,7 @@ class UpActionTest < Test::Unit::TestCase
boot_seq = sequence("boot")
@action.expects(:update_dotfile).once.in_sequence(boot_seq)
@action.expects(:setup_mac_address).once.in_sequence(boot_seq)
@action.expects(:check_guest_additions).once.in_sequence(boot_seq)
@action.after_import
end
end

View File

@ -76,11 +76,12 @@ class ResourceLoggerTest < Test::Unit::TestCase
@instance.stubs(:cl_reset).returns("")
end
should "log with the proper format" do
message = "bar"
@logger.expects(:info).with("[#{@resource}] #{message}").once
@instance.info(message)
[:debug, :info, :error, :fatal].each do |method|
should "log with the proper format on #{method}" do
message = "bar"
@logger.expects(method).with("[#{@resource}] #{message}").once
@instance.send(method, message)
end
end
end