Fixes #11228: Allow to force check for box updates
Prior to this commit, if a user had recently checked for updates, there was no way to force Vagrant to re-check without manually deleting a state file in the local `.vagrant` data dir. This commit fixes that by giving users the ability to force check for updates for a given box with a flag to the `vagrant box outdated` command.
This commit is contained in:
parent
b03f8f5aac
commit
bcf4d5a210
|
@ -40,7 +40,7 @@ module Vagrant
|
||||||
# Have download options specified in the environment override
|
# Have download options specified in the environment override
|
||||||
# options specified for the machine.
|
# options specified for the machine.
|
||||||
download_options = {
|
download_options = {
|
||||||
automatic_check: true,
|
automatic_check: !env[:box_outdated_force],
|
||||||
ca_cert: env[:ca_cert] || machine.config.vm.box_download_ca_cert,
|
ca_cert: env[:ca_cert] || machine.config.vm.box_download_ca_cert,
|
||||||
ca_path: env[:ca_path] || machine.config.vm.box_download_ca_path,
|
ca_path: env[:ca_path] || machine.config.vm.box_download_ca_path,
|
||||||
client_cert: env[:client_cert] ||
|
client_cert: env[:client_cert] ||
|
||||||
|
|
|
@ -26,6 +26,10 @@ module VagrantPlugins
|
||||||
options[:global] = g
|
options[:global] = g
|
||||||
end
|
end
|
||||||
|
|
||||||
|
o.on("-f", "--force", "Force checks for latest box updates") do |f|
|
||||||
|
options[:force] = f
|
||||||
|
end
|
||||||
|
|
||||||
build_download_options(o, download_options)
|
build_download_options(o, download_options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -40,7 +44,7 @@ module VagrantPlugins
|
||||||
|
|
||||||
with_target_vms(argv) do |machine|
|
with_target_vms(argv) do |machine|
|
||||||
@env.action_runner.run(Vagrant::Action.action_box_outdated, {
|
@env.action_runner.run(Vagrant::Action.action_box_outdated, {
|
||||||
box_outdated_force: true,
|
box_outdated_force: options[:force],
|
||||||
box_outdated_refresh: true,
|
box_outdated_refresh: true,
|
||||||
box_outdated_success_ui: true,
|
box_outdated_success_ui: true,
|
||||||
machine: machine,
|
machine: machine,
|
||||||
|
|
|
@ -20,6 +20,18 @@ describe VagrantPlugins::CommandBox::Command::Outdated do
|
||||||
allow(iso_env).to receive(:action_runner).and_return(action_runner)
|
allow(iso_env).to receive(:action_runner).and_return(action_runner)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "with force argument" do
|
||||||
|
let(:argv) { ["--force"] }
|
||||||
|
|
||||||
|
it "passes along the force update option" do
|
||||||
|
expect(action_runner).to receive(:run).with(any_args) { |action, **opts|
|
||||||
|
expect(opts[:box_outdated_force]).to be_truthy
|
||||||
|
true
|
||||||
|
}
|
||||||
|
subject.execute
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "with global argument" do
|
context "with global argument" do
|
||||||
let(:argv) { ["--global"] }
|
let(:argv) { ["--global"] }
|
||||||
|
|
||||||
|
@ -29,10 +41,6 @@ describe VagrantPlugins::CommandBox::Command::Outdated do
|
||||||
subject.execute
|
subject.execute
|
||||||
end
|
end
|
||||||
|
|
||||||
before do
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
describe ".outdated_global" do
|
describe ".outdated_global" do
|
||||||
let(:test_iso_env) { isolated_environment }
|
let(:test_iso_env) { isolated_environment }
|
||||||
|
|
||||||
|
|
|
@ -54,11 +54,21 @@ describe Vagrant::Action::Builtin::BoxCheckOutdated do
|
||||||
env[:box_outdated_force] = true
|
env[:box_outdated_force] = true
|
||||||
|
|
||||||
expect(app).to receive(:call).with(env).once
|
expect(app).to receive(:call).with(env).once
|
||||||
|
expect(box).to receive(:has_update?)
|
||||||
|
|
||||||
subject.call(env)
|
subject.call(env)
|
||||||
|
|
||||||
expect(env).to have_key(:box_outdated)
|
expect(env).to have_key(:box_outdated)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "checks if not forced" do
|
||||||
|
machine.config.vm.box_check_update = false
|
||||||
|
env[:box_outdated_force] = false
|
||||||
|
|
||||||
|
expect(app).to receive(:call).with(env).once
|
||||||
|
|
||||||
|
subject.call(env)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "no box" do
|
context "no box" do
|
||||||
|
|
|
@ -125,8 +125,13 @@ which may be different than the absolute latest version available.
|
||||||
Checking for updates involves refreshing the metadata associated with
|
Checking for updates involves refreshing the metadata associated with
|
||||||
a box. This generally requires an internet connection.
|
a box. This generally requires an internet connection.
|
||||||
|
|
||||||
|
By default, if Vagrant has recently checked for a box that's out of date, it will
|
||||||
|
cache that answer and not look up another update for one hour. This cached value
|
||||||
|
can be ignored if the `--force` flag is used.
|
||||||
|
|
||||||
## Options
|
## Options
|
||||||
|
|
||||||
|
* `--force` - Check for updates for all installed boxes and ignore cache interval.
|
||||||
* `--global` - Check for updates for all installed boxes, not just the
|
* `--global` - Check for updates for all installed boxes, not just the
|
||||||
boxes for the current Vagrant environment.
|
boxes for the current Vagrant environment.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue