Collect processor, memory and BIOS output of dmidecode - follow-up
Fixes nits, modifies unit tests.
This is a follow-up to commit c5544fb7a0
.
Change-Id: Ibca82cc6e32311b1ff0be7137d8392f63e12639b
Closes-Bug: #1635057
This commit is contained in:
parent
e626cd744f
commit
3ab779c897
@ -40,7 +40,7 @@ def collect_dmidecode_info(data, failures):
|
||||
try:
|
||||
data['dmi'] = parse_dmi(shret)
|
||||
except (ValueError, IndexError) as exc:
|
||||
LOG.warning('Failed to collect dmidecode info %s:', exc)
|
||||
LOG.warning('Failed to collect dmidecode info: %s', exc)
|
||||
|
||||
|
||||
def parse_dmi(data):
|
||||
@ -69,28 +69,30 @@ def parse_dmi(data):
|
||||
if not len(infoblock):
|
||||
continue
|
||||
|
||||
if infoblock.startswith('Handle 0x'):
|
||||
try:
|
||||
# Determine DMI type value. Handle line will look like this:
|
||||
# Handle 0x0018, DMI type 17, 27 bytes
|
||||
dmi_type = int(infoblock.split(',', 2)[1].strip()[
|
||||
len('DMI type'):])
|
||||
except (ValueError, IndexError) as exc:
|
||||
LOG.warning('Failed to parse Handle type in dmi output: %s',
|
||||
exc)
|
||||
continue
|
||||
if not infoblock.startswith('Handle 0x'):
|
||||
continue
|
||||
|
||||
if dmi_type in TYPE.values():
|
||||
sectiondata = _parse_handle_block(infoblock)
|
||||
try:
|
||||
# Determine DMI type value. Handle line will look like this:
|
||||
# Handle 0x0018, DMI type 17, 27 bytes
|
||||
dmi_type = int(infoblock.split(',', 2)[1].strip()[
|
||||
len('DMI type'):])
|
||||
except (ValueError, IndexError) as exc:
|
||||
LOG.warning('Failed to parse Handle type in dmi output: %s',
|
||||
exc)
|
||||
continue
|
||||
|
||||
if dmi_type == TYPE['bios']:
|
||||
dmi_info['bios'] = sectiondata
|
||||
elif dmi_type == TYPE['cpu']:
|
||||
dmi_info['cpu'].append(sectiondata)
|
||||
elif dmi_type == TYPE['memory']:
|
||||
memorydata.append(sectiondata)
|
||||
elif dmi_type == TYPE['devices']:
|
||||
devicedata.append(sectiondata)
|
||||
if dmi_type in TYPE.values():
|
||||
sectiondata = _parse_handle_block(infoblock)
|
||||
|
||||
if dmi_type == TYPE['bios']:
|
||||
dmi_info['bios'] = sectiondata
|
||||
elif dmi_type == TYPE['cpu']:
|
||||
dmi_info['cpu'].append(sectiondata)
|
||||
elif dmi_type == TYPE['memory']:
|
||||
memorydata.append(sectiondata)
|
||||
elif dmi_type == TYPE['devices']:
|
||||
devicedata.append(sectiondata)
|
||||
|
||||
return _save_data(dmi_info, memorydata, devicedata)
|
||||
|
||||
@ -124,7 +126,7 @@ def _save_data(dmi_info, memorydata, devicedata):
|
||||
dmi_info['memory'] = memorydata[0]
|
||||
dmi_info['memory']['Number Of Devices'] = device_count
|
||||
dmi_info['memory'].pop('Handle')
|
||||
except (KeyError) as exc:
|
||||
except KeyError as exc:
|
||||
LOG.warning('Failed to process memory dmi data: %s', exc)
|
||||
raise
|
||||
|
||||
|
@ -668,12 +668,26 @@ class TestCollectDmidecodeInfo(base.IronicAgentTest):
|
||||
ret = dmi_inspector._save_data(dmi_info, mem, devices)
|
||||
self.assertEqual(expected, ret)
|
||||
|
||||
def test_save_data_error_number_of_devices(self):
|
||||
dmi_info = {}
|
||||
dmi_info['bios'] = {}
|
||||
dmi_info['cpu'] = []
|
||||
dmi_info['memory'] = {}
|
||||
dmi_info['memory']['devices'] = {}
|
||||
|
||||
self.assertRaises(KeyError,
|
||||
dmi_inspector._save_data,
|
||||
dmi_info,
|
||||
[{'foo': 'bar', 'Handle': '0x10'}],
|
||||
[{'bar': 'foo'}, {'bar': 'foo'}])
|
||||
|
||||
def test_save_data_error_handle(self):
|
||||
dmi_info = {}
|
||||
dmi_info['bios'] = {}
|
||||
dmi_info['cpu'] = []
|
||||
dmi_info['memory'] = {}
|
||||
dmi_info['memory']['devices'] = {}
|
||||
|
||||
self.assertRaises(KeyError,
|
||||
dmi_inspector._save_data,
|
||||
dmi_info,
|
||||
|
Loading…
Reference in New Issue
Block a user