From 143fa4d0d6ef6a9d8d2e543263ed19ff2123578b Mon Sep 17 00:00:00 2001 From: Dmitry Tantsur Date: Fri, 14 Jun 2019 10:10:02 +0200 Subject: [PATCH] Stop failing on missing memory or CPU They have been optional for scheduling since Pike and are not used by Nova at all since Stein. Change-Id: Idd4d727d3bbcbb8898a0d989d3c496070bc41d8a (cherry picked from commit 463d0a2f5412c49a5e5ff567386794e8b0bbce97) --- ironic_inspector/plugins/standard.py | 28 ++++++--------- .../test/unit/test_plugins_standard.py | 36 ++++++++++++++++++- ironic_inspector/utils.py | 10 ++---- .../notes/cpu-memory-cfdc72b625780871.yaml | 6 ++++ 4 files changed, 55 insertions(+), 25 deletions(-) create mode 100644 releasenotes/notes/cpu-memory-cfdc72b625780871.yaml diff --git a/ironic_inspector/plugins/standard.py b/ironic_inspector/plugins/standard.py index cfaeb37e5..032c20414 100644 --- a/ironic_inspector/plugins/standard.py +++ b/ironic_inspector/plugins/standard.py @@ -100,39 +100,33 @@ class SchedulerHook(base.ProcessingHook): """Update node with scheduler properties.""" inventory = utils.get_inventory(introspection_data, node_info=node_info) - errors = [] - try: introspection_data['cpus'] = int(inventory['cpu']['count']) introspection_data['cpu_arch'] = six.text_type( inventory['cpu']['architecture']) except (KeyError, ValueError, TypeError): - errors.append(_('malformed or missing CPU information: %s') % - inventory.get('cpu')) + LOG.warning('malformed or missing CPU information: %s', + inventory.get('cpu')) try: introspection_data['memory_mb'] = int( inventory['memory']['physical_mb']) except (KeyError, ValueError, TypeError): - errors.append(_('malformed or missing memory information: %s; ' - 'introspection requires physical memory size ' - 'from dmidecode') % inventory.get('memory')) + LOG.warning('malformed or missing memory information: %s; ' + 'introspection requires physical memory size ' + 'from dmidecode', inventory.get('memory')) - if errors: - raise utils.Error(_('The following problems encountered: %s') % - '; '.join(errors), - node_info=node_info, data=introspection_data) - - LOG.info('Discovered data: CPUs: %(cpus)s %(cpu_arch)s, ' - 'memory %(memory_mb)s MiB', + LOG.info('Discovered data: CPUs: count %(cpus)s, architecture ' + '%(cpu_arch)s, memory %(memory_mb)s MiB', {key: introspection_data.get(key) for key in self.KEYS}, node_info=node_info, data=introspection_data) overwrite = CONF.processing.overwrite_existing properties = {key: str(introspection_data[key]) - for key in self.KEYS if overwrite or - not node_info.node().properties.get(key)} - node_info.update_properties(**properties) + for key in self.KEYS if introspection_data.get(key) and + (overwrite or not node_info.node().properties.get(key))} + if properties: + node_info.update_properties(**properties) class ValidateInterfacesHook(base.ProcessingHook): diff --git a/ironic_inspector/test/unit/test_plugins_standard.py b/ironic_inspector/test/unit/test_plugins_standard.py index 5a355aad2..f23b4b09d 100644 --- a/ironic_inspector/test/unit/test_plugins_standard.py +++ b/ironic_inspector/test/unit/test_plugins_standard.py @@ -64,6 +64,40 @@ class TestSchedulerHook(test_base.NodeTest): self.hook.before_update(self.data, self.node_info) self.assertCalledWithPatch(patch, mock_patch) + @mock.patch.object(node_cache.NodeInfo, 'patch') + def test_missing_cpu(self, mock_patch): + self.data['inventory']['cpu'] = {'count': 'none'} + patch = [ + {'path': '/properties/memory_mb', 'value': '12288', 'op': 'add'}, + ] + + self.hook.before_update(self.data, self.node_info) + self.assertCalledWithPatch(patch, mock_patch) + + @mock.patch.object(node_cache.NodeInfo, 'patch') + def test_missing_memory(self, mock_patch): + # We require physical_mb, not total + self.data['inventory']['memory'] = {'total': 42} + patch = [ + {'path': '/properties/cpus', 'value': '4', 'op': 'add'}, + {'path': '/properties/cpu_arch', 'value': 'x86_64', 'op': 'add'}, + ] + + self.hook.before_update(self.data, self.node_info) + self.assertCalledWithPatch(patch, mock_patch) + + @mock.patch.object(node_cache.NodeInfo, 'patch') + def test_no_data(self, mock_patch): + self.data['inventory']['cpu'] = {} + self.data['inventory']['memory'] = {} + self.hook.before_update(self.data, self.node_info) + + del self.data['inventory']['cpu'] + del self.data['inventory']['memory'] + self.hook.before_update(self.data, self.node_info) + + self.assertFalse(mock_patch.called) + class TestValidateInterfacesHookLoad(test_base.NodeTest): def test_hook_loadable_by_name(self): @@ -87,7 +121,7 @@ class TestValidateInterfacesHookBeforeProcessing(test_base.NodeTest): self.hook.before_processing, {'inventory': {}}) del self.inventory['interfaces'] self.assertRaisesRegex(utils.Error, - 'interfaces key is missing or empty', + 'No network interfaces', self.hook.before_processing, self.data) def test_only_pxe(self): diff --git a/ironic_inspector/utils.py b/ironic_inspector/utils.py index b0cfc2168..e6f63f576 100644 --- a/ironic_inspector/utils.py +++ b/ironic_inspector/utils.py @@ -202,9 +202,6 @@ def get_valid_macs(data): if m.get('mac')] -_INVENTORY_MANDATORY_KEYS = ('memory', 'cpu', 'interfaces') - - def get_inventory(data, node_info=None): """Get and validate the hardware inventory from introspection data.""" inventory = data.get('inventory') @@ -213,10 +210,9 @@ def get_inventory(data, node_info=None): raise Error(_('Hardware inventory is empty or missing'), data=data, node_info=node_info) - for key in _INVENTORY_MANDATORY_KEYS: - if not inventory.get(key): - raise Error(_('Invalid hardware inventory: %s key is missing ' - 'or empty') % key, data=data, node_info=node_info) + if not inventory.get('interfaces'): + raise Error(_('No network interfaces provided in the inventory'), + data=data, node_info=node_info) if not inventory.get('disks'): LOG.info('No disks were detected in the inventory, assuming this ' diff --git a/releasenotes/notes/cpu-memory-cfdc72b625780871.yaml b/releasenotes/notes/cpu-memory-cfdc72b625780871.yaml new file mode 100644 index 000000000..9420a02e9 --- /dev/null +++ b/releasenotes/notes/cpu-memory-cfdc72b625780871.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + No longer fails introspection if memory or CPU information is not provided + in the inventory. These are no longer required for scheduling, + introspection should not require them either.