Skip to content

fix: use correct encryption_key parameter, improve error messages#601

Merged
richm merged 3 commits intolinux-system-roles:mainfrom
vojtechtrefny:main_various-fixes
Mar 23, 2026
Merged

fix: use correct encryption_key parameter, improve error messages#601
richm merged 3 commits intolinux-system-roles:mainfrom
vojtechtrefny:main_various-fixes

Conversation

@vojtechtrefny
Copy link
Copy Markdown
Collaborator

@vojtechtrefny vojtechtrefny commented Mar 23, 2026

Summary by Sourcery

Align encryption parameter names with key-based encryption handling and clarify pool-related error messages in blivet volume operations.

Bug Fixes:

  • Correct encryption parameter names when updating volume and pool metadata to use the key file value.
  • Fix lookup of encryption credentials by using the updated pool keys for password and key-based unlocking.
  • Avoid referencing attributes of a missing pool device when reporting pool lookup failures.

Enhancements:

  • Improve VDO pool size error messages by including the invalid size and target volume name.
  • Simplify pool-not-found error messages to avoid misleading or invalid pool name references.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Mar 23, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Aligns encryption-related parameter names between volume and pool structures, updates how LUKS encryption details are propagated, and refines several BlivetAnsibleError messages for clarity and to avoid dereferencing missing pool devices.

Sequence diagram for applying encryption parameters in _look_up_device

sequenceDiagram
    participant BlivetVolume
    participant Pool
    participant ParentDevice
    participant LUKSDevice

    BlivetVolume->>Pool: get(encryption_password)
    Pool-->>BlivetVolume: passphrase
    BlivetVolume->>Pool: get(encryption_key)
    Pool-->>BlivetVolume: key_file

    loop for each parent in device.parents
        BlivetVolume->>ParentDevice: inspect parent.format.type
        ParentDevice-->>BlivetVolume: type = luks
        alt passphrase is set
            BlivetVolume->>LUKSDevice: open_with_passphrase(passphrase)
            LUKSDevice-->>BlivetVolume: opened
        else key_file is set
            BlivetVolume->>LUKSDevice: open_with_key_file(key_file)
            LUKSDevice-->>BlivetVolume: opened
        end
    end
Loading

Updated class diagram for volume and pool encryption metadata

classDiagram
    class BlivetVolume {
        dict _volume
        dict _pool
        BlivetPool _blivet_pool
        _update_from_device(param_name)
        _look_up_device()
        _get_params_create_vdo()
        _create()
    }

    class VolumeEncryptionMetadata {
        bool encryption
        int encryption_key_size
        string encryption_key
        string encryption_cipher
        string encryption_luks_version
    }

    class PoolEncryptionMetadata {
        bool encryption
        int encryption_key_size
        string encryption_key
        string encryption_cipher
        string encryption_luks_version
        string encryption_password
    }

    class BlivetPool {
        Device _device
    }

    class Device {
        list parents
        Format format
        string name
        Size free_space
    }

    class Format {
        string type
        int key_size
        string key_file
        string cipher
        string luks_version
    }

    BlivetVolume --> BlivetPool : uses
    BlivetPool --> Device : wraps
    Device --> Format : has

    BlivetVolume .. VolumeEncryptionMetadata : stores_in__volume
    BlivetVolume .. PoolEncryptionMetadata : stores_in__pool

    VolumeEncryptionMetadata <.. Format : derives_from
    PoolEncryptionMetadata <.. Format : derives_from
Loading

File-Level Changes

Change Details Files
Align encryption key parameter names and propagation between volume metadata and underlying LUKS format.
  • Rename volume encryption parameter from 'encryption_key_file' to 'encryption_key' when updating from luks_fmt
  • Use luks_fmt.key_file value to populate the new 'encryption_key' field when encryption is enabled for a volume
library/blivet.py
Standardize pool-level encryption parameter names and their use when opening encrypted parents.
  • Switch pool passphrase lookup from 'encryption_passphrase' to 'encryption_password' when applying keys to encrypted device parents
  • Switch pool key file lookup from 'encryption_key_file' to 'encryption_key' when applying keys to encrypted device parents
  • Update pool metadata update logic to write 'encryption_key' instead of 'encryption_key_file' based on the LUKS format key_file
library/blivet.py
Improve and harden error messages around VDO pool sizing and missing pools.
  • Expand VDO pool size error message to include the requested 'vdo_pool_size' and volume name for better diagnostics
  • Simplify missing pool errors in _create paths to avoid referencing _blivet_pool._device.name when the device is None and to report only the volume name
library/blivet.py

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
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 - I've left some high level feedback:

  • In _get_params_create_vdo, the updated error message now interpolates pool_size, but if _trim_size raises BlivetAnsibleError before assigning to pool_size, this will cause an UnboundLocalError; consider computing and storing the human‑readable size before the try, or guarding against pool_size being undefined in the exception path.
  • The renames from encryption_key_file to encryption_key and from encryption_passphrase to encryption_password in _update_from_device and _look_up_device should be checked for consistency with other uses of these keys within this module to avoid mismatched dictionary lookups at runtime.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `_get_params_create_vdo`, the updated error message now interpolates `pool_size`, but if `_trim_size` raises `BlivetAnsibleError` before assigning to `pool_size`, this will cause an `UnboundLocalError`; consider computing and storing the human‑readable size before the try, or guarding against `pool_size` being undefined in the exception path.
- The renames from `encryption_key_file` to `encryption_key` and from `encryption_passphrase` to `encryption_password` in `_update_from_device` and `_look_up_device` should be checked for consistency with other uses of these keys within this module to avoid mismatched dictionary lookups at runtime.

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
Copy Markdown

codecov Bot commented Mar 23, 2026

Codecov Report

❌ Patch coverage is 0% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 10.33%. Comparing base (59fd1c6) to head (b89cafa).
⚠️ Report is 127 commits behind head on main.

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

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

HEAD has 1 upload less than BASE
Flag BASE (59fd1c6) HEAD (b89cafa)
sanity 1 0
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #601      +/-   ##
==========================================
- Coverage   16.54%   10.33%   -6.22%     
==========================================
  Files           2        8       +6     
  Lines         284     2023    +1739     
  Branches       79        0      -79     
==========================================
+ Hits           47      209     +162     
- Misses        237     1814    +1577     
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.

self._blivet_pool._device is None in these error paths
It's 'encryption_key' for key file and 'encryption_password' for
password/passphrase.
@vojtechtrefny vojtechtrefny changed the title Multiple small fixes: error messages and encryption parameters fix: error messages and encryption parameters Mar 23, 2026
@richm richm changed the title fix: error messages and encryption parameters fix: use correct encryption_key parameter, improve error messages Mar 23, 2026
@richm
Copy link
Copy Markdown
Contributor

richm commented Mar 23, 2026

[citest]

@richm richm merged commit 5137e76 into linux-system-roles:main Mar 23, 2026
34 of 41 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