Commit Graph

9 Commits (cf9577a40edd7c3f8bebcf02aaccb7ef441e7dac)

Author SHA1 Message Date
Alejandro Sirgo Rica bf15491435 hw_inventory: fix json parsing
Add support for both lshw -json return formats.
The json structure may follow one of the following.

output:list flag enabled:
[{content}]

output:list flag disabled:
{content}

The output:list flag was defined in the commit 2b1c730 of
https://ezix.org/src/pkg/lshw
2024-12-11 15:17:02 +01:00
OpenGnSys Support Team 62b52ff364 src: update license header 2024-11-28 16:45:56 +01:00
Alejandro Sirgo Rica dfde363aa6 src: log backtrace in unhandled error cases
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.
2024-04-03 13:31:10 +02:00
Alejandro Sirgo Rica 049b7a5a2b src: make exception messages more contextual and explicit
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.
2024-03-21 10:29:57 +01:00
Jose M. Guisado b49ec83bcd 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.
2023-10-18 13:32:24 +02:00
Jose M. Guisado 59eac6d0d5 live: hw_inventory: fix typo
Add missing underscore to _bytes_to_human call.

Fixes: 39c13287c5 ("live: hw_inventory: fix empty memory bank bug")
2023-10-18 12:05:23 +02:00
Jose M. Guisado 39c13287c5 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.
2023-10-05 16:19:36 +02:00
Jose M. Guisado ee0d62db44 hw_inventory: use dict.get
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.
2023-07-21 11:55:25 +02:00
Jose M. Guisado 49a86bddd9 utils: add hw_inventory.py
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
2023-04-18 12:02:29 +02:00