diff --git a/ironic_inspector/plugins/standard.py b/ironic_inspector/plugins/standard.py index 8c9befe24..83601d799 100644 --- a/ironic_inspector/plugins/standard.py +++ b/ironic_inspector/plugins/standard.py @@ -53,6 +53,15 @@ class RootDiskSelectionHook(base.ProcessingHook): 'as an inspection ramdisk'), node_info=node_info, data=introspection_data) + if 'size' in hints: + # Special case to match IPA behaviour + try: + hints['size'] = int(hints['size']) + except (TypeError, ValueError): + raise utils.Error(_('Invalid root device size hint, expected ' + 'an integer, got %s') % hints['size'], + node_info=node_info, data=introspection_data) + disks = inventory.get('disks', []) if not disks: raise utils.Error(_('No disks found'), diff --git a/ironic_inspector/test/unit/test_plugins_standard.py b/ironic_inspector/test/unit/test_plugins_standard.py index 2892a88f5..b5f76b363 100644 --- a/ironic_inspector/test/unit/test_plugins_standard.py +++ b/ironic_inspector/test/unit/test_plugins_standard.py @@ -388,6 +388,19 @@ class TestRootDiskSelection(test_base.NodeTest): self.assertNotIn('local_gb', self.data) self.assertNotIn('root_disk', self.data) + def test_size_string(self): + self.node.properties['root_device'] = {'size': '10'} + self.hook.before_update(self.data, self.node_info) + self.assertEqual(self.matched, self.data['root_disk']) + + def test_size_invalid(self): + for bad_size in ('foo', None, {}): + self.node.properties['root_device'] = {'size': bad_size} + self.assertRaisesRegexp(utils.Error, + 'Invalid root device size hint', + self.hook.before_update, + self.data, self.node_info) + class TestRamdiskError(test_base.BaseTest): def setUp(self): diff --git a/releasenotes/notes/size-hint-ea2a264468e1fcb7.yaml b/releasenotes/notes/size-hint-ea2a264468e1fcb7.yaml new file mode 100644 index 000000000..e75afa397 --- /dev/null +++ b/releasenotes/notes/size-hint-ea2a264468e1fcb7.yaml @@ -0,0 +1,4 @@ +--- +fixes: + - The "size" root device hint is now always converted to an integer for + consistency with IPA.