summaryrefslogtreecommitdiffstats
path: root/src/utils/hw_inventory.py
Commit message (Collapse)AuthorAgeFilesLines
* src: log backtrace in unhandled error casesAlejandro Sirgo Rica2024-04-031-5/+6
| | | | | | | | | | | | | | | | | | | Log an error message in known error cases and log a backtrace otherwise. Define a new error type OgError to be used in all the 'raise' blocks to define the error message to log. The exception propagates until it reaches send_internal_server_error() where the exception type is checked. If the type is OgError we log the exception message. Logs the backtrace for other types. The initial error implementation printed a backtrace everytime an error ocurred. The next iteration changed it to only print a backtrace in a very particular case but ended up omiting too much information such as syntax errors or unknown error context. The actual implementation only logs the cases we already cover in the codebase and logs a bracktrace in the others, enabling a better debugging experience.
* src: make exception messages more contextual and explicitAlejandro Sirgo Rica2024-03-211-3/+3
| | | | | | | Provide more information in exception messages as those are the source of the logging messages. Add information about paths, files or configuration related to the operation associated to the exception.
* live: hw_inventory: fix empty pci storage size bugJose M. Guisado2023-10-181-1/+1
| | | | | | | | | | | 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.
* live: hw_inventory: fix typoJose M. Guisado2023-10-181-1/+1
| | | | | | Add missing underscore to _bytes_to_human call. Fixes: 39c13287c53bd8 ("live: hw_inventory: fix empty memory bank bug")
* live: hw_inventory: fix empty memory bank bugJose M. Guisado2023-10-051-6/+9
| | | | | | | | | | | | 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.
* hw_inventory: use dict.getJose M. Guisado2023-07-211-23/+27
| | | | | | | | | The first stage of parsing the "lshw -json" command output is to load the json string into a Python dictionary. lshw output is large and varies from machine to machine, so it's not safe to assume that different keys will be present in the dictionary. Use dict.get() instead of dict[key] to avoid KeyError exceptions.
* utils: add hw_inventory.pyJose M. Guisado2023-04-181-0/+309
hw_inventory.py defines classes and helpers functions enabling fetching of hardware inventory from a running client. Uses a subprocess call to the command 'lshw -json' to obtain hardware information. Relevant public functions: > get_hardware_inventory() Main function encapsulating subprocess and output processing logic. Returns a HardwareInventory object. > legacy_list_hardware_inventory(inventory) Legacy string representation of parameter HardwareInventory object