Update get_essential_properties() for empty CPU socket

This patch updates get_essential_properties() so that "'NoneType'
object has no attribute 'text'" exception is not thrown when one of
CPU sockets is empty in bare metal server.

Change-Id: Ib5a8f0cd93c03049d1810678fc4ddfbd69b0b499
This commit is contained in:
Naohiro Tamura
2016-04-28 10:11:01 +09:00
parent b8bc3d8c1f
commit 65fdef26dc
3 changed files with 19 additions and 1 deletions

View File

@@ -477,7 +477,8 @@ def get_essential_properties(report, prop_keys):
[int(int(size.text) / 1000)
for size in report.findall('.//PhysicalDrive/PhysicalSize')])
v['cpus'] = sum([int(cpu.find('./CoreNumber').text)
for cpu in report.find('./System/Processor')])
for cpu in report.find('./System/Processor')
if cpu.find('./CoreNumber') is not None])
# v['cpus'] = sum([int(cpu.find('./LogicalCpuNumber').text)
# for cpu in report.find('./System/Processor')])
v['cpu_arch'] = 'x86_64'

View File

@@ -85,6 +85,10 @@
<Level2CacheSize Unit="KByte">2048</Level2CacheSize>
<Level3CacheSize Unit="KByte">20480</Level3CacheSize>
</CPU>
<CPU Boot="false">
<SocketDesignation>CPU2</SocketDesignation>
<Status Description="empty">0</Status>
</CPU>
</Processor>
<Memory Schema="2">
<Installed>8192</Installed>

View File

@@ -672,3 +672,16 @@ class SCCITestCase(testtools.TestCase):
self.report_ok_xml, ESSENTIAL_PROPERTIES_KEYS)
self.assertEqual(expected, result)
def test_get_essential_properties_empty_cpu_socket(self):
ESSENTIAL_PROPERTIES_KEYS = {
'memory_mb', 'local_gb', 'cpus', 'cpu_arch'}
expected = {'memory_mb': 8192,
'local_gb': 190,
'cpus': 16,
'cpu_arch': 'x86_64'}
result = scci.get_essential_properties(
self.report_ng_xml, ESSENTIAL_PROPERTIES_KEYS)
self.assertEqual(expected, result)