Report missing dependencies when trying to create a format#1465
Report missing dependencies when trying to create a format#1465vojtechtrefny merged 2 commits intostoraged-project:mainfrom
Conversation
For devices we already report all missing dependencies, for formats only a generic error message is reported. This fixes this issue by adding a full information about missing dependencies (e.g. a missing or not loaded libblockdev plugin) and the missing tool (e.g. mkfs.xfs) as well. Fixes: storaged-project#1459
This test case needs root privilegies to work properly. Also the MD libblockdev is called "mdraid", not "md".
📝 WalkthroughWalkthroughThis PR introduces a new Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
blivet/deviceaction.py (1)
605-612: Cache_format_resourceonce before message assembly.Line 605–Line 612 repeatedly evaluate the property. Cache it locally to avoid repeated lookups and keep the block clearer.
♻️ Suggested refactor
- if not self._format.formattable: - if self._format._format_resource: - avail_errors = ", ".join(self._format._format_resource.availability_errors) - msg = "resource %s to create this format %s is unavailable: %s" % (self._format._format_resource.name, - self._format.type, - avail_errors) + if not self._format.formattable: + resource = self._format._format_resource + if resource is not None: + avail_errors = ", ".join(resource.availability_errors) + msg = "resource %s to create this format %s is unavailable: %s" % (resource.name, + self._format.type, + avail_errors) else: msg = "resource to create this format %s is unavailable" % self._format.type raise ValueError(msg)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@blivet/deviceaction.py` around lines 605 - 612, Cache self._format._format_resource into a local variable before assembling the error message to avoid repeated property access; e.g., assign format_resource = self._format._format_resource, then use format_resource (and format_resource.availability_errors and format_resource.name) when building msg, falling back to the existing else branch that uses self._format.type as needed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@tests/unit_tests/devices_test/device_dependencies_test.py`:
- Around line 198-200: The test currently passes a literal string as the regex
in assertRaisesRegex which can break if the message contains regex
metacharacters; update the assertion to pass a regex-escaped version of the
expected message (use re.escape(msg)) when calling
self.assertRaisesRegex(ValueError, ...) and add an import for the re module if
missing so the test uses re.escape(msg) to robustly match the exact message from
self.bvt.create_device(pv_fail).
---
Nitpick comments:
In `@blivet/deviceaction.py`:
- Around line 605-612: Cache self._format._format_resource into a local variable
before assembling the error message to avoid repeated property access; e.g.,
assign format_resource = self._format._format_resource, then use format_resource
(and format_resource.availability_errors and format_resource.name) when building
msg, falling back to the existing else branch that uses self._format.type as
needed.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: ce76d8cf-ea03-4d06-9041-e7f335221592
📒 Files selected for processing (8)
blivet/deviceaction.pyblivet/formats/__init__.pyblivet/formats/fs.pyblivet/formats/luks.pyblivet/formats/lvmpv.pyblivet/formats/mdraid.pyblivet/formats/swap.pytests/unit_tests/devices_test/device_dependencies_test.py
| msg = "resource libblockdev lvm plugin to create this format lvmpv is unavailable: libblockdev plugin lvm not loaded" | ||
| with self.assertRaisesRegex(ValueError, msg): | ||
| self.bvt.create_device(pv_fail) |
There was a problem hiding this comment.
Escape the expected message when using assertRaisesRegex.
Line 198–Line 200 pass a literal string as a regex pattern; this is fragile if the message gains regex-special characters or minor formatting changes.
🧪 Suggested fix
import os
+import re
import unittest- with self.assertRaisesRegex(ValueError, msg):
+ with self.assertRaisesRegex(ValueError, re.escape(msg)):
self.bvt.create_device(pv_fail)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@tests/unit_tests/devices_test/device_dependencies_test.py` around lines 198 -
200, The test currently passes a literal string as the regex in
assertRaisesRegex which can break if the message contains regex metacharacters;
update the assertion to pass a regex-escaped version of the expected message
(use re.escape(msg)) when calling self.assertRaisesRegex(ValueError, ...) and
add an import for the re module if missing so the test uses re.escape(msg) to
robustly match the exact message from self.bvt.create_device(pv_fail).
Fixes: #1459
Summary by CodeRabbit
Release Notes