Skip to content

Conversation

@vojtechtrefny
Copy link
Collaborator

@vojtechtrefny vojtechtrefny commented Jul 21, 2025

Summary by Sourcery

Validate RAID parameters before array creation, improve error messages and remove obsolete logic

Bug Fixes:

  • Raise clear error when an invalid RAID level is specified
  • Enforce minimum disk count and error out if trying to create a RAID with too few disks

Enhancements:

  • Remove the deprecated _process_device_numbers helper and unify raid_level usage

Tests:

  • Add failure tests for invalid RAID level and insufficient disks scenarios

@sourcery-ai
Copy link

sourcery-ai bot commented Jul 21, 2025

Reviewer's Guide

Adds explicit validation and clearer error messages when creating RAID arrays by checking for invalid RAID levels and insufficient disks, refactors new_mdarray to utilize these checks, removes legacy device count processing, and introduces tests for these failure cases.

Sequence diagram for RAID array creation with improved error handling

sequenceDiagram
    participant User
    participant BlivetAnsible
    participant BlivetLibs
    participant RaidLib

    User->>BlivetAnsible: Request to create RAID array
    BlivetAnsible->>BlivetLibs: _new_mdarray(members, raid_name)
    BlivetLibs->>RaidLib: get_raid_level(raid_level)
    alt Invalid RAID level
        RaidLib-->>BlivetLibs: Raise RaidError
        BlivetLibs-->>BlivetAnsible: Raise BlivetAnsibleError (invalid RAID level)
        BlivetAnsible-->>User: Error: not a valid RAID level
    else Valid RAID level
        RaidLib-->>BlivetLibs: blivet_level
        BlivetLibs->>BlivetLibs: Check len(members) < blivet_level.min_members
        alt Not enough disks
            BlivetLibs-->>BlivetAnsible: Raise BlivetAnsibleError (not enough disks)
            BlivetAnsible-->>User: Error: not enough disks selected
        else Enough disks
            BlivetLibs->>BlivetLibs: Proceed with RAID creation
            BlivetLibs-->>BlivetAnsible: RAID array created
            BlivetAnsible-->>User: RAID array created successfully
        end
    end
Loading

Class diagram for updated RAID error handling and validation

classDiagram
    class BlivetAnsibleError
    class RaidError
    class BlivetLibs {
        +_new_mdarray(members, raid_name="")
    }
    class devicelibs.raid {
        +get_raid_level(raid_level)
    }
    class blivet_level {
        +min_members
    }

    BlivetLibs --> devicelibs.raid : uses
    devicelibs.raid --> RaidError : raises
    BlivetLibs --> BlivetAnsibleError : raises
    devicelibs.raid --> blivet_level : returns
    BlivetLibs ..> blivet_level : checks min_members
Loading

File-Level Changes

Change Details Files
Introduce RAID level validation and disk count checks in new_mdarray
  • import RaidError from blivet and blivet3 errors
  • catch invalid RAID level and raise BlivetAnsibleError
  • validate member count against min_members and raise error if insufficient
  • use local raid_level variable for new_mdarray invocation
library/blivet.py
Remove deprecated device number processing method
  • delete _process_device_numbers from BlivetMDRaidVolume class
library/blivet.py
Add tests for RAID failure scenarios
  • test invalid RAID level error
  • test insufficient disks error for raid5
tests/tests_fatals_raid_pool.yml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @vojtechtrefny - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov
Copy link

codecov bot commented Jul 21, 2025

Codecov Report

Attention: Patch coverage is 0% with 9 lines in your changes missing coverage. Please review.

Project coverage is 10.66%. Comparing base (59fd1c6) to head (44f8e2d).
Report is 73 commits behind head on main.

Files with missing lines Patch % Lines
library/blivet.py 0.00% 9 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (59fd1c6) and HEAD (44f8e2d). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (59fd1c6) HEAD (44f8e2d)
sanity 1 0
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #545      +/-   ##
==========================================
- Coverage   16.54%   10.66%   -5.89%     
==========================================
  Files           2        8       +6     
  Lines         284     1960    +1676     
  Branches       79        0      -79     
==========================================
+ Hits           47      209     +162     
- Misses        237     1751    +1514     
Flag Coverage Δ
sanity ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@vojtechtrefny vojtechtrefny force-pushed the main_raid-disks-error branch from 9b93b33 to 51adc52 Compare July 21, 2025 12:39
@richm
Copy link
Contributor

richm commented Jul 21, 2025

@vojtechtrefny you'll also need to change the error message in tests_fatals_raid_volume.yml:

--- a/tests/tests_fatals_raid_volume.yml
+++ b/tests/tests_fatals_raid_volume.yml
@@ -30,7 +30,7 @@
     - name: Try to create a raid pool with invalid raid_level (expect failure)
       include_tasks: verify-role-failed.yml
       vars:
-        __storage_failed_exception: RAID level null is an invalid value.
+        __storage_failed_exception: null is not a valid RAID level
         __storage_failed_params:
           storage_safe_mode: false
           storage_volumes:

@vojtechtrefny vojtechtrefny force-pushed the main_raid-disks-error branch from 51adc52 to 44f8e2d Compare July 22, 2025 07:43
@vojtechtrefny
Copy link
Collaborator Author

@vojtechtrefny you'll also need to change the error message in tests_fatals_raid_volume.yml:

--- a/tests/tests_fatals_raid_volume.yml
+++ b/tests/tests_fatals_raid_volume.yml
@@ -30,7 +30,7 @@
     - name: Try to create a raid pool with invalid raid_level (expect failure)
       include_tasks: verify-role-failed.yml
       vars:
-        __storage_failed_exception: RAID level null is an invalid value.
+        __storage_failed_exception: null is not a valid RAID level
         __storage_failed_params:
           storage_safe_mode: false
           storage_volumes:

Thank you, fixed.

@richm
Copy link
Contributor

richm commented Jul 22, 2025

[citest]

1 similar comment
@spetrosi
Copy link
Contributor

[citest]

@richm richm merged commit 0fa7f21 into linux-system-roles:main Jul 22, 2025
30 of 36 checks passed
@spetrosi
Copy link
Contributor

[citest]

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.

3 participants