core: BoxCheckOutdated checks locally
This commit is contained in:
parent
d78194654d
commit
8cc16d14fa
|
@ -31,6 +31,36 @@ module Vagrant
|
|||
raise Errors::BoxOutdatedNoBox, name: machine.config.vm.box
|
||||
end
|
||||
|
||||
if env[:box_outdated_refresh]
|
||||
@logger.info(
|
||||
"Checking if box is outdated by refreshing metadata")
|
||||
check_outdated_refresh(env)
|
||||
else
|
||||
@logger.info("Checking if box is outdated locally")
|
||||
check_outdated_local(env)
|
||||
end
|
||||
|
||||
@app.call(env)
|
||||
end
|
||||
|
||||
def check_outdated_local(env)
|
||||
machine = env[:machine]
|
||||
box = env[:box_collection].find(
|
||||
machine.box.name, machine.box.provider,
|
||||
"> #{machine.box.version}")
|
||||
if box
|
||||
env[:ui].warn(I18n.t(
|
||||
"vagrant.box_outdated_local",
|
||||
name: box.name,
|
||||
old: machine.box.version,
|
||||
new: box.version))
|
||||
env[:box_outdated] = true
|
||||
end
|
||||
end
|
||||
|
||||
def check_outdated_refresh(env)
|
||||
machine = env[:machine]
|
||||
|
||||
if !machine.box.metadata_url
|
||||
# This box doesn't have a metadata URL, so we can't
|
||||
# possibly check the version information.
|
||||
|
@ -49,7 +79,7 @@ module Vagrant
|
|||
end
|
||||
|
||||
env[:box_outdated] = false
|
||||
return @app.call(env)
|
||||
return
|
||||
end
|
||||
|
||||
env[:ui].warn(I18n.t(
|
||||
|
@ -58,8 +88,6 @@ module Vagrant
|
|||
current: machine.box.version,
|
||||
latest: newer.version))
|
||||
env[:box_outdated] = true
|
||||
|
||||
@app.call(env)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -30,6 +30,11 @@ en:
|
|||
Loading metadata for box '%{name}'
|
||||
box_outdated: |-
|
||||
* '%{name}' is outdated! Current: %{current}. Latest: %{latest}
|
||||
box_outdated_local: |-
|
||||
A newer version of the box '%{name}' is available and already
|
||||
installed, but your Vagrant machine is running against
|
||||
version '%{old}'. To update to version '%{new}',
|
||||
destroy and recreate your machine.
|
||||
box_outdated_single: |-
|
||||
A newer version of the box '%{name}' is available! You currently
|
||||
have version '%{current}'. The latest is version '%{latest}'. Run
|
||||
|
|
|
@ -5,6 +5,7 @@ describe Vagrant::Action::Builtin::BoxCheckOutdated do
|
|||
|
||||
let(:app) { lambda { |env| } }
|
||||
let(:env) { {
|
||||
box_collection: iso_vagrant_env.boxes,
|
||||
machine: machine,
|
||||
ui: Vagrant::UI::Silent.new,
|
||||
} }
|
||||
|
@ -37,7 +38,40 @@ describe Vagrant::Action::Builtin::BoxCheckOutdated do
|
|||
end
|
||||
end
|
||||
|
||||
context "box with no metadata_url" do
|
||||
context "without refreshing" do
|
||||
before do
|
||||
env[:box_outdated_refresh] = false
|
||||
|
||||
machine.stub(box: box)
|
||||
end
|
||||
|
||||
it "isn't outdated if there are no newer boxes" do
|
||||
iso_env.box3("foo", "0.5", :virtualbox)
|
||||
|
||||
app.should_receive(:call).with(env)
|
||||
|
||||
subject.call(env)
|
||||
|
||||
expect(env[:box_outdated]).to be_false
|
||||
end
|
||||
|
||||
it "is outdated if there are newer boxes" do
|
||||
iso_env.box3("foo", "1.5", :virtualbox)
|
||||
|
||||
app.should_receive(:call).with(env)
|
||||
|
||||
subject.call(env)
|
||||
|
||||
expect(env[:box_outdated]).to be_true
|
||||
end
|
||||
end
|
||||
|
||||
context "with refreshing" do
|
||||
before do
|
||||
env[:box_outdated_refresh] = true
|
||||
end
|
||||
|
||||
context "no metadata URL" do
|
||||
let(:box) do
|
||||
box_dir = iso_env.box3("foo", "1.0", :virtualbox)
|
||||
Vagrant::Box.new("foo", :virtualbox, "1.0", box_dir)
|
||||
|
@ -55,7 +89,7 @@ describe Vagrant::Action::Builtin::BoxCheckOutdated do
|
|||
end
|
||||
end
|
||||
|
||||
context "with a metadata URL" do
|
||||
context "with metadata URL" do
|
||||
let(:metadata_url) do
|
||||
Tempfile.new("vagrant").tap do |f|
|
||||
f.close
|
||||
|
@ -184,4 +218,5 @@ describe Vagrant::Action::Builtin::BoxCheckOutdated do
|
|||
expect(env[:box_outdated]).to be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue