From 65fdef26dc8b99cae8383f416f13c75d1c6a8a6c Mon Sep 17 00:00:00 2001 From: Naohiro Tamura Date: Thu, 28 Apr 2016 10:11:01 +0900 Subject: [PATCH] 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 --- scciclient/irmc/scci.py | 3 ++- scciclient/tests/irmc/fixtures/irmc_report_ng.xml | 4 ++++ scciclient/tests/irmc/test_scci.py | 13 +++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/scciclient/irmc/scci.py b/scciclient/irmc/scci.py index a9f614e..5079f0f 100644 --- a/scciclient/irmc/scci.py +++ b/scciclient/irmc/scci.py @@ -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' diff --git a/scciclient/tests/irmc/fixtures/irmc_report_ng.xml b/scciclient/tests/irmc/fixtures/irmc_report_ng.xml index 313e02e..14658f3 100644 --- a/scciclient/tests/irmc/fixtures/irmc_report_ng.xml +++ b/scciclient/tests/irmc/fixtures/irmc_report_ng.xml @@ -85,6 +85,10 @@ 2048 20480 + + CPU2 + 0 + 8192 diff --git a/scciclient/tests/irmc/test_scci.py b/scciclient/tests/irmc/test_scci.py index bfbe458..ae958c3 100644 --- a/scciclient/tests/irmc/test_scci.py +++ b/scciclient/tests/irmc/test_scci.py @@ -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)