Added boxes are now verified
This commit is contained in:
parent
b454408314
commit
5b307a5d9b
|
@ -15,6 +15,7 @@ module Vagrant
|
||||||
|
|
||||||
@runner.add_action(Download)
|
@runner.add_action(Download)
|
||||||
@runner.add_action(Unpackage)
|
@runner.add_action(Unpackage)
|
||||||
|
@runner.add_action(Verify)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,7 +4,6 @@ module Vagrant
|
||||||
# This action unpackages a downloaded box file into its final
|
# This action unpackages a downloaded box file into its final
|
||||||
# box destination within the vagrant home folder.
|
# box destination within the vagrant home folder.
|
||||||
class Unpackage < Base
|
class Unpackage < Base
|
||||||
|
|
||||||
def execute!
|
def execute!
|
||||||
@runner.invoke_around_callback(:unpackage) do
|
@runner.invoke_around_callback(:unpackage) do
|
||||||
setup_box_dir
|
setup_box_dir
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
module Vagrant
|
||||||
|
module Actions
|
||||||
|
module Box
|
||||||
|
# This action verifies that a given box is valid. This works by attempting
|
||||||
|
# to read/interpret the appliance file (OVF). If the reading succeeds, then
|
||||||
|
# the box is assumed to be valid.
|
||||||
|
class Verify < Base
|
||||||
|
def execute!
|
||||||
|
reload_configuration
|
||||||
|
verify_appliance
|
||||||
|
end
|
||||||
|
|
||||||
|
def reload_configuration
|
||||||
|
# We have to reload the environment config since we _just_ added the
|
||||||
|
# box. We do this by setting the current box to the recently added box,
|
||||||
|
# then reloading
|
||||||
|
@runner.env.config.vm.box = @runner.name
|
||||||
|
@runner.env.load_box!
|
||||||
|
@runner.env.load_config!
|
||||||
|
end
|
||||||
|
|
||||||
|
def verify_appliance
|
||||||
|
# We now try to read the applince. If it succeeds, we return true.
|
||||||
|
VirtualBox::Appliance.new(@runner.env.box.ovf_file)
|
||||||
|
true
|
||||||
|
rescue VirtualBox::Exceptions::FileErrorException
|
||||||
|
false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -7,7 +7,7 @@ class AddBoxActionTest < Test::Unit::TestCase
|
||||||
|
|
||||||
context "prepare" do
|
context "prepare" do
|
||||||
setup do
|
setup do
|
||||||
@default_order = [Vagrant::Actions::Box::Download, Vagrant::Actions::Box::Unpackage]
|
@default_order = [Vagrant::Actions::Box::Download, Vagrant::Actions::Box::Unpackage, Vagrant::Actions::Box::Verify]
|
||||||
@runner.stubs(:directory).returns("foo")
|
@runner.stubs(:directory).returns("foo")
|
||||||
File.stubs(:exists?).returns(false)
|
File.stubs(:exists?).returns(false)
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
||||||
|
|
||||||
|
class VerifyBoxActionTest < Test::Unit::TestCase
|
||||||
|
setup do
|
||||||
|
@runner, @vm, @action = mock_action(Vagrant::Actions::Box::Verify)
|
||||||
|
@runner.stubs(:name).returns("foo")
|
||||||
|
@runner.stubs(:temp_path).returns("bar")
|
||||||
|
end
|
||||||
|
|
||||||
|
context "executing" do
|
||||||
|
should "execute the proper actions in the proper order" do
|
||||||
|
exec_seq = sequence("exec_seq")
|
||||||
|
@action.expects(:reload_configuration).in_sequence(exec_seq)
|
||||||
|
@action.expects(:verify_appliance).in_sequence(exec_seq)
|
||||||
|
@action.execute!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "reloading configuration" do
|
||||||
|
should "set the new box, load box, then load config" do
|
||||||
|
reload_seq = sequence("reload_seq")
|
||||||
|
@runner.env.config.vm.expects(:box=).with(@runner.name).in_sequence(reload_seq)
|
||||||
|
@runner.env.expects(:load_box!).in_sequence(reload_seq)
|
||||||
|
@runner.env.expects(:load_config!).in_sequence(reload_seq)
|
||||||
|
@action.reload_configuration
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "verifying appliance" do
|
||||||
|
setup do
|
||||||
|
@box = mock("box")
|
||||||
|
@box.stubs(:ovf_file).returns("foo")
|
||||||
|
|
||||||
|
@runner.env.stubs(:box).returns(@box)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "create new appliance and return true if succeeds" do
|
||||||
|
VirtualBox::Appliance.expects(:new).with(@box.ovf_file)
|
||||||
|
assert @action.verify_appliance
|
||||||
|
end
|
||||||
|
|
||||||
|
should "return false if an exception is raised" do
|
||||||
|
VirtualBox::Appliance.expects(:new).with(@box.ovf_file).raises(VirtualBox::Exceptions::FileErrorException)
|
||||||
|
assert !@action.verify_appliance
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue