core: BoxAdd adds matching provider even if lower version
This commit is contained in:
parent
80194cde35
commit
5b075fa34e
|
@ -21,6 +21,7 @@ module Vagrant
|
||||||
@download_interrupted = false
|
@download_interrupted = false
|
||||||
|
|
||||||
provider = env[:box_provider]
|
provider = env[:box_provider]
|
||||||
|
provider = Array(provider) if provider
|
||||||
url = env[:box_url]
|
url = env[:box_url]
|
||||||
version = env[:box_version]
|
version = env[:box_version]
|
||||||
|
|
||||||
|
@ -34,26 +35,29 @@ module Vagrant
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: provider that is in an earlier version
|
metadata_version = metadata.version(
|
||||||
# TODO: multiple providers
|
version || ">= 0", provider: provider)
|
||||||
metadata_version = metadata.version(version || ">= 0")
|
|
||||||
if !metadata_version
|
if !metadata_version
|
||||||
raise Errors::BoxAddNoMatchingVersion,
|
if !provider
|
||||||
constraints: version || ">= 0",
|
raise Errors::BoxAddNoMatchingVersion,
|
||||||
url: url,
|
constraints: version || ">= 0",
|
||||||
versions: metadata.versions.join(", ")
|
url: url,
|
||||||
|
versions: metadata.versions.join(", ")
|
||||||
|
else
|
||||||
|
# TODO: show supported providers
|
||||||
|
raise Errors::BoxAddNoMatchingProvider,
|
||||||
|
requested: provider,
|
||||||
|
url: url
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
metadata_provider = nil
|
metadata_provider = nil
|
||||||
if provider
|
if provider
|
||||||
# If a provider was specified, make sure we get that specific
|
# If a provider was specified, make sure we get that specific
|
||||||
# version.
|
# version.
|
||||||
metadata_provider = metadata_version.provider(provider)
|
provider.each do |p|
|
||||||
if !metadata_provider
|
metadata_provider = metadata_version.provider(p)
|
||||||
raise Errors::BoxAddNoMatchingProvider,
|
break if metadata_provider
|
||||||
providers: metadata_version.providers.join(", "),
|
|
||||||
requested: provider,
|
|
||||||
url: url
|
|
||||||
end
|
end
|
||||||
elsif metadata_version.providers.length == 1
|
elsif metadata_version.providers.length == 1
|
||||||
# If we have only one provider in the metadata, just use that
|
# If we have only one provider in the metadata, just use that
|
||||||
|
|
|
@ -219,7 +219,6 @@ en:
|
||||||
|
|
||||||
Box: %{url}
|
Box: %{url}
|
||||||
Requested provider: %{requested}
|
Requested provider: %{requested}
|
||||||
Available providers: %{providers}
|
|
||||||
box_add_no_matching_version: |-
|
box_add_no_matching_version: |-
|
||||||
The box you're attempting to add has no available version that
|
The box you're attempting to add has no available version that
|
||||||
matches the constraints you requested. Please double-check your
|
matches the constraints you requested. Please double-check your
|
||||||
|
|
|
@ -109,6 +109,52 @@ describe Vagrant::Action::Builtin::BoxAdd do
|
||||||
subject.call(env)
|
subject.call(env)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "adds the latest version of a box with the specified provider, even if not latest" do
|
||||||
|
box_path = iso_env.box2_file(:vmware)
|
||||||
|
tf = Tempfile.new("vagrant").tap do |f|
|
||||||
|
f.write(<<-RAW)
|
||||||
|
{
|
||||||
|
"name": "foo/bar",
|
||||||
|
"versions": [
|
||||||
|
{
|
||||||
|
"version": "0.5"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"version": "0.7",
|
||||||
|
"providers": [
|
||||||
|
{
|
||||||
|
"name": "virtualbox",
|
||||||
|
"url": "#{iso_env.box2_file(:virtualbox)}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "vmware",
|
||||||
|
"url": "#{box_path}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"version": "1.5"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
RAW
|
||||||
|
f.close
|
||||||
|
end
|
||||||
|
|
||||||
|
env[:box_url] = tf.path
|
||||||
|
env[:box_provider] = "vmware"
|
||||||
|
box_collection.should_receive(:add).with do |path, name, version|
|
||||||
|
expect(checksum(path)).to eq(checksum(box_path))
|
||||||
|
expect(name).to eq("foo/bar")
|
||||||
|
expect(version).to eq("0.7")
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
app.should_receive(:call).with(env)
|
||||||
|
|
||||||
|
subject.call(env)
|
||||||
|
end
|
||||||
|
|
||||||
it "adds the constrained version of a box with the only provider" do
|
it "adds the constrained version of a box with the only provider" do
|
||||||
box_path = iso_env.box2_file(:vmware)
|
box_path = iso_env.box2_file(:vmware)
|
||||||
tf = Tempfile.new("vagrant").tap do |f|
|
tf = Tempfile.new("vagrant").tap do |f|
|
||||||
|
@ -188,6 +234,51 @@ describe Vagrant::Action::Builtin::BoxAdd do
|
||||||
subject.call(env)
|
subject.call(env)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "adds the latest version of a box with any specified provider" do
|
||||||
|
box_path = iso_env.box2_file(:vmware)
|
||||||
|
tf = Tempfile.new("vagrant").tap do |f|
|
||||||
|
f.write(<<-RAW)
|
||||||
|
{
|
||||||
|
"name": "foo/bar",
|
||||||
|
"versions": [
|
||||||
|
{
|
||||||
|
"version": "0.5",
|
||||||
|
"providers": [
|
||||||
|
{
|
||||||
|
"name": "virtualbox",
|
||||||
|
"url": "#{iso_env.box2_file(:virtualbox)}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"version": "0.7",
|
||||||
|
"providers": [
|
||||||
|
{
|
||||||
|
"name": "vmware",
|
||||||
|
"url": "#{box_path}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
RAW
|
||||||
|
f.close
|
||||||
|
end
|
||||||
|
|
||||||
|
env[:box_url] = tf.path
|
||||||
|
env[:box_provider] = ["virtualbox", "vmware"]
|
||||||
|
box_collection.should_receive(:add).with do |path, name, version|
|
||||||
|
expect(checksum(path)).to eq(checksum(box_path))
|
||||||
|
expect(name).to eq("foo/bar")
|
||||||
|
expect(version).to eq("0.7")
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
app.should_receive(:call).with(env)
|
||||||
|
|
||||||
|
subject.call(env)
|
||||||
|
end
|
||||||
|
|
||||||
it "raises an exception if no matching version" do
|
it "raises an exception if no matching version" do
|
||||||
box_path = iso_env.box2_file(:vmware)
|
box_path = iso_env.box2_file(:vmware)
|
||||||
tf = Tempfile.new("vagrant").tap do |f|
|
tf = Tempfile.new("vagrant").tap do |f|
|
||||||
|
|
Loading…
Reference in New Issue