diff --git a/lib/vagrant/action/builtin/box_check_outdated.rb b/lib/vagrant/action/builtin/box_check_outdated.rb index eecad9911..c703ddf58 100644 --- a/lib/vagrant/action/builtin/box_check_outdated.rb +++ b/lib/vagrant/action/builtin/box_check_outdated.rb @@ -24,6 +24,12 @@ module Vagrant def call(env) machine = env[:machine] + if !env[:box_outdated_force] + if !machine.config.vm.box_check_update + return @app.call(env) + end + end + if !machine.box # The box doesn't exist. I suppose technically that means # that it is "outdated" but we show a specialized error @@ -55,7 +61,10 @@ module Vagrant old: machine.box.version, new: box.version)) env[:box_outdated] = true + return end + + env[:box_outdated] = false end def check_outdated_refresh(env) diff --git a/plugins/commands/box/command/outdated.rb b/plugins/commands/box/command/outdated.rb index aec4c94c7..81f453dfe 100644 --- a/plugins/commands/box/command/outdated.rb +++ b/plugins/commands/box/command/outdated.rb @@ -26,6 +26,7 @@ module VagrantPlugins with_target_vms(argv) do |machine| @env.action_runner.run(Vagrant::Action.action_box_outdated, { + box_outdated_force: true, box_outdated_refresh: true, box_outdated_success_ui: true, machine: machine, diff --git a/plugins/kernel_v2/config/vm.rb b/plugins/kernel_v2/config/vm.rb index 308e6a0af..563ed1719 100644 --- a/plugins/kernel_v2/config/vm.rb +++ b/plugins/kernel_v2/config/vm.rb @@ -17,6 +17,7 @@ module VagrantPlugins attr_accessor :base_mac attr_accessor :boot_timeout attr_accessor :box + attr_accessor :box_check_update attr_accessor :box_url attr_accessor :box_version attr_accessor :box_download_ca_cert @@ -33,6 +34,7 @@ module VagrantPlugins def initialize @base_mac = UNSET_VALUE @boot_timeout = UNSET_VALUE + @box_check_update = UNSET_VALUE @box_download_ca_cert = UNSET_VALUE @box_download_checksum = UNSET_VALUE @box_download_checksum_type = UNSET_VALUE @@ -305,6 +307,7 @@ module VagrantPlugins # Defaults @base_mac = nil if @base_mac == UNSET_VALUE @boot_timeout = 300 if @boot_timeout == UNSET_VALUE + @box_check_update = nil if @box_check_update == UNSET_VALUE @box_download_ca_cert = nil if @box_download_ca_cert == UNSET_VALUE @box_download_checksum = nil if @box_download_checksum == UNSET_VALUE @box_download_checksum_type = nil if @box_download_checksum_type == UNSET_VALUE diff --git a/test/unit/plugins/kernel_v2/config/vm_test.rb b/test/unit/plugins/kernel_v2/config/vm_test.rb index 205597f09..73f0a85fd 100644 --- a/test/unit/plugins/kernel_v2/config/vm_test.rb +++ b/test/unit/plugins/kernel_v2/config/vm_test.rb @@ -32,6 +32,14 @@ describe VagrantPlugins::Kernel_V2::VMConfig do end end + context "#box_check_update" do + it "defaults to nil" do + subject.finalize! + + expect(subject.box_check_update).to be_nil + end + end + describe "#box_url" do it "defaults to nil" do subject.finalize! diff --git a/test/unit/vagrant/action/builtin/box_check_outdated_test.rb b/test/unit/vagrant/action/builtin/box_check_outdated_test.rb index 3c08777c6..4b67b9c89 100644 --- a/test/unit/vagrant/action/builtin/box_check_outdated_test.rb +++ b/test/unit/vagrant/action/builtin/box_check_outdated_test.rb @@ -25,7 +25,38 @@ describe Vagrant::Action::Builtin::BoxCheckOutdated do box_dir = iso_env.box3("foo", "1.0", :virtualbox) Vagrant::Box.new("foo", :virtualbox, "1.0", box_dir) end - let(:machine) { iso_vagrant_env.machine(iso_vagrant_env.machine_names[0], :dummy) } + let(:machine) do + m = iso_vagrant_env.machine(iso_vagrant_env.machine_names[0], :dummy) + m.config.vm.box_check_update = true + m + end + + before do + machine.stub(box: box) + end + + context "disabling outdated checking" do + it "doesn't check" do + machine.config.vm.box_check_update = false + + app.should_receive(:call).with(env).once + + subject.call(env) + + expect(env).to_not have_key(:box_outdated) + end + + it "checks if forced" do + machine.config.vm.box_check_update = false + env[:box_outdated_force] = true + + app.should_receive(:call).with(env).once + + subject.call(env) + + expect(env).to have_key(:box_outdated) + end + end context "no box" do it "raises an exception if the machine doesn't have a box yet" do