Skip to content

fix: Fix getting PVs from raid_disks for RAID LVs#536

Merged
richm merged 1 commit intolinux-system-roles:mainfrom
vojtechtrefny:main_lvm-raid-disks-fix
Jun 3, 2025
Merged

fix: Fix getting PVs from raid_disks for RAID LVs#536
richm merged 1 commit intolinux-system-roles:mainfrom
vojtechtrefny:main_lvm-raid-disks-fix

Conversation

@vojtechtrefny
Copy link
Copy Markdown
Collaborator

@vojtechtrefny vojtechtrefny commented Jun 3, 2025

Currently the code expects the disks specified in raid_disks are parent devices of the PVs we are going to use to allocate the RAID LVs. This might not be true in several cases, for example if the VG is encrypted (the LUKS device introduces a new layer in the storage stack) or if partitions are not used (the disk is then the PV and doesn't have a parent). This fix also allows user to specify the PV partition instead of the underlying disk.

Summary by Sourcery

Improve PV resolution in LVM RAID to support encrypted and partitioned devices and add corresponding tests

Bug Fixes:

  • Fix PV detection for raid_disks entries to handle encrypted LUKS layers and direct partitions

Enhancements:

  • Add error handling for missing or invalid raid_disks entries

Tests:

  • Add tests for creating and removing LVM RAID devices on encrypted volume groups

Currently the code expects the disks specified in raid_disks are
parent devices of the PVs we are going to use to allocate the RAID
LVs. This might not be true in several cases, for example if the
VG is encrypted (the LUKS device introduces a new layer in the
storage stack) or if partitions are not used (the disk is then the
PV and doesn't have a parent). This fix also allows user to
specify the PV partition instead of the underlying disk.
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Jun 3, 2025

Reviewer's Guide

Enhance LVM RAID disk resolution to correctly handle partitions and encrypted VGs by matching PVs via direct or ancestor relationships, add validation errors, and introduce integration tests covering encrypted VG RAID creation and removal with PV-level disk specification.

Class Diagram: Storage Entities for PV Matching in LVM RAID

classDiagram
    class Device {
      +name: string
    }
    class Disk {
      <<Represents resolved raid_disk entry>>
      +path: string
    }
    class PV {
      <<Physical Volume>>
      +ancestors: List<Device>
    }
    class ParentDevice {
      <<e.g. Volume Group>>
      +name: string
      +pvs: List<PV>
    }

    Disk --|> Device : is a
    PV --|> Device : is a
    ParentDevice "1" o-- "*" PV : contains
    PV "1" -- "*" Device : has_ancestor
Loading

File-Level Changes

Change Details Files
Enhanced PV discovery for RAID disks to support partitions and encryption layers with validation
  • Match PV if disk equals PV or is in its ancestor chain
  • Raise error when a specified disk is not found or not a PV of the VG
  • Break loop after finding the first matching PV to avoid duplicates
library/blivet.py
Added integration tests for RAID on encrypted VGs and PV-level disk specification
  • Create RAID1 on an encrypted VG using specified raid_disks
  • Verify role results after creation and after removal
  • Remove the RAID device and verify cleanup
tests/tests_create_raid_pool_then_remove.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 Jun 3, 2025

Codecov Report

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

Project coverage is 10.64%. Comparing base (59fd1c6) to head (a07c80c).
Report is 61 commits behind head on main.

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

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

HEAD has 1 upload less than BASE
Flag BASE (59fd1c6) HEAD (a07c80c)
sanity 1 0
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #536      +/-   ##
==========================================
- Coverage   16.54%   10.64%   -5.91%     
==========================================
  Files           2        8       +6     
  Lines         284     1964    +1680     
  Branches       79        0      -79     
==========================================
+ Hits           47      209     +162     
- Misses        237     1755    +1518     
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.

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 - here's some feedback:

  • The new test is titled “Create a RAID1 lvm raid device on encrypted VG” but uses raid_level: raid0—please update the test title or the raid_level to match.
  • It would be good to add a test case where raid_disks points to a partition (not the whole disk) to verify the new pv == disk and disk in pv.ancestors logic handles that scenario.
  • Consider adding a brief code comment or docstring explaining why we switched from pv.parents to pv.ancestors so future readers understand the intended device hierarchy resolution.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 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.

Comment thread library/blivet.py
for pv in parent_device.pvs:
if disk in pv.parents:
pvs.append(pv)
if disk:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion (bug_risk): Use explicit None check for resolved device

Use if disk is not None: to prevent issues if disk has a custom __bool__ method.

Suggested change
if disk:
if disk is not None:

@richm
Copy link
Copy Markdown
Contributor

richm commented Jun 3, 2025

[citest]

@richm
Copy link
Copy Markdown
Contributor

richm commented Jun 3, 2025

[citest_bad]

@richm richm merged commit 9d342b1 into linux-system-roles:main Jun 3, 2025
34 of 36 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