Lookup latest available installed box if required on update
When performing a box update and the box version has been updated to be different than the installed version, perform a lookup for the latest available installed box to allow the update command to continue successfully
This commit is contained in:
parent
03d8965ef7
commit
00b783a6a5
|
@ -100,10 +100,14 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
|
|
||||||
if !machine.box
|
if !machine.box
|
||||||
machine.ui.output(I18n.t(
|
collection = Vagrant::BoxCollection.new(@env.boxes_path)
|
||||||
"vagrant.errors.box_update_no_box",
|
machine.box = collection.find(machine.config.vm.box, provider || @env.default_provider, "> 0")
|
||||||
name: machine.config.vm.box))
|
if !machine.box
|
||||||
next
|
machine.ui.output(I18n.t(
|
||||||
|
"vagrant.errors.box_update_no_box",
|
||||||
|
name: machine.config.vm.box))
|
||||||
|
next
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
name = machine.box.name
|
name = machine.box.name
|
||||||
|
|
|
@ -307,6 +307,35 @@ describe VagrantPlugins::CommandBox::Command::Update do
|
||||||
subject.execute
|
subject.execute
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "when box version is updated but previous box exists" do
|
||||||
|
|
||||||
|
let(:collection) { double("collection") }
|
||||||
|
|
||||||
|
it "updates the box" do
|
||||||
|
# First call gets nil result to for lookup
|
||||||
|
expect(machine).to receive(:box).and_return(nil)
|
||||||
|
expect(Vagrant::BoxCollection).to receive(:new).and_return(collection)
|
||||||
|
expect(collection).to receive(:find).and_return(box)
|
||||||
|
|
||||||
|
expect(box).to receive(:has_update?).
|
||||||
|
with(machine.config.vm.box_version,
|
||||||
|
{download_options:
|
||||||
|
{ca_cert: nil, ca_path: nil, client_cert: nil,
|
||||||
|
insecure: false}}).
|
||||||
|
and_return([md, md.version("1.1"), md.version("1.1").provider("virtualbox")])
|
||||||
|
|
||||||
|
expect(action_runner).to receive(:run).with(any_args) { |action, opts|
|
||||||
|
expect(opts[:box_url]).to eq(box.metadata_url)
|
||||||
|
expect(opts[:box_provider]).to eq("virtualbox")
|
||||||
|
expect(opts[:box_version]).to eq("1.1")
|
||||||
|
expect(opts[:ui]).to equal(machine.ui)
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
subject.execute
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "machine has download options" do
|
context "machine has download options" do
|
||||||
before do
|
before do
|
||||||
machine.config.vm.box_download_ca_cert = "oof"
|
machine.config.vm.box_download_ca_cert = "oof"
|
||||||
|
|
Loading…
Reference in New Issue