Merge pull request #9502 from briancain/override-box-version

Use provider override for box_version if given
This commit is contained in:
Brian Cain 2018-02-22 12:58:24 -08:00 committed by GitHub
commit 2475c62b20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -155,6 +155,7 @@ module Vagrant
# Track the original box so we know if we changed # Track the original box so we know if we changed
box = nil box = nil
original_box = config.vm.box original_box = config.vm.box
original_version = config.vm.box_version
# The proc below loads the box and provider overrides. This is # The proc below loads the box and provider overrides. This is
# in a proc because it may have to recurse if the provider override # in a proc because it may have to recurse if the provider override
@ -188,10 +189,11 @@ module Vagrant
end end
# If the box changed, then we need to reload # If the box changed, then we need to reload
if original_box != config.vm.box if original_box != config.vm.box || original_version != config.vm.box_version
# TODO: infinite loop protection? # TODO: infinite loop protection?
original_box = config.vm.box original_box = config.vm.box
original_version = config.vm.box_version
load_box_proc.call load_box_proc.call
end end
end end

View File

@ -288,9 +288,11 @@ describe Vagrant::Vagrantfile do
configure do |config| configure do |config|
config.vm.box = "base" config.vm.box = "base"
config.vm.box_version = "1.0"
config.vm.provider "foo" do |_, c| config.vm.provider "foo" do |_, c|
c.vm.box = "foobox" c.vm.box = "foobox"
c.vm.box_version = "2.0"
end end
end end
@ -300,7 +302,7 @@ describe Vagrant::Vagrantfile do
end end
VF VF
iso_env.box3("foobox", "1.0", :foo, vagrantfile: <<-VF) iso_env.box3("foobox", "2.0", :foo, vagrantfile: <<-VF)
Vagrant.configure("2") do |config| Vagrant.configure("2") do |config|
config.ssh.port = 234 config.ssh.port = 234
end end
@ -311,8 +313,10 @@ describe Vagrant::Vagrantfile do
box = results[:box] box = results[:box]
expect(config.vm.box).to eq("foobox") expect(config.vm.box).to eq("foobox")
expect(config.ssh.port).to eq(234) expect(config.ssh.port).to eq(234)
expect(config.vm.box_version).to eq("2.0")
expect(box).to_not be_nil expect(box).to_not be_nil
expect(box.name).to eq("foobox") expect(box.name).to eq("foobox")
expect(box.version).to eq("2.0")
end end
it "raises an error if the machine is not found" do it "raises an error if the machine is not found" do