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 end
def call(env) def call(env)
begin @env[:ui].info I18n.t("vagrant.actions.box.verify.verifying")
@env[:ui].info I18n.t("vagrant.actions.box.verify.verifying")
VirtualBox::Appliance.new(env["box_directory"].join("box.ovf").to_s) driver = Driver::VirtualBox.new(nil)
rescue Exception if !driver.verify_image(env["box_directory"].join("box.ovf").to_s)
raise Errors::BoxVerificationFailed raise Errors::BoxVerificationFailed
end end

View File

@ -242,6 +242,14 @@ module Vagrant
execute("controlvm", @uuid, "savestate") execute("controlvm", @uuid, "savestate")
end 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 protected
# This returns the version of VirtualBox that is running. # 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. # Execute the given subcommand for VBoxManage and return the output.
def execute(*command) def execute(*command)
# TODO: Detect failures and handle them # Execute the command
r = Subprocess.execute("VBoxManage", *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 if r.exit_code != 0
# TODO: Inherit from VagrantError
raise Exception, "FAILURE: #{r.stderr}" raise Exception, "FAILURE: #{r.stderr}"
end end
# Return the output
r.stdout r.stdout
end end
# Executes a command and returns the raw result object.
def raw(*command)
Subprocess.execute("VBoxManage", *command)
end
end end
end end
end end