Skip to content

Conversation

@mulkieran
Copy link
Member

@mulkieran mulkieran commented Sep 30, 2025

Related #1225

Fix a bug where printing out a filesystem detail view would result
in a stack trace if the used D-Bus value was not valid.

Signed-off-by: mulhern <amulhern@redhat.com>
@mulkieran mulkieran self-assigned this Sep 30, 2025
@coderabbitai
Copy link

coderabbitai bot commented Sep 30, 2025

Walkthrough

Introduces a new SizeTriple class for handling total/used/free size calculations, removes the old size_triple formatter, and refactors filesystem and pool listing actions to use SizeTriple with TABLE_FAILURE_STRING fallbacks for None values. Imports are updated accordingly; no public interfaces changed except the new class.

Changes

Cohort / File(s) Summary of edits
Size abstraction introduction
src/stratis_cli/_actions/_utils.py
Added public class SizeTriple (stores total Range and optional used Range; provides total(), used(), free()). Added imports (Range, Optional).
Legacy formatter removal
src/stratis_cli/_actions/_formatting.py
Removed size_triple(total, used) function and its Range import.
Filesystem listing refactor
src/stratis_cli/_actions/_list_filesystem.py
Replaced prior size_triple usage with SizeTriple; introduced TABLE_FAILURE_STRING fallback in formatted strings; updated filesystem_size_quartet and Detail.display to use SizeTriple.total()/used()/free(); adjusted imports (removed size_triple, added TABLE_FAILURE_STRING and SizeTriple).
Pool listing refactor
src/stratis_cli/_actions/_list_pool.py
Consolidated size calculations via SizeTriple for detailed and table views; added TABLE_FAILURE_STRING fallbacks; removed direct Range/usage computations; updated imports accordingly.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant UI as CLI Action (List Filesystem/Pool)
  participant S as SizeTriple
  participant D as Data Source (fs/pool props)
  participant F as Formatter (TABLE_FAILURE_STRING)

  UI->>D: Read total size, used size (may be None)
  UI->>S: Construct SizeTriple(total, used)
  UI->>S: total()
  S-->>UI: Range
  UI->>S: used()
  S-->>UI: Optional[Range]
  UI->>S: free()
  S-->>UI: Optional[Range] (total - used or None)
  UI->>F: Format trio, substituting TABLE_FAILURE_STRING for None
  F-->>UI: Display strings (Total / Used / Free [...limit])
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

Hops in the code, I bundle three,
Total, Used, and Free for tea.
Old strings gone, a tidy ripple,
Now I nibble one neat triple.
If Used is missing—no distress—
TABLE_FAILURE whispers “N/A”, no mess. 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly captures the primary refactoring in this pull request by highlighting the introduction of the new SizeTriple class and the removal of the deprecated size_triple function in a clear, single phrase. It accurately reflects the core changes without extraneous detail, making it immediately understandable to reviewers and maintainers.
Docstring Coverage ✅ Passed Docstring coverage is 92.86% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 552e4f4 and dcaf205.

📒 Files selected for processing (4)
  • src/stratis_cli/_actions/_formatting.py (0 hunks)
  • src/stratis_cli/_actions/_list_filesystem.py (4 hunks)
  • src/stratis_cli/_actions/_list_pool.py (3 hunks)
  • src/stratis_cli/_actions/_utils.py (2 hunks)
💤 Files with no reviewable changes (1)
  • src/stratis_cli/_actions/_formatting.py
🧰 Additional context used
🧬 Code graph analysis (2)
src/stratis_cli/_actions/_list_pool.py (2)
src/stratis_cli/_actions/_utils.py (4)
  • SizeTriple (272-297)
  • total (281-285)
  • used (287-291)
  • free (293-297)
src/stratis_cli/_actions/_formatting.py (1)
  • get_property (38-52)
src/stratis_cli/_actions/_list_filesystem.py (2)
src/stratis_cli/_actions/_formatting.py (2)
  • get_property (38-52)
  • print_table (108-149)
src/stratis_cli/_actions/_utils.py (4)
  • SizeTriple (272-297)
  • total (281-285)
  • used (287-291)
  • free (293-297)
🔇 Additional comments (10)
src/stratis_cli/_actions/_utils.py (3)

26-26: LGTM!

The addition of Optional to the typing imports is necessary for the new SizeTriple class.


32-32: LGTM!

The Range import from justbytes is correctly added to support the SizeTriple class implementation.


272-297: LGTM! Clean abstraction for size calculations.

The SizeTriple class provides a clear, focused abstraction for managing total/used/free size calculations. The free() method correctly handles the None case for used, returning None when usage data is unavailable rather than attempting invalid arithmetic.

src/stratis_cli/_actions/_list_filesystem.py (4)

29-35: LGTM!

Import changes correctly reflect the refactoring from the old size_triple function to the new SizeTriple class and TABLE_FAILURE_STRING constant.


142-153: LGTM! Consistent use of SizeTriple with proper None handling.

The refactored filesystem_size_quartet correctly constructs a SizeTriple and uses TABLE_FAILURE_STRING as a fallback for None values from used() and free(). The approach cleanly separates size calculation logic from formatting.


196-196: LGTM!

The SizeTriple construction in the detail view correctly passes total and used values, with get_property handling the optional Used() property.


218-226: LGTM! Proper None handling in detail view.

The detail view correctly uses size_triple.total(), size_triple.used(), and size_triple.free() methods, with appropriate TABLE_FAILURE_STRING fallbacks for None values. The formatting maintains consistency with the table view.

src/stratis_cli/_actions/_list_pool.py (3)

47-47: LGTM!

The SizeTriple import is correctly added to support the refactored pool listing logic.


402-413: LGTM! Consistent SizeTriple usage in detail view.

The detail view correctly constructs a SizeTriple from TotalPhysicalSize() and TotalPhysicalUsed(), then uses the accessor methods with proper TABLE_FAILURE_STRING fallback for the used() value when it's None.


474-488: LGTM! Clean refactoring of physical_size_triple helper.

The physical_size_triple helper correctly constructs a SizeTriple and formats the output using total(), used(), and free() methods with TABLE_FAILURE_STRING fallbacks. This refactoring consolidates the size calculation logic and makes it consistent with the filesystem listing code.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@mulkieran mulkieran marked this pull request as ready for review September 30, 2025 17:50
@mulkieran mulkieran moved this to In Review in 2025September Sep 30, 2025
@mulkieran mulkieran merged commit 83ae558 into stratis-storage:master Sep 30, 2025
10 checks passed
@mulkieran mulkieran deleted the fix-used-free-fs-size-bug branch September 30, 2025 20:08
@github-project-automation github-project-automation bot moved this from In Review to Done in 2025September Sep 30, 2025
@mulkieran mulkieran moved this from Done to Done(5) in 2025September Oct 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Status: Done(5)

Development

Successfully merging this pull request may close these issues.

1 participant