Skip to content

staslib: parse time spans the way systemd does - #517

Merged
martin-belanger merged 1 commit into
linux-nvme:mainfrom
martin-belanger:timeparse-systemd-parity
Sep 1, 2026
Merged

staslib: parse time spans the way systemd does#517
martin-belanger merged 1 commit into
linux-nvme:mainfrom
martin-belanger:timeparse-systemd-parity

Conversation

@martin-belanger

Copy link
Copy Markdown
Collaborator

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.

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>
@martin-belanger
martin-belanger merged commit 360abaa into linux-nvme:main Sep 1, 2026
10 checks passed
@codecov

codecov Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.78049% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 71.32%. Comparing base (a3e2152) to head (fc93ae9).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
staslib/timeparse.py 98.78% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant