Repository navigation
fix(smart): keep healthy disks when pySMART rejects a device type - #3807
Open
flyingnobita wants to merge 1 commit into
Open
flyingnobita wants to merge 1 commit into
flyingnobita wants to merge 1 commit into
Conversation
When smartctl --scan reports a device type pySMART does not accept, such as a USB bridge (-d usbsunplus), pySMART raises ValueError from DeviceList(). On v4 this kills Glances at startup; on develop the per-plugin guard catches it, but the smart plugin then returns no data at all, healthy disks included, and logs a warning every cycle. Call DeviceList(catch_errors=True) so pySMART skips the device it cannot parse and keeps the others, and add ValueError to the whole-list fallback. With catch_errors, pySMART logs the skipped device with logging.exception() on the root logger on every refresh. In the Docker image that is a full traceback in the console every few seconds. A root-logger filter, attached only around the DeviceList() call, turns the first such record per device into one WARNING without traceback and drops the repeats. It matches only pySMART's "Error parsing device" record and never formats other records. Fixes nicolargo#3806
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #3806: a disk whose
smartctl --scantype pySMART does not accept (USB bridges such as-d usbsunplus,usbjmicron) no longer takes out SMART data for every disk.On
developthis is not a crash: the per-plugin guard inGlancesPluginBase.update()catches theValueError, butget_smart_data()then returns nothing at all, healthy disks included, and logsPlugin smart update failedevery cycle. On v4 (4.5.8, as reported in the issue) there is no such guard and Glances exits at startup. A backport tosupport/glancesv4will follow if you want it.Why the filter: with
catch_errors=True, pySMART callslogging.exception("Error parsing device ...")on the root logger (it has no named logger) on every refresh. In the Docker image (LOG_CFG=/app/docker-logger.json) that is a full traceback indocker logsevery few seconds. The filter turns the first such record per device into one WARNING without traceback and drops the repeats. It only matches pySMART'sError parsing devicerecord (by pathname and raw message), never formats other records, and is attached only around theDeviceList()call.Alternative, your call: drop the filter and keep only the 2-line
catch_errors=Truechange. The plugin then works, at the cost of the repeated tracebacks shown below.Evidence
Real hardware: Sunplus USB bridge (
1bcf:0c31) reported as/dev/sda -d usbsunplus, plus an NVMe. Imagenicolargo/glances:dev(5.0.0b1, pySMART 1.4.3, smartctl 7.5), patcheddata.pybind-mounted,--enable-plugin smart.catch_errorsonly/api/5/smartnullnvme0(23 attributes), nosdanvme0(23 attributes), nosdaPlugin smart update failedError parsing devicetracebacksSmart plugin - Skippingdocker logswith this PR:Tests in
tests/test_smart_data.py(written first, red ondevelop):test_unknown_interface_skips_device_keeps_others: drives the realpySMART.DeviceList.initialize()with an nvme + usbsunplus scan; returns the NVMe, plugin stays enabled.test_device_list_value_error_disables_plugin: whole-listValueErrorreturns[]and setsimport_error_tag.test_skipped_device_logs_one_warning_without_traceback: two refreshes, one WARNING per device, no traceback.test_root_logger_filters_restored,test_unrelated_root_errors_not_suppressed,test_filter_never_raises: the filter is scoped and cannot break other logging.test_missing_smartctl_returns_no_device: its fake now accepts**kwargs, otherwise it would pass through theTypeErrorbranch instead ofFileNotFoundError.make test: 4162 passed, 20 skipped.ruff check,ruff format --checkandpre-commit run --all-filespass.Notes
catch_errorsexists since pySMART 1.2.3. On older versions the call raisesTypeError, which is caught, so SMART is disabled rather than crashing.pyproject.tomldoes not pin pySMART; pinningpySMART>=1.2.3is left to you.-d <type>makes pySMART raiseAttributeErroroutside itstry.Resume