Update how disk_ext default is set

Prior to this commit, the default value of disk_ext was set in the
finalize! method, and was really only valid for the virtualbox provider.
This commit updates that by moving the step into the validate function,
which has access to the machines provider.
This commit is contained in:
Brian Cain 2020-04-07 09:47:26 -07:00
parent a7a779586a
commit fe7705e694
No known key found for this signature in database
GPG Key ID: 9FC4639B2E4510A0
2 changed files with 13 additions and 4 deletions

View File

@ -107,8 +107,6 @@ module VagrantPlugins
@size = nil if @size == UNSET_VALUE
@file = nil if @file == UNSET_VALUE
@disk_ext = "vdi" if @disk_ext == UNSET_VALUE
if @primary == UNSET_VALUE
@primary = false
end
@ -135,7 +133,18 @@ module VagrantPlugins
types: DEFAULT_DISK_TYPES.join(', '))
end
if @disk_ext
if @disk_ext == UNSET_VALUE
# Work around to finalize disk_ext with a valid default per-provider
if machine.provider_name == :virtualbox
@disk_ext = "vdi"
elsif machine.provider_name == :vmware_desktop
@disk_ext = nil
elsif machine.provider_name == :hyperv
@disk_ext = "vhdx"
else
@disk_ext = "vdi"
end
elsif @disk_ext
@disk_ext = @disk_ext.downcase
if machine.provider.capability?(:validate_disk_ext)

View File

@ -10,7 +10,7 @@ describe VagrantPlugins::Kernel_V2::VagrantConfigDisk do
subject { described_class.new(type) }
let(:provider) { double("provider") }
let(:machine) { double("machine", provider: provider) }
let(:machine) { double("machine", provider: provider, provider_name: :virtualbox) }
def assert_invalid