Merge "Fixes physical memory fetching for aarch64"

This commit is contained in:
Zuul 2019-08-12 16:02:44 +00:00 committed by Gerrit Code Review
commit 6b778e171b
3 changed files with 120 additions and 0 deletions

View File

@ -885,6 +885,11 @@ class GenericHardwareManager(HardwareManager):
if sys_child['id'] == 'core':
for core_child in sys_child['children']:
if _MEMORY_ID_RE.match(core_child['id']):
if (not core_child.get("children") and
core_child.get('size')):
value = ("%(size)s %(units)s" % core_child)
physical += int(UNIT_CONVERTER(value).to
('MB').magnitude)
for bank in core_child.get('children', ()):
if bank.get('size'):
value = ("%(size)s %(units)s" % bank)

View File

@ -570,6 +570,105 @@ LSHW_JSON_OUTPUT_V2 = ("""
}
""", "")
LSHW_JSON_OUTPUT_ARM64 = ("""
{
"id" : "debian",
"class" : "system",
"claimed" : true,
"description" : "Computer",
"width" : 64,
"capabilities" : {
"cp15_barrier" : true,
"setend" : true,
"swp" : true
},
"children" : [
{
"id" : "core",
"class" : "bus",
"claimed" : true,
"description" : "Motherboard",
"physid" : "0",
"children" : [
{
"id" : "memory",
"class" : "memory",
"claimed" : true,
"description" : "System memory",
"physid" : "0",
"units" : "bytes",
"size" : 4143972352
},
{
"id" : "cpu:0",
"class" : "processor",
"claimed" : true,
"physid" : "1",
"businfo" : "cpu@0",
"capabilities" : {
"fp" : "Floating point instructions",
"asimd" : "Advanced SIMD",
"evtstrm" : "Event stream",
"aes" : "AES instructions",
"pmull" : "PMULL instruction",
"sha1" : "SHA1 instructions",
"sha2" : "SHA2 instructions",
"crc32" : "CRC extension",
"cpuid" : true
}
},
{
"id" : "pci:0",
"class" : "bridge",
"claimed" : true,
"handle" : "PCIBUS:0002:e9",
"physid" : "100",
"businfo" : "pci@0002:e8:00.0",
"version" : "01",
"width" : 32,
"clock" : 33000000,
"configuration" : {
"driver" : "pcieport"
},
"capabilities" : {
"pci" : true,
"pm" : "Power Management",
"msi" : "Message Signalled Interrupts",
"pciexpress" : "PCI Express",
"bus_master" : "bus mastering",
"cap_list" : "PCI capabilities listing"
}
}
]
},
{
"id" : "network:0",
"class" : "network",
"claimed" : true,
"description" : "Ethernet interface",
"physid" : "2",
"logicalname" : "enahisic2i2",
"serial" : "d0:ef:c1:e9:bf:33",
"configuration" : {
"autonegotiation" : "off",
"broadcast" : "yes",
"driver" : "hns",
"driverversion" : "2.0",
"firmware" : "N/A",
"link" : "no",
"multicast" : "yes",
"port" : "fibre"
},
"capabilities" : {
"ethernet" : true,
"physical" : "Physical interface",
"fibre" : "optical fibre"
}
}
]
}
""", "")
SMARTCTL_NORMAL_OUTPUT = ("""
smartctl 6.2 2017-02-27 r4394 [x86_64-linux-3.10.0-693.21.1.el7.x86_64] (local build)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org
@ -1405,6 +1504,16 @@ class TestGenericHardwareManager(base.IronicAgentTest):
self.assertEqual(3952 * 1024 * 1024, mem.total)
self.assertIsNone(mem.physical_mb)
@mock.patch('psutil.virtual_memory', autospec=True)
@mock.patch.object(utils, 'execute', autospec=True)
def test_get_memory_arm64_lshw(self, mocked_execute, mocked_psutil):
mocked_psutil.return_value.total = 3952 * 1024 * 1024
mocked_execute.return_value = LSHW_JSON_OUTPUT_ARM64
mem = self.hardware.get_memory()
self.assertEqual(3952 * 1024 * 1024, mem.total)
self.assertEqual(3952, mem.physical_mb)
@mock.patch('ironic_python_agent.netutils.get_hostname', autospec=True)
def test_list_hardware_info(self, mocked_get_hostname):
self.hardware.list_network_interfaces = mock.Mock()

View File

@ -0,0 +1,6 @@
---
fixes:
- |
Fixes issue that 0 physical memory calculated for aarch64. Since output
for aarch64 `lshw -quiet -json` is a bit different from x86_64. This fix
is compatible with both x86_64 and arm64.