Interface with udev database for various fixes (but future work needed) #42
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.
Rather than attempting to parse
/dev
and/sys
directly within smfc, we can outsource that task toudev
(through pyudev). This allows us to simplify much of the logic and string parsing, making it less fragile and more robust.This new strategy gives a convenient fix to #25.
Additionally: under linux (under the persistent storage naming rules present in most distributions AFAIK), the NVMe device by-id symlinks point to the block device (e.g.,
/dev/nvme0n1
) rather than the controller (/dev/nvme0
). However, the correspondinghwmon
device is actually a child of the controller (thus a sibling to the block device in sysfs).The original code has a bug where the symlink is assumed to be backwards (so it assumes the link points to
/dev/nvme0
and concatenates the namespace within sysfs). This bug is also present in the unit tests in the test data created by the filetest_00_data.py
.Properly parsing the string would require stripping the namespace (in 99% of cases, this is
"n1"
) from the block device name. Instead, in this commit we use pyudev to query the udev database to find the siblinghwmon
device. Unfortunately, the test file doesn't have such a simple fix, so someone will have to patch it more deeply.Unfortunately, the unit tests will require a more extensive refactoring to be able to support pyudev, but these changes are not a part of this PR. If we want to keep the current strategy of creating a set of "test data" for the tests, then something like umockdev might be best. Otherwise, we could write
Mock
s for the expected function calls, but for that a wholesale restructuring of all the test data is probably required.For now, this code continues to use the
open
andread
paradigm on sysfs files, but a future refactor might instead use the pythonic interface from pyudev (e.g.,hwmon_dev.attributes.get('temp1_input')
).