staslib: parse time spans the way systemd does - #517
Merged
martin-belanger merged 1 commit intoSep 1, 2026
Conversation
dc-giveup-timeout is documented as a time span, and nvme-discoverd takes the same key with the same encoding, parsing it with a copy of systemd's parse_time(). A span a user writes once has to mean the same thing in both daemons. It did not: timeparse.py was a vendored copy of pytimeparse, which has a grammar of its own. 500ms systemd 0.5s pytimeparse rejected 1week systemd 604800s pytimeparse rejected 1y systemd 31557600s pytimeparse rejected 1:30 systemd rejected pytimeparse 90s The parser now implements systemd's grammar, including the suffix table, the "M" months / "m" minutes case distinction, the 30.44-day month and 365.25-day year, and the truncating arithmetic on fractional digits. Nothing of pytimeparse remains, so the file drops the vendored MIT notice it no longer owes and takes the same header as the rest of staslib. Spans only pytimeparse accepted now fall back to the default with a warning: "hrs"/"secs"/"mins"/"dy", uppercase, comma-separated terms, colon notation, and "inf"/"1e5"/"nan". One value keeps parsing and changes meaning: "1M" was 60 seconds and is now one month. stafd.conf(5) and the sample stafd.conf now point at systemd.time(7). The tests mirror nvme-cli's, and every case was checked against the host's systemd-analyze timespan. Signed-off-by: Martin Belanger <martin.belanger@dell.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #517 +/- ##
==========================================
+ Coverage 70.86% 71.32% +0.46%
==========================================
Files 16 16
Lines 2742 2786 +44
==========================================
+ Hits 1943 1987 +44
Misses 799 799 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
dc-giveup-timeout is documented as a time span, and nvme-discoverd takes the same key with the same encoding, parsing it with a copy of systemd's parse_time(). A span a user writes once has to mean the same thing in both daemons. It did not: timeparse.py was a vendored copy of pytimeparse, which has a grammar of its own.
500ms systemd 0.5s pytimeparse rejected
1week systemd 604800s pytimeparse rejected
1y systemd 31557600s pytimeparse rejected
1:30 systemd rejected pytimeparse 90s
The parser now implements systemd's grammar, including the suffix table, the "M" months / "m" minutes case distinction, the 30.44-day month and 365.25-day year, and the truncating arithmetic on fractional digits. Nothing of pytimeparse remains, so the file drops the vendored MIT notice it no longer owes and takes the same header as the rest of staslib.
Spans only pytimeparse accepted now fall back to the default with a warning: "hrs"/"secs"/"mins"/"dy", uppercase, comma-separated terms, colon notation, and "inf"/"1e5"/"nan". One value keeps parsing and changes meaning: "1M" was 60 seconds and is now one month.
stafd.conf(5) and the sample stafd.conf now point at systemd.time(7). The tests mirror nvme-cli's, and every case was checked against the host's systemd-analyze timespan.