diff --git a/ironic_inspector/plugins/root_device_hint.py b/ironic_inspector/plugins/root_device_hint.py index c0b16cc8c..063c020eb 100644 --- a/ironic_inspector/plugins/root_device_hint.py +++ b/ironic_inspector/plugins/root_device_hint.py @@ -37,8 +37,20 @@ class RootDeviceHintHook(base.ProcessingHook): information about the created RAID disks. Using this plugin immediately before and after creating the root RAID device will solve the issue of root device hints. + + In cases where there's no RAID volume on the node, the standard plugin will + fail due to the missing local_gb value. This plugin fakes the missing + value, until it's corrected during later runs. Note, that for this to work + the plugin needs to take precedence over the standard plugin. """ + def before_processing(self, node_info): + """Adds fake local_gb value if it's missing from node_info.""" + if not node_info.get('local_gb'): + LOG.info(_LI('No volume is found on the node. Adding a fake ' + 'value for "local_gb"')) + node_info['local_gb'] = 1 + def before_update(self, node, ports, node_info): if 'block_devices' not in node_info: LOG.warning(_LW('No block device was received from ramdisk')) diff --git a/ironic_inspector/test/test_plugins_root_device_hint.py b/ironic_inspector/test/test_plugins_root_device_hint.py index c14124272..06382135c 100644 --- a/ironic_inspector/test/test_plugins_root_device_hint.py +++ b/ironic_inspector/test/test_plugins_root_device_hint.py @@ -21,6 +21,18 @@ class TestRootDeviceHint(test_base.NodeTest): super(TestRootDeviceHint, self).setUp() self.hook = root_device_hint.RootDeviceHintHook() + def test_missing_local_gb(self): + node_info = {} + self.hook.before_processing(node_info) + + self.assertEqual(1, node_info['local_gb']) + + def test_local_gb_not_changes(self): + node_info = {'local_gb': 42} + self.hook.before_processing(node_info) + + self.assertEqual(42, node_info['local_gb']) + def test_no_previous_block_devices(self): node_info = {'block_devices': {'serials': ['foo', 'bar']}} node_patches, _ = self.hook.before_update(self.node, None, node_info)