Skip to content

fix: Show error when trying to put LVM volume on partition pool#531

Merged
richm merged 1 commit intolinux-system-roles:mainfrom
vojtechtrefny:main_lvm-partition-error
May 13, 2025
Merged

fix: Show error when trying to put LVM volume on partition pool#531
richm merged 1 commit intolinux-system-roles:mainfrom
vojtechtrefny:main_lvm-partition-error

Conversation

@vojtechtrefny
Copy link
Copy Markdown
Collaborator

@vojtechtrefny vojtechtrefny commented May 12, 2025

Trying this currently fails later with an exception so this just makes sure we show a nicer error message describing the error in the provided playbook.

Resolves: RHEL-71246

Summary by Sourcery

Provide explicit error handling when attempting to create an LVM volume on a non-LVM pool and add a test to verify this scenario

Bug Fixes:

  • Raise a clear error when placing an LVM volume on a non-LVM (partition) pool

Tests:

  • Add a test case to validate the pool and volume type mismatch triggers the correct error message

Trying this currently fails later with an exception so this just
makes sure we show a nicer error message describing the error in
the provided playbook.

Resolves: RHEL-71246
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 12, 2025

Reviewer's Guide

Introduce an explicit validation in the blivet backend to ensure LVM volumes are only created on LVM pools and add a corresponding test case to verify that a clear error is raised when a type mismatch occurs.

Sequence Diagram: LVM Volume Creation with Pool Type Validation

sequenceDiagram
    actor User/Playbook
    participant BVC as BlivetCode
    participant BP as BlivetPool
    participant PD as PoolDevice

    User/Playbook->>BVC: Call _create() for LVM Volume
    BVC->>BP: Get self._blivet_pool
    BP->>PD: Get self._blivet_pool._device
    PD-->>BP: return device
    BP-->>BVC: return pool (with device)
    BVC->>BVC: Check pool._device.type
    alt Pool device type is not "lvmvg"
        BVC-->>User/Playbook: raise BlivetAnsibleError("LVM volume can be placed only on LVM pool")
    else Pool device type is "lvmvg"
        BVC->>BVC: Proceed with LVM volume creation (original logic)
    end
Loading

Class Diagram: Update to LVM Volume Creation Logic in Blivet Library

classDiagram
    class BlivetLogicContainer {
        -_blivet_pool: BlivetPool
        +_create() void
        note for _create "Modified to add validation: checks self._blivet_pool._device.type.\nRaises BlivetAnsibleError if type is not 'lvmvg'."
    }
    class BlivetPool {
        -_device: PoolDevice
    }
    class PoolDevice {
        +type: string
    }
    class BlivetAnsibleError {
        <<Exception>>
        +message: string
    }
    BlivetLogicContainer ..> BlivetAnsibleError : throws
    BlivetLogicContainer o-- BlivetPool : uses
    BlivetPool o-- PoolDevice : has
Loading

File-Level Changes

Change Details Files
Validate pool type before LVM volume creation
  • Insert a check on the pool’s device type in the _create() method
  • Raise BlivetAnsibleError with a clear message when type is not “lvmvg”
library/blivet.py
Add test for pool and volume type mismatch
  • Add a new test scenario in tests_lvm_errors.yml using verify-role-failed.yml
  • Define expected error regex and message for wrong pool type
tests/tests_lvm_errors.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

@codecov
Copy link
Copy Markdown

codecov Bot commented May 12, 2025

Codecov Report

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

Project coverage is 10.71%. Comparing base (59fd1c6) to head (98136f0).
Report is 56 commits behind head on main.

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

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

HEAD has 1 upload less than BASE
Flag BASE (59fd1c6) HEAD (98136f0)
sanity 1 0
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #531      +/-   ##
==========================================
- Coverage   16.54%   10.71%   -5.84%     
==========================================
  Files           2        8       +6     
  Lines         284     1951    +1667     
  Branches       79        0      -79     
==========================================
+ Hits           47      209     +162     
- Misses        237     1742    +1505     
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.

@richm
Copy link
Copy Markdown
Contributor

richm commented May 12, 2025

[citest]

@richm
Copy link
Copy Markdown
Contributor

richm commented May 12, 2025

[citest_bad]

@vojtechtrefny vojtechtrefny marked this pull request as ready for review May 13, 2025 06:57
Copy link
Copy Markdown

@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!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Review instructions: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Documentation: all looks good

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.

@richm richm merged commit c7a09f6 into linux-system-roles:main May 13, 2025
34 of 38 checks passed
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.

2 participants