From f205a747c9d80efd6379f13e0ee23cb32349293b Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 5 Jul 2010 03:53:19 +0200 Subject: [PATCH] CheckGuestAdditions middleware --- lib/vagrant/action/builtin.rb | 1 + .../action/vm/check_guest_additions.rb | 30 +++++++++++++++++++ .../action/vm/check_guest_additions_test.rb | 9 ++++++ vagrant.gemspec | 6 ++++ 4 files changed, 46 insertions(+) create mode 100644 lib/vagrant/action/vm/check_guest_additions.rb create mode 100644 test/vagrant/action/vm/check_guest_additions_test.rb diff --git a/lib/vagrant/action/builtin.rb b/lib/vagrant/action/builtin.rb index b1b5aab99..02c7d2095 100644 --- a/lib/vagrant/action/builtin.rb +++ b/lib/vagrant/action/builtin.rb @@ -9,6 +9,7 @@ module Vagrant use VM::Import use VM::Persist use VM::MatchMACAddress + use VM::CheckGuestAdditions use VM::Customize use VM::ForwardPorts use VM::ShareFolders diff --git a/lib/vagrant/action/vm/check_guest_additions.rb b/lib/vagrant/action/vm/check_guest_additions.rb new file mode 100644 index 000000000..f7a962b7e --- /dev/null +++ b/lib/vagrant/action/vm/check_guest_additions.rb @@ -0,0 +1,30 @@ +module Vagrant + class Action + module VM + # Middleware which verifies that the VM has the proper guest additions + # installed and prints a warning if they're not detected or if the + # version does not match the installed VirtualBox version. + class CheckGuestAdditions + def initialize(app, env) + @app = app + end + + def call(env) + # Use the raw interface for now, while the virtualbox gem + # doesn't support guest properties (due to cross platform issues) + version = env["vm"].vm.interface.get_guest_property_value("/VirtualBox/GuestAdd/Version") + if version.empty? + env.logger.error Translator.t(:vm_additions_not_detected) + elsif version != VirtualBox.version + env.logger.error Translator.t(:vm_additions_version_mismatch, + :guest_additions_version => version, + :virtualbox_version => VirtualBox.version) + end + + # Continue + @app.call(env) + end + end + end + end +end diff --git a/test/vagrant/action/vm/check_guest_additions_test.rb b/test/vagrant/action/vm/check_guest_additions_test.rb new file mode 100644 index 000000000..656d3faf2 --- /dev/null +++ b/test/vagrant/action/vm/check_guest_additions_test.rb @@ -0,0 +1,9 @@ +require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper') + +class CheckGuestAdditionsVMActionTest < Test::Unit::TestCase + setup do + @klass = Vagrant::Action::VM::CheckGuestAdditions + end + + # TODO: This isn't tested. +end diff --git a/vagrant.gemspec b/vagrant.gemspec index 1126a8633..186c90d5c 100644 --- a/vagrant.gemspec +++ b/vagrant.gemspec @@ -42,6 +42,8 @@ Gem::Specification.new do |s| "lib/vagrant/action/vm/customize.rb", "lib/vagrant/action/vm/forward_ports.rb", "lib/vagrant/action/vm/import.rb", + "lib/vagrant/action/vm/match_mac_address.rb", + "lib/vagrant/action/vm/persist.rb", "lib/vagrant/action/vm/share_folders.rb", "lib/vagrant/actions/base.rb", "lib/vagrant/actions/box/add.rb", @@ -130,6 +132,8 @@ Gem::Specification.new do |s| "test/vagrant/action/vm/customize_test.rb", "test/vagrant/action/vm/forward_ports_test.rb", "test/vagrant/action/vm/import_test.rb", + "test/vagrant/action/vm/match_mac_address_test.rb", + "test/vagrant/action/vm/persist_test.rb", "test/vagrant/action/vm/share_folders_test.rb", "test/vagrant/action_test.rb", "test/vagrant/actions/base_test.rb", @@ -216,6 +220,8 @@ Gem::Specification.new do |s| "test/vagrant/action/vm/customize_test.rb", "test/vagrant/action/vm/forward_ports_test.rb", "test/vagrant/action/vm/import_test.rb", + "test/vagrant/action/vm/match_mac_address_test.rb", + "test/vagrant/action/vm/persist_test.rb", "test/vagrant/action/vm/share_folders_test.rb", "test/vagrant/action_test.rb", "test/vagrant/actions/base_test.rb",