Box verification works with VBoxManage

This commit is contained in:
Mitchell Hashimoto 2011-12-21 15:34:51 -08:00
parent d030c62820
commit 0aae0dd588
2 changed files with 25 additions and 6 deletions

View File

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

View File

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