Box collection can detect V1 boxes and throws an exception
The exception notifies the caller that the box needs to be upgraded. The upgrade process is not yet done but is coming ina future commit.
This commit is contained in:
parent
a6d7bd48fd
commit
9d1924811e
|
@ -24,6 +24,18 @@ module Vagrant
|
|||
box_directory = @directory.join(name, provider.to_s, "metadata.json")
|
||||
return Box2.new(name, provider, box_directory.dirname) if box_directory.file?
|
||||
|
||||
# Check if a V1 version of this box exists, and if so, raise an
|
||||
# exception notifying the caller that the box exists but needs
|
||||
# to be upgraded. We don't do the upgrade here because it can be
|
||||
# a fairly intensive activity and don't want to immediately degrade
|
||||
# user performance on a find.
|
||||
#
|
||||
# To determine if it is a V1 box we just do a simple heuristic
|
||||
# based approach.
|
||||
if @directory.join(name, "box.ovf").file?
|
||||
raise Errors::BoxUpgradeRequired, :name => name
|
||||
end
|
||||
|
||||
# Didn't find it, return nil
|
||||
nil
|
||||
end
|
||||
|
|
|
@ -123,6 +123,10 @@ module Vagrant
|
|||
error_key(:untar_failure, "vagrant.actions.box.unpackage")
|
||||
end
|
||||
|
||||
class BoxUpgradeRequired < VagrantError
|
||||
error_key(:box_upgrade_required)
|
||||
end
|
||||
|
||||
class BoxVerificationFailed < VagrantError
|
||||
status_code(15)
|
||||
error_key(:failed, "vagrant.actions.box.verify")
|
||||
|
|
|
@ -16,6 +16,10 @@ en:
|
|||
errors:
|
||||
base_vm_not_found: The base VM with the name '%{name}' was not found.
|
||||
box_not_found: Box '%{name}' could not be found.
|
||||
box_upgrade_required: |-
|
||||
The box '%{name}' is still stored on disk in the Vagrant 1.0.x
|
||||
format. This box must be upgraded in order to work properly with
|
||||
this version of Vagrant.
|
||||
cli_invalid_options: |-
|
||||
An invalid option was specified. The help for this command
|
||||
is available below.
|
||||
|
|
|
@ -24,5 +24,16 @@ describe Vagrant::BoxCollection2 do
|
|||
result.should be_kind_of(box_class)
|
||||
result.name.should == "foo"
|
||||
end
|
||||
|
||||
it "should throw an exception if it is a v1 box" do
|
||||
# Create a V1 box
|
||||
box_dir = environment.boxes_dir.join("foo")
|
||||
box_dir.mkpath
|
||||
box_dir.join("box.ovf").open("w") { |f| f.write("") }
|
||||
|
||||
# Test!
|
||||
expect { instance.find("foo", :virtualbox) }.
|
||||
to raise_error(Vagrant::Errors::BoxUpgradeRequired)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue