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
This commit is contained in:
Dmitry Tantsur 2019-06-14 10:10:02 +02:00
parent cebeb82006
commit 463d0a2f54
4 changed files with 55 additions and 25 deletions

View File

@ -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):

View File

@ -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):

View File

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

View File

@ -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.