Raise an error if disk files are re-used in config
This commit is contained in:
parent
c52eb1b44c
commit
8985369eab
@ -914,6 +914,13 @@ module VagrantPlugins
|
||||
name: duplicate_names)
|
||||
end
|
||||
|
||||
disk_files = @disks.select { |d| d.type == :disk }.map { |d| d.file }
|
||||
duplicate_files = disk_files.detect { |d| disk_files.count(d) > 1 }
|
||||
if duplicate_files && duplicate_files.size
|
||||
errors << I18n.t("vagrant.config.vm.multiple_disk_files_error",
|
||||
file: duplicate_files)
|
||||
end
|
||||
|
||||
@disks.each do |d|
|
||||
error = d.validate(machine)
|
||||
errors.concat error if !error.empty?
|
||||
|
||||
@ -1972,6 +1972,12 @@ en:
|
||||
Ignoring provider config for validation...
|
||||
multiple_primary_disks_error: |-
|
||||
There are more than one primary disks defined for guest '%{name}'. Please ensure that only one disk has been defined as a primary disk.
|
||||
multiple_disk_files_error: |-
|
||||
The following disk file is used multiple times in the disk configuration:
|
||||
|
||||
%{file}
|
||||
|
||||
Each disk file may only be attached to a VM once.
|
||||
multiple_disk_names_error: |-
|
||||
Duplicate disk names defined: '%{name}'. Disk names must be unique.
|
||||
multiple_networks_set_hostname: "Multiple networks have set `:hostname`"
|
||||
|
||||
@ -622,6 +622,22 @@ describe VagrantPlugins::Kernel_V2::VMConfig do
|
||||
assert_invalid
|
||||
end
|
||||
|
||||
it "raises an error with duplicate disk files" do
|
||||
allow(File).to receive(:file?).with("bar.vmdk").and_return(true)
|
||||
subject.disk(:disk, size: 100, name: "foo1", file: "bar.vmdk")
|
||||
subject.disk(:disk, size: 100, name: "foo2", file: "bar.vmdk")
|
||||
subject.finalize!
|
||||
assert_invalid
|
||||
end
|
||||
|
||||
it "does not raise an error with duplicate dvd files" do
|
||||
allow(File).to receive(:file?).with("bar.iso").and_return(true)
|
||||
subject.disk(:dvd, name: "foo1", file: "bar.iso")
|
||||
subject.disk(:dvd, name: "foo2", file: "bar.iso")
|
||||
subject.finalize!
|
||||
assert_valid
|
||||
end
|
||||
|
||||
it "does not merge duplicate disks" do
|
||||
subject.disk(:disk, size: 1000, primary: false, name: "storage")
|
||||
subject.disk(:disk, size: 1000, primary: false, name: "backup")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user