Avoid sorting of controllers with nil boot_priority

Some unsupported storage controllers (e.g. floppy) report a nil
boot_priority which results in a failed sort. Select only supported
storage controllers to avoid that case.
This commit is contained in:
Dan Duvall 2020-08-31 18:20:29 -07:00
parent 9a2369df8b
commit 1b0f5120c6
2 changed files with 7 additions and 8 deletions

View File

@ -27,10 +27,8 @@ module VagrantPlugins
#
# @return [VagrantPlugins::ProviderVirtualBox::Model::StorageController]
def get_primary_controller
ordered = sort { |a, b| a.boot_priority <=> b.boot_priority }
controller = ordered.detect do |c|
c.supported? && c.attachments.any? { |a| hdd?(a) }
end
ordered = find_all(&:supported?).sort_by(&:boot_priority)
controller = ordered.detect { |c| c.attachments.any? { |a| hdd?(a) } }
if !controller
raise Vagrant::Errors::VirtualBoxDisksNoSupportedControllers,
@ -62,8 +60,8 @@ module VagrantPlugins
#
# @return [VagrantPlugins::ProviderVirtualBox::Model::StorageController]
def get_dvd_controller
ordered = sort { |a, b| a.boot_priority <=> b.boot_priority }
controller = ordered.detect { |c| c.supported? }
ordered = find_all(&:supported?).sort_by(&:boot_priority)
controller = ordered.first
if !controller
raise Vagrant::Errors::VirtualBoxDisksNoSupportedControllers,
supported_types: supported_types.join(" ,")

View File

@ -91,7 +91,7 @@ describe VagrantPlugins::ProviderVirtualBox::Model::StorageControllerArray do
describe "#get_dvd_controller" do
context "with one controller" do
let(:controller) { double("controller", supported?: true) }
let(:controller) { double("controller", supported?: true, boot_priority: 1) }
before do
subject.replace([controller])
@ -111,9 +111,10 @@ describe VagrantPlugins::ProviderVirtualBox::Model::StorageControllerArray do
context "with multiple controllers" do
let(:controller1) { double("controller", supported?: true, boot_priority: 2) }
let(:controller2) { double("controller", supported?: true, boot_priority: 1) }
let(:controller3) { double("controller", supported?: false, boot_priority: nil) }
before do
subject.replace([controller1, controller2])
subject.replace([controller1, controller2, controller3])
end
it "returns the first supported controller" do