Ensure box version default of 0 uses mtime (#1512)

If a box is added directly without a version, vagrant will default set
it to 0. When this occurs it is necessary to ensure use of mtime to
distinguish when the disk image in the box was last updated to allow
replacement of the box to trigger a fresh upload.

Fixes: #1382
This commit is contained in:
Darragh Bailey 2022-06-13 10:25:43 +01:00 committed by GitHub
parent 26e25c0191
commit 66e0fa7dda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -134,7 +134,7 @@ module VagrantPlugins
'' ''
end end
if version.empty? if version.empty? || version == '0'
ui.warn(I18n.t('vagrant_libvirt.box_version_missing', name: box.name.to_s)) ui.warn(I18n.t('vagrant_libvirt.box_version_missing', name: box.name.to_s))
version = "0_#{File.mtime(path).to_i}" version = "0_#{File.mtime(path).to_i}"

View File

@ -125,6 +125,23 @@ describe VagrantPlugins::ProviderLibvirt::Action::HandleBoxImage do
end end
end end
context 'when box version set to 0' do
let(:box_mtime) { Time.now }
before do
expect(env[:machine]).to receive_message_chain("box.version") { '0' }
expect(File).to receive(:mtime).and_return(box_mtime)
end
it 'should use the box file timestamp' do
expect(ui).to receive(:warn).with(/No verison detected for test/)
expect(subject.call(env)).to be_nil
expect(env[:box_volume_number]).to eq(1)
expect(env[:box_volumes]).to match([hash_including({:name=>"test_vagrant_box_image_0_#{box_mtime.to_i}_box.img"})])
end
end
context 'When config.machine_virtual_size is set and smaller than box_virtual_size' do context 'When config.machine_virtual_size is set and smaller than box_virtual_size' do
before do before do
env[:machine].provider_config.machine_virtual_size = 1 env[:machine].provider_config.machine_virtual_size = 1