Do not try to set local_gb to -1 when the matched root device size is 0

Apparently, virtual floppies on some machines are represented as normal
block devices, but with size = 0. We should filter them out in ironic-lib,
but for now at least don't fail miserably.

Story: #2007907
Task: #40308
Change-Id: Ia96a9a8b85841612fb13616754bfdbf651b212d8
(cherry picked from commit 95e103d21c)
This commit is contained in:
Dmitry Tantsur 2020-07-09 16:15:28 +02:00
parent 4cb904fb13
commit 470c2f4119
3 changed files with 26 additions and 5 deletions

View File

@ -76,11 +76,17 @@ class RootDiskSelectionHook(base.ProcessingHook):
root_disk = introspection_data.get('root_disk') root_disk = introspection_data.get('root_disk')
if root_disk: if root_disk:
local_gb = root_disk['size'] // units.Gi local_gb = root_disk['size'] // units.Gi
if CONF.processing.disk_partitioning_spacing: if not local_gb:
local_gb -= 1 LOG.warning('The requested root disk is too small (smaller '
LOG.info('Root disk %(disk)s, local_gb %(local_gb)s GiB', 'than 1 GiB) or its size cannot be detected: %s',
{'disk': root_disk, 'local_gb': local_gb}, root_disk,
node_info=node_info, data=introspection_data) node_info=node_info, data=introspection_data)
else:
if CONF.processing.disk_partitioning_spacing:
local_gb -= 1
LOG.info('Root disk %(disk)s, local_gb %(local_gb)s GiB',
{'disk': root_disk, 'local_gb': local_gb},
node_info=node_info, data=introspection_data)
else: else:
local_gb = 0 local_gb = 0
LOG.info('No root device found, assuming a diskless node', LOG.info('No root device found, assuming a diskless node',

View File

@ -363,6 +363,7 @@ class TestRootDiskSelection(test_base.NodeTest):
{'model': 'Model 3', 'size': 10 * units.Gi, 'name': '/dev/sdc'}, {'model': 'Model 3', 'size': 10 * units.Gi, 'name': '/dev/sdc'},
{'model': 'Model 4', 'size': 4 * units.Gi, 'name': '/dev/sdd'}, {'model': 'Model 4', 'size': 4 * units.Gi, 'name': '/dev/sdd'},
{'model': 'Too Small', 'size': 1 * units.Gi, 'name': '/dev/sde'}, {'model': 'Too Small', 'size': 1 * units.Gi, 'name': '/dev/sde'},
{'model': 'Floppy', 'size': 0, 'name': '/dev/sdf'},
] ]
self.matched = self.inventory['disks'][2].copy() self.matched = self.inventory['disks'][2].copy()
self.node_info = mock.Mock(spec=node_cache.NodeInfo, self.node_info = mock.Mock(spec=node_cache.NodeInfo,
@ -434,6 +435,15 @@ class TestRootDiskSelection(test_base.NodeTest):
self.assertEqual(10, self.data['local_gb']) self.assertEqual(10, self.data['local_gb'])
self.node_info.update_properties.assert_called_once_with(local_gb='10') self.node_info.update_properties.assert_called_once_with(local_gb='10')
def test_zero_size(self):
self.node.properties['root_device'] = {'name': '/dev/sdf'}
self.hook.before_update(self.data, self.node_info)
self.assertEqual(self.inventory['disks'][5], self.data['root_disk'])
self.assertEqual(0, self.data['local_gb'])
self.node_info.update_properties.assert_called_once_with(local_gb='0')
def test_all_match(self): def test_all_match(self):
self.node.properties['root_device'] = {'size': 10, self.node.properties['root_device'] = {'size': 10,
'model': 'Model 3'} 'model': 'Model 3'}

View File

@ -0,0 +1,5 @@
---
fixes:
- |
No longer tries to set ``local_gb`` to -1 if the matched root device has
size of zero.