fix: ensure libblockdev-loop package on EL7 for loop mounts#591
fix: ensure libblockdev-loop package on EL7 for loop mounts#591richm merged 1 commit intolinux-system-roles:mainfrom
Conversation
Reviewer's GuideEnsures libblockdev-loop is installed on EL7 hosts with loop mounts to avoid blivet runtime errors, and adds an integration test that creates and cleans up a loop mount to exercise this behavior. Sequence diagram for libblockdev-loop installation on EL7 with loop mountssequenceDiagram
participant Controller
participant AnsibleRole as Role_storage
participant TargetHost
participant PackageManager
Controller->>AnsibleRole: Run tasks/main-blivet.yml
AnsibleRole->>TargetHost: Check ansible_facts.os_family and distribution_major_version
TargetHost-->>AnsibleRole: RedHat, 7
AnsibleRole->>TargetHost: Evaluate package_info.packages and ansible_facts.packages for libblockdev-loop
TargetHost-->>AnsibleRole: libblockdev-loop not present
AnsibleRole->>TargetHost: setup gather_subset: mounts
TargetHost-->>AnsibleRole: ansible_facts.mounts including /dev/loopX
AnsibleRole->>TargetHost: package libblockdev-loop state: present
TargetHost->>PackageManager: Install libblockdev-loop
PackageManager-->>TargetHost: libblockdev-loop installed
TargetHost-->>AnsibleRole: Package install result
AnsibleRole-->>Controller: Continue role execution without blivet error
Flow diagram for EL7 libblockdev-loop installation logicflowchart TD
A[Start tasks/main-blivet.yml] --> B{os_family == RedHat?}
B -->|No| Z[Skip libblockdev-loop block]
B -->|Yes| C{distribution_major_version == 7?}
C -->|No| Z
C -->|Yes| D{libblockdev-loop in package_info.packages?}
D -->|Yes| Z
D -->|No| E{libblockdev-loop in ansible_facts.packages?}
E -->|Yes| Z
E -->|No| F[setup gather_subset: mounts]
F --> G{ansible_facts.mounts has device matching ^/dev/loop?}
G -->|No| Z
G -->|Yes| H[package name: libblockdev-loop state: present
use: rhel_rpm_ostree if __storage_is_ostree else omit]
H --> Z
Z[Continue with Make sure required packages are installed]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The condition checking if
libblockdev-loopis installed mixespackage_info.packagesandansible_facts['packages']with aselectattr('name', ...)that assumes a list of objects; sinceansible_facts['packages']is typically a dict keyed by package name, consider normalizing on a single, reliable source (e.g. justpackage_infoor using'libblockdev-loop' in ansible_facts['packages']) to avoid type mismatches and make the check more robust. - In the test playbook, the loop device setup/cleanup currently uses raw
shellcommands formount/umountand directory handling; consider using themountandfilemodules where possible to make the test idempotent and less dependent on shell semantics.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The condition checking if `libblockdev-loop` is installed mixes `package_info.packages` and `ansible_facts['packages']` with a `selectattr('name', ...)` that assumes a list of objects; since `ansible_facts['packages']` is typically a dict keyed by package name, consider normalizing on a single, reliable source (e.g. just `package_info` or using `'libblockdev-loop' in ansible_facts['packages']`) to avoid type mismatches and make the check more robust.
- In the test playbook, the loop device setup/cleanup currently uses raw `shell` commands for `mount`/`umount` and directory handling; consider using the `mount` and `file` modules where possible to make the test idempotent and less dependent on shell semantics.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
[citest] |
vojtechtrefny
left a comment
There was a problem hiding this comment.
Why not add this the loop plugin vars/RedHat_7.yml? It would be installed every time, but we already install other libblockdev plugins and the loop one is the smallest one, so it shouldn't be a big problem to install it on systems without loop devices.
I thought about that - there is some risk in installing a "new" package on el7 which is supposed to be a "stable" platform - that is - the user runs the role on el7 expecting no changes, but they get the unexpected change of a new libblockdev-loop package being installed - perhaps that isn't worth worrying about |
Codecov Report✅ All modified and coverable lines are covered by tests.
Additional details and impacted files@@ Coverage Diff @@
## main #591 +/- ##
==========================================
- 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Cause: The blivet module on EL7 will try to use a function that is undefined when checking for mounts if there is a loop mount (/dev/loopX) on the system. The function is provided by the libblockdev-loop package but that isn't always installed. Consequence: The role will give an error like: "The function 'bd_loop_get_backing_file' called, but not implemented" Fix: Ensure that the libblockdev-loop package is installed on EL7. Result: The role works on EL7 when there are loop mounts. Added a test to create a loop mount. Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2bac761 to
4c96482
Compare
After further thought - I think this is the way to go - however, this means that a user who upgrades to this version of the storage role and runs the role may see an unexpected change due to the library being installed if if was not already installed - I think this issue is minor enough not to worry about it |
|
[citest] |
Cause: The blivet module on EL7 will try to use a function that is undefined when checking
for mounts if there is a loop mount (/dev/loopX) on the system. The function is provided
by the libblockdev-loop package but that isn't always installed.
Consequence: The role will give an error like:
"The function 'bd_loop_get_backing_file' called, but not implemented"
Fix: Ensure that the libblockdev-loop package is installed if there are loop mounts
on the EL7 system.
Result: The role works on EL7 when there are loop mounts.
Added a test to create a loop mount.
Signed-off-by: Rich Megginson rmeggins@redhat.com
Summary by Sourcery
Ensure EL7 systems with loop mounts have the required libblockdev-loop package installed to prevent blivet errors and add coverage for loop-mount scenarios in tests.
Bug Fixes:
Tests: