From 0aae0dd588c28239323c051ae054ad4729865ffc Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 21 Dec 2011 15:34:51 -0800 Subject: [PATCH] Box verification works with VBoxManage --- lib/vagrant/action/box/verify.rb | 8 ++++---- lib/vagrant/driver/virtualbox.rb | 23 +++++++++++++++++++++-- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/lib/vagrant/action/box/verify.rb b/lib/vagrant/action/box/verify.rb index 11ad2e6f9..67232db05 100644 --- a/lib/vagrant/action/box/verify.rb +++ b/lib/vagrant/action/box/verify.rb @@ -8,10 +8,10 @@ module Vagrant end def call(env) - begin - @env[:ui].info I18n.t("vagrant.actions.box.verify.verifying") - VirtualBox::Appliance.new(env["box_directory"].join("box.ovf").to_s) - rescue Exception + @env[:ui].info I18n.t("vagrant.actions.box.verify.verifying") + + driver = Driver::VirtualBox.new(nil) + if !driver.verify_image(env["box_directory"].join("box.ovf").to_s) raise Errors::BoxVerificationFailed end diff --git a/lib/vagrant/driver/virtualbox.rb b/lib/vagrant/driver/virtualbox.rb index 59e5eaeb5..80069588b 100644 --- a/lib/vagrant/driver/virtualbox.rb +++ b/lib/vagrant/driver/virtualbox.rb @@ -242,6 +242,14 @@ module Vagrant execute("controlvm", @uuid, "savestate") end + # Verifies that an image can be imported properly. + # + # @return [Boolean] + def verify_image(path) + r = raw("import", path.to_s, "--dry-run") + return r.exit_code == 0 + end + protected # This returns the version of VirtualBox that is running. @@ -253,13 +261,24 @@ module Vagrant # Execute the given subcommand for VBoxManage and return the output. def execute(*command) - # TODO: Detect failures and handle them - r = Subprocess.execute("VBoxManage", *command) + # Execute the command + r = raw(*command) + + # If the command was a failure, then raise an exception that is + # nicely handled by Vagrant. if r.exit_code != 0 + # TODO: Inherit from VagrantError raise Exception, "FAILURE: #{r.stderr}" end + + # Return the output r.stdout end + + # Executes a command and returns the raw result object. + def raw(*command) + Subprocess.execute("VBoxManage", *command) + end end end end