Fix CPU count returned by introspection in Ironic iDRAC driver

If list_cpus in dracclient, it returns below values -

[CPU(id='CPU.Socket.1', cores=14, ht__enabled=True),
CPU(id='CPU.Socket.2', cores=14, ht_enabled=True)]

Each CPU socket has cores with hyperthreading enabled, so if we
calculate the cpu per socket, we will get actual cpu count per socket,
So objective of this patch to fetch actual CPU's per socket and sum it

Story: #2004155
Change-Id: Ia86b0462a3e73af7a2ce0a6439286f7071f74caa
(cherry picked from commit 3e1fe5f7e4)
This commit is contained in:
digambar 2018-10-30 11:57:38 -05:00 committed by Richard Pioso
parent a1c8f31cdf
commit 410f73e9b0
3 changed files with 41 additions and 5 deletions

View File

@ -80,7 +80,8 @@ class DracInspect(base.InspectInterface):
[memory.size_mb for memory in client.list_memory()])
cpus = client.list_cpus()
if cpus:
properties['cpus'] = len(cpus)
properties['cpus'] = sum(
[self._calculate_cpus(cpu) for cpu in cpus])
properties['cpu_arch'] = 'x86_64' if cpus[0].arch64 else 'x86'
virtual_disks = client.list_virtual_disks()
@ -148,3 +149,15 @@ class DracInspect(base.InspectInterface):
for disk in disks:
if disk.size_mb >= min_size_required_mb:
return disk
def _calculate_cpus(self, cpu):
"""Find actual CPU count.
:param cpu: Pass cpu.
:returns: returns total cpu count.
"""
if cpu.ht_enabled:
return cpu.cores * 2
else:
return cpu.cores

View File

@ -67,7 +67,7 @@ class DracInspectionTestCase(db_base.DbTestCase):
'speed': 2400,
'model': 'Intel(R) Xeon(R) CPU E5-2620 v3 @ 2.40GHz',
'state': 'ok',
'ht_enabled': True,
'ht_enabled': False,
'turbo_enabled': True,
'vt_enabled': True,
'arch64': True}]
@ -145,7 +145,7 @@ class DracInspectionTestCase(db_base.DbTestCase):
expected_node_properties = {
'memory_mb': 32768,
'local_gb': 1116,
'cpus': 2,
'cpus': 18,
'cpu_arch': 'x86_64'}
mock_client = mock.Mock()
mock_get_drac_client.return_value = mock_client
@ -188,7 +188,7 @@ class DracInspectionTestCase(db_base.DbTestCase):
expected_node_properties = {
'memory_mb': 32768,
'local_gb': 279,
'cpus': 2,
'cpus': 18,
'cpu_arch': 'x86_64'}
mock_client = mock.Mock()
mock_get_drac_client.return_value = mock_client
@ -233,7 +233,7 @@ class DracInspectionTestCase(db_base.DbTestCase):
expected_node_properties = {
'memory_mb': 32768,
'local_gb': 1116,
'cpus': 2,
'cpus': 18,
'cpu_arch': 'x86_64'}
mock_client = mock.Mock()
mock_get_drac_client.return_value = mock_client
@ -259,3 +259,19 @@ class DracInspectionTestCase(db_base.DbTestCase):
self.physical_disks)
self.assertEqual(285888, root_disk.size_mb)
def test__calculate_cpus(self):
with task_manager.acquire(self.context, self.node.uuid,
shared=True) as task:
cpu = task.driver.inspect._calculate_cpus(
self.cpus[0])
self.assertEqual(12, cpu)
def test__calculate_cpus_without_ht_enabled(self):
with task_manager.acquire(self.context, self.node.uuid,
shared=True) as task:
cpu = task.driver.inspect._calculate_cpus(
self.cpus[1])
self.assertEqual(6, cpu)

View File

@ -0,0 +1,7 @@
---
fixes:
- |
Fixes a bug where the number of CPU sockets was being returned by the
``idrac`` hardware type during introspection, instead of the number of
virtual CPUs. See bug `2004155
<https://storyboard.openstack.org/#!/story/2004155>`_ for details.