Skip to content

Commit 3ab779c

Browse files
committed
Collect processor, memory and BIOS output of dmidecode - follow-up
Fixes nits, modifies unit tests. This is a follow-up to commit c5544fb. Change-Id: Ibca82cc6e32311b1ff0be7137d8392f63e12639b Closes-Bug: #1635057
1 parent e626cd7 commit 3ab779c

2 files changed

Lines changed: 40 additions & 24 deletions

File tree

ironic_python_agent/dmi_inspector.py

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def collect_dmidecode_info(data, failures):
4040
try:
4141
data['dmi'] = parse_dmi(shret)
4242
except (ValueError, IndexError) as exc:
43-
LOG.warning('Failed to collect dmidecode info %s:', exc)
43+
LOG.warning('Failed to collect dmidecode info: %s', exc)
4444

4545

4646
def parse_dmi(data):
@@ -69,28 +69,30 @@ def parse_dmi(data):
6969
if not len(infoblock):
7070
continue
7171

72-
if infoblock.startswith('Handle 0x'):
73-
try:
74-
# Determine DMI type value. Handle line will look like this:
75-
# Handle 0x0018, DMI type 17, 27 bytes
76-
dmi_type = int(infoblock.split(',', 2)[1].strip()[
77-
len('DMI type'):])
78-
except (ValueError, IndexError) as exc:
79-
LOG.warning('Failed to parse Handle type in dmi output: %s',
80-
exc)
81-
continue
82-
83-
if dmi_type in TYPE.values():
84-
sectiondata = _parse_handle_block(infoblock)
85-
86-
if dmi_type == TYPE['bios']:
87-
dmi_info['bios'] = sectiondata
88-
elif dmi_type == TYPE['cpu']:
89-
dmi_info['cpu'].append(sectiondata)
90-
elif dmi_type == TYPE['memory']:
91-
memorydata.append(sectiondata)
92-
elif dmi_type == TYPE['devices']:
93-
devicedata.append(sectiondata)
72+
if not infoblock.startswith('Handle 0x'):
73+
continue
74+
75+
try:
76+
# Determine DMI type value. Handle line will look like this:
77+
# Handle 0x0018, DMI type 17, 27 bytes
78+
dmi_type = int(infoblock.split(',', 2)[1].strip()[
79+
len('DMI type'):])
80+
except (ValueError, IndexError) as exc:
81+
LOG.warning('Failed to parse Handle type in dmi output: %s',
82+
exc)
83+
continue
84+
85+
if dmi_type in TYPE.values():
86+
sectiondata = _parse_handle_block(infoblock)
87+
88+
if dmi_type == TYPE['bios']:
89+
dmi_info['bios'] = sectiondata
90+
elif dmi_type == TYPE['cpu']:
91+
dmi_info['cpu'].append(sectiondata)
92+
elif dmi_type == TYPE['memory']:
93+
memorydata.append(sectiondata)
94+
elif dmi_type == TYPE['devices']:
95+
devicedata.append(sectiondata)
9496

9597
return _save_data(dmi_info, memorydata, devicedata)
9698

@@ -124,7 +126,7 @@ def _save_data(dmi_info, memorydata, devicedata):
124126
dmi_info['memory'] = memorydata[0]
125127
dmi_info['memory']['Number Of Devices'] = device_count
126128
dmi_info['memory'].pop('Handle')
127-
except (KeyError) as exc:
129+
except KeyError as exc:
128130
LOG.warning('Failed to process memory dmi data: %s', exc)
129131
raise
130132

ironic_python_agent/tests/unit/test_dmi_inspector.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,12 +668,26 @@ def test_save_data(self):
668668
ret = dmi_inspector._save_data(dmi_info, mem, devices)
669669
self.assertEqual(expected, ret)
670670

671+
def test_save_data_error_number_of_devices(self):
672+
dmi_info = {}
673+
dmi_info['bios'] = {}
674+
dmi_info['cpu'] = []
675+
dmi_info['memory'] = {}
676+
dmi_info['memory']['devices'] = {}
677+
671678
self.assertRaises(KeyError,
672679
dmi_inspector._save_data,
673680
dmi_info,
674681
[{'foo': 'bar', 'Handle': '0x10'}],
675682
[{'bar': 'foo'}, {'bar': 'foo'}])
676683

684+
def test_save_data_error_handle(self):
685+
dmi_info = {}
686+
dmi_info['bios'] = {}
687+
dmi_info['cpu'] = []
688+
dmi_info['memory'] = {}
689+
dmi_info['memory']['devices'] = {}
690+
677691
self.assertRaises(KeyError,
678692
dmi_inspector._save_data,
679693
dmi_info,

0 commit comments

Comments
 (0)