mirror of https://git.48k.eu/ogclient
live: hw_inventory: fix empty memory bank bug
When a client's hardware presents an empty memory bank and invalid call to _bytes_to_human is performed because None is passed as a parameter. size = _bytes_to_human(obj.get('size', None)) Fix this by checking if 'size' is present in the JSON output from lshw. If size is present then map the bytes to a human readable string using _bytes_to_human, if no size is present then use 'Empty slot' to indicate that the memory bank is not being used.master
parent
49038f125a
commit
39c13287c5
|
@ -64,7 +64,7 @@ class HardwareInventory():
|
|||
def _bytes_to_human(size):
|
||||
suffixes = ['B', 'MiB', 'GiB', 'TiB']
|
||||
if type(size) is not int:
|
||||
raise TypeError('Invalid type')
|
||||
raise TypeError(f'Invalid type in _bytes_to_human, got: {size} {type(size)}')
|
||||
for exponent, suffix in enumerate(suffixes, start=1):
|
||||
conv = size / (1024**exponent)
|
||||
if conv < 1024:
|
||||
|
@ -106,11 +106,14 @@ def _process_core_cpu(inventory, obj):
|
|||
|
||||
def _process_core_mem_bank(inventory, obj):
|
||||
slot = obj.get('slot', 'Unknown slot')
|
||||
size = _bytes_to_human(obj.get('size', None))
|
||||
if size:
|
||||
mem = ' '.join([obj.get('vendor', 'Unknown vendor'), obj.get('product', 'Unknown product'), size, f'({slot})'])
|
||||
mem_elem = HardwareElement(HardwareType.MEMORY, mem)
|
||||
inventory.add_element(mem_elem)
|
||||
if 'size' in obj:
|
||||
size = obj['size']
|
||||
human_size = _bytes_to_human(size)
|
||||
mem = ' '.join([obj.get('vendor', 'Unknown vendor'), obj.get('product', 'Unknown product'), human_size, f'({slot})'])
|
||||
else:
|
||||
mem = ' '.join([obj.get('vendor', 'Unknown vendor'), obj.get('product', 'Unknown product'), 'Empty slot', f'({slot})'])
|
||||
mem_elem = HardwareElement(HardwareType.MEMORY, mem)
|
||||
inventory.add_element(mem_elem)
|
||||
|
||||
|
||||
def _process_core_mem(inventory, obj):
|
||||
|
|
Loading…
Reference in New Issue