Add secondary sorting by name when guessing root disk

As some BIOSes try to boot only from the "first" disk, Ironic
should order potential disks not only by size, but also by name.
This patch proposes to add secondary sorting by device name when
identifying the root disk.

Change-Id: I4017c839eeb9d00d2b4ad5b90e4e9b65b74296c7
Story: #2004976
Task: #29434
This commit is contained in:
Arne Wiebalck
2019-02-06 19:12:57 +01:00
parent 1684ad707c
commit fb74b55606
4 changed files with 81 additions and 6 deletions

@ -290,12 +290,15 @@ class AccumulatedFailures(object):
def guess_root_disk(block_devices, min_size_required=4 * units.Gi):
"""Find suitable disk provided that root device hints are not given.
If no hints are passed find the first device larger than min_size_required,
assume it is the OS disk
If no hints are passed, order the devices by size (primary key) and
name (secondary key), and return the first device larger than
min_size_required as the root disk.
"""
# TODO(russellhaering): This isn't a valid assumption in
# all cases, is there a more reasonable default behavior?
block_devices.sort(key=lambda device: device.size)
# NOTE(arne_wiebalck): Order devices by size and name. Secondary
# ordering by name is done to increase chances of successful
# booting for BIOSes which try only one (the "first") disk.
block_devices.sort(key=lambda device: (device.size, device.name))
if not block_devices or block_devices[-1].size < min_size_required:
raise errors.DeviceNotFound(
"No suitable device was found "