Merge pull request #11867 from marxarelli/fix/storage-controller-array-sort

Avoid sorting of controllers with nil boot_priority
This commit is contained in:
Chris Roberts 2020-09-22 11:36:02 -07:00 committed by GitHub
commit 7103be62b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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