From b49ec83bcde10ca6e0066ef5f01b636e11cb4d25 Mon Sep 17 00:00:00 2001 From: "Jose M. Guisado" Date: Wed, 18 Oct 2023 13:05:39 +0200 Subject: live: hw_inventory: fix empty pci storage size bug When a client's hardware presents an empty pci storage child there is an invalid call to _bytes_to_human a string is supplied as a default value if the storage child does not present a 'size' attribute. 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. --- src/utils/hw_inventory.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/utils') diff --git a/src/utils/hw_inventory.py b/src/utils/hw_inventory.py index dff1c7a..23c8765 100644 --- a/src/utils/hw_inventory.py +++ b/src/utils/hw_inventory.py @@ -151,7 +151,7 @@ def _process_core_pci_network(inventory, obj): def _process_core_pci_storage_child(inventory, obj): obj_id = obj.get('id', '') if obj_id.startswith('disk') or obj_id.startswith('nvme'): - size = _bytes_to_human(obj.get('size', 'Unknown size')) + size = _bytes_to_human(obj['size']) if 'size' in obj else 'Unknown size' name = ' '.join([obj.get('description', ''), obj.get('product', 'Unknown product'), size]) elem = HardwareElement(HardwareType.DISK, name) inventory.add_element(elem) -- cgit v1.2.3-18-g5258