Browse Source

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)
tags/10.1.1
Dmitry Tantsur 2 months ago
parent
commit
470c2f4119
3 changed files with 26 additions and 5 deletions
  1. +11
    -5
      ironic_inspector/plugins/standard.py
  2. +10
    -0
      ironic_inspector/test/unit/test_plugins_standard.py
  3. +5
    -0
      releasenotes/notes/zero-size-55c4b4f2b9e8384d.yaml

+ 11
- 5
ironic_inspector/plugins/standard.py View File

@@ -76,11 +76,17 @@ class RootDiskSelectionHook(base.ProcessingHook):
root_disk = introspection_data.get('root_disk')
if root_disk:
local_gb = root_disk['size'] // units.Gi
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)
if not local_gb:
LOG.warning('The requested root disk is too small (smaller '
'than 1 GiB) or its size cannot be detected: %s',
root_disk,
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:
local_gb = 0
LOG.info('No root device found, assuming a diskless node',


+ 10
- 0
ironic_inspector/test/unit/test_plugins_standard.py View File

@@ -363,6 +363,7 @@ class TestRootDiskSelection(test_base.NodeTest):
{'model': 'Model 3', 'size': 10 * units.Gi, 'name': '/dev/sdc'},
{'model': 'Model 4', 'size': 4 * units.Gi, 'name': '/dev/sdd'},
{'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.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.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):
self.node.properties['root_device'] = {'size': 10,
'model': 'Model 3'}


+ 5
- 0
releasenotes/notes/zero-size-55c4b4f2b9e8384d.yaml 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.

Loading…
Cancel
Save