-
Notifications
You must be signed in to change notification settings - Fork 61
fix: check for no disks specified and report correct error #575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Cause: The code did not check for missing or empty disks in the right place. Consequence: The role would issue a strange error which did not indicate that the problem is that no disks were specified. Fix: Check for missing disks early and report appropriate error. Result: The role will report an appropriate error message if no disks are specified. Signed-off-by: Rich Megginson <rmeggins@redhat.com>
Reviewer's GuideAdds an early check in BlivetDiskVolume to handle volumes with no disks specified by returning None as the device id, and extends the Ansible test suite to cover the no-disks error case plus generated tests for multiple partition layouts on NVMe and SCSI. Class diagram for updated BlivetDiskVolume device id handlingclassDiagram
class BlivetVolume {
+dict _volume
+string name
+string id
+get_device_id()
+_type_check()
}
class BlivetDiskVolume {
+dict _volume
+string name
+string id
+_get_device_id() string
+_type_check()
}
BlivetVolume <|-- BlivetDiskVolume
BlivetVolume : _volume holds volume configuration
BlivetDiskVolume : blivet_device_class = devices.DiskDevice
BlivetDiskVolume : _get_device_id() checks _volume.disks
BlivetDiskVolume : if _volume.disks missing or empty returns None
BlivetDiskVolume : if _volume.disks nonempty returns first disk identifier
Flow diagram for BlivetDiskVolume _get_device_id no-disks error handlingflowchart TD
A[Start _get_device_id] --> B[Read disks from _volume using key disks with default empty list]
B --> C{Is disks empty?}
C -- Yes --> D[Return None as device id]
C -- No --> E[Select first element of disks]
E --> F[Return first disk as device id]
D --> G[Caller detects missing device id and reports no disks specified error]
F --> H[Caller continues with disk operations]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey - I've found 1 issue, and left some high level feedback:
- In
BlivetDiskVolume._get_device_id, you build adiskslocal variable but then ignore it in the return; consider usingdisks[0]for consistency and to avoid duplicating the lookup logic. - Returning
Nonefrom_get_device_idto represent "no disks" relies on implicit behavior further up the stack; consider handling this case more explicitly (e.g., by raising a clear error or performing the validation at the call site) so the failure mode is easier to follow in the code.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `BlivetDiskVolume._get_device_id`, you build a `disks` local variable but then ignore it in the return; consider using `disks[0]` for consistency and to avoid duplicating the lookup logic.
- Returning `None` from `_get_device_id` to represent "no disks" relies on implicit behavior further up the stack; consider handling this case more explicitly (e.g., by raising a clear error or performing the validation at the call site) so the failure mode is easier to follow in the code.
## Individual Comments
### Comment 1
<location> `library/blivet.py:943-944` </location>
<code_context>
blivet_device_class = devices.DiskDevice
def _get_device_id(self):
+ disks = self._volume.get('disks', [])
+ if not disks:
+ return None
return self._volume['disks'][0]
</code_context>
<issue_to_address>
**question (bug_risk):** Clarify the intended behavior change when `disks` is missing or empty (now returning `None`).
Previously this would raise a `KeyError`/`IndexError` when `disks` was missing or empty; now it returns `None`. Please confirm all callers either expect `None` as a valid "no device" value or explicitly handle it, rather than relying on the earlier exception behavior.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| disks = self._volume.get('disks', []) | ||
| if not disks: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question (bug_risk): Clarify the intended behavior change when disks is missing or empty (now returning None).
Previously this would raise a KeyError/IndexError when disks was missing or empty; now it returns None. Please confirm all callers either expect None as a valid "no device" value or explicitly handle it, rather than relying on the earlier exception behavior.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #575 +/- ##
==========================================
- Coverage 16.54% 10.34% -6.21%
==========================================
Files 2 8 +6
Lines 284 2020 +1736
Branches 79 0 -79
==========================================
+ Hits 47 209 +162
- Misses 237 1811 +1574
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:
|
|
[citest] |
|
[citest] |
|
testing farm ci is broken :-( investigating |
Cause: The code did not check for missing or empty disks in the right place.
Consequence: The role would issue a strange error which did not indicate that the
problem is that no disks were specified.
Fix: Check for missing disks early and report appropriate error.
Result: The role will report an appropriate error message if no disks
are specified.
Signed-off-by: Rich Megginson rmeggins@redhat.com
Summary by Sourcery
Improve disk volume handling when no disks are specified and extend coverage with new storage tests.
Bug Fixes:
Tests: