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

This commit is contained in:
Zuul 2020-07-20 13:22:22 +00:00 committed by Gerrit Code Review
commit 5a9e5e101d
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')
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',

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'}

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.