Raise an error if primary disk can't be found
This commit is contained in:
parent
8561467e40
commit
1e6eb0d636
@ -936,6 +936,10 @@ module Vagrant
|
||||
error_key(:virtualbox_disks_controller_not_found)
|
||||
end
|
||||
|
||||
class VirtualBoxDisksPrimaryNotFound < VagrantError
|
||||
error_key(:virtualbox_disks_primary_not_found)
|
||||
end
|
||||
|
||||
class VirtualBoxGuestPropertyNotFound < VagrantError
|
||||
error_key(:virtualbox_guest_property_not_found)
|
||||
end
|
||||
|
||||
@ -27,12 +27,16 @@ module VagrantPlugins
|
||||
# @param [Hash] disk_meta - A hash of all the previously defined disks from the last configure_disk action
|
||||
def self.handle_cleanup_disk(machine, defined_disks, disk_meta)
|
||||
controller = machine.provider.driver.get_controller('SATA')
|
||||
primary_disk = controller.attachments.detect { |a| a[:port] == "0" && a[:device] == "0" }[:uuid]
|
||||
primary = controller.attachments.detect { |a| a[:port] == "0" && a[:device] == "0" }
|
||||
if primary.nil?
|
||||
raise Vagrant::Errors::VirtualBoxDisksPrimaryNotFound
|
||||
end
|
||||
primary_uuid = primary[:uuid]
|
||||
|
||||
if disk_meta
|
||||
disk_meta.each do |d|
|
||||
dsk = defined_disks.select { |dk| dk.name == d["name"] }
|
||||
if !dsk.empty? || d["uuid"] == primary_disk
|
||||
if !dsk.empty? || d["uuid"] == primary_uuid
|
||||
next
|
||||
else
|
||||
LOGGER.warn("Found disk not in Vagrantfile config: '#{d["name"]}'. Removing disk from guest #{machine.name}")
|
||||
|
||||
@ -69,6 +69,9 @@ module VagrantPlugins
|
||||
# always come in port order, but primary is always Port 0 Device 0.
|
||||
controller = machine.provider.driver.get_controller('SATA')
|
||||
primary = controller.attachments.detect { |a| a[:port] == "0" && a[:device] == "0" }
|
||||
if primary.nil?
|
||||
raise Vagrant::Errors::VirtualBoxDisksPrimaryNotFound
|
||||
end
|
||||
primary_uuid = primary[:uuid]
|
||||
|
||||
current_disk = all_disks.select { |d| d["UUID"] == primary_uuid }.first
|
||||
|
||||
@ -1683,6 +1683,10 @@ en:
|
||||
'%{storage_bus}', but no such controller was found. Please add the
|
||||
proper controller to your guest using provider-specific
|
||||
customizations.
|
||||
virtualbox_disks_primary_not_found: |-
|
||||
Vagrant was not able to detect a primary disk attached to the SATA
|
||||
controller. Vagrant Disks requires that the primary disk be attached
|
||||
to the first port of the SATA controller in order to manage it.
|
||||
virtualbox_disks_defined_exceed_limit: |-
|
||||
VirtualBox only allows up to 30 disks to be attached to a single guest using the SATA Controller,
|
||||
including the primray disk.
|
||||
|
||||
@ -63,6 +63,12 @@ describe VagrantPlugins::ProviderVirtualBox::Cap::CleanupDisks do
|
||||
|
||||
subject.cleanup_disks(machine, defined_disks, disk_meta_file)
|
||||
end
|
||||
|
||||
it "raises an error if primary disk can't be found" do
|
||||
allow(sata_controller).to receive(:attachments).and_return([])
|
||||
expect { subject.cleanup_disks(machine, defined_disks, disk_meta_file) }.
|
||||
to raise_error(Vagrant::Errors::VirtualBoxDisksPrimaryNotFound)
|
||||
end
|
||||
end
|
||||
|
||||
context "with dvd attached" do
|
||||
|
||||
@ -142,6 +142,12 @@ describe VagrantPlugins::ProviderVirtualBox::Cap::ConfigureDisks do
|
||||
expect(primary_disk).to eq(all_disks.first)
|
||||
end
|
||||
|
||||
it "raises an error if primary disk can't be found" do
|
||||
allow(sata_controller).to receive(:attachments).and_return([])
|
||||
expect { subject.get_current_disk(machine, defined_disks.first, all_disks) }.
|
||||
to raise_error(Vagrant::Errors::VirtualBoxDisksPrimaryNotFound)
|
||||
end
|
||||
|
||||
it "finds the disk to configure" do
|
||||
disk = subject.get_current_disk(machine, defined_disks[1], all_disks)
|
||||
expect(disk).to eq(all_disks[1])
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user