summaryrefslogtreecommitdiff
path: root/ironic_python_agent/utils.py
diff options
context:
space:
mode:
authorArne Wiebalck <Arne.Wiebalck@cern.ch>2019-02-06 19:12:57 +0100
committerArne Wiebalck <Arne.Wiebalck@cern.ch>2019-02-11 17:53:47 +0100
commitfb74b556067536b65f2e244f46c6ee9c5c556e1d (patch)
treeba4b175bd2604c7df477b3a24102480eb4690a0b /ironic_python_agent/utils.py
parent1684ad707c7ab21536bb3a4c0a31d160c6107084 (diff)
downloadironic-python-agent-fb74b556067536b65f2e244f46c6ee9c5c556e1d.tar.gz
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
Diffstat (limited to 'ironic_python_agent/utils.py')
-rw-r--r--ironic_python_agent/utils.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/ironic_python_agent/utils.py b/ironic_python_agent/utils.py
index 2bc2bfa1..4621ff8d 100644
--- a/ironic_python_agent/utils.py
+++ b/ironic_python_agent/utils.py
@@ -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 "