-
Notifications
You must be signed in to change notification settings - Fork 21
Lookup blockdev D-Bus properties without raising not found exception #1250
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,7 +44,9 @@ | |
| from ._constants import TOP_OBJECT | ||
| from ._formatting import ( | ||
| TABLE_FAILURE_STRING, | ||
| TABLE_UNKNOWN_STRING, | ||
| TOTAL_USED_FREE, | ||
| catch_missing_property, | ||
| get_property, | ||
| print_table, | ||
| ) | ||
|
|
@@ -452,7 +454,7 @@ def __init__(self, uuid_formatter: Callable[[str | UUID], str]): | |
| """ | ||
| self.uuid_formatter = uuid_formatter | ||
|
|
||
| def display(self): | ||
| def display(self): # pylint: disable=too-many-locals | ||
| """ | ||
| List pools in table view. | ||
| """ | ||
|
|
@@ -526,21 +528,34 @@ def gen_string(has_property: bool, code: str) -> str: | |
| (objpath, MOPool(info)) for objpath, info in pools().search(managed_objects) | ||
| ] | ||
|
|
||
| name_func = catch_missing_property(lambda mo: mo.Name(), TABLE_UNKNOWN_STRING) | ||
| size_func = catch_missing_property(physical_size_triple, TABLE_UNKNOWN_STRING) | ||
| properties_func = catch_missing_property( | ||
| properties_string, TABLE_UNKNOWN_STRING | ||
| ) | ||
| uuid_func = catch_missing_property( | ||
| lambda mo: self.uuid_formatter(mo.Uuid()), TABLE_UNKNOWN_STRING | ||
| ) | ||
|
|
||
| def alert_func(pool_object_path: str, mopool: Any) -> List[str]: | ||
| """ | ||
| Combined alert codes. | ||
| """ | ||
| return [ | ||
| str(code) | ||
| for code in catch_missing_property( | ||
| Default.alert_codes, default=[TABLE_UNKNOWN_STRING] | ||
| )(mopool) | ||
| + alerts.alert_codes(pool_object_path) | ||
| ] | ||
|
Comment on lines
+540
to
+550
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This still fails on missing blockdev size properties. Line 525 builds 🤖 Prompt for AI Agents |
||
|
|
||
| tables = [ | ||
| ( | ||
| mopool.Name(), | ||
| physical_size_triple(mopool), | ||
| properties_string(mopool), | ||
| self.uuid_formatter(mopool.Uuid()), | ||
| ", ".join( | ||
| sorted( | ||
| str(code) | ||
| for code in ( | ||
| Default.alert_codes(mopool) | ||
| + alerts.alert_codes(pool_object_path) | ||
| ) | ||
| ) | ||
| ), | ||
| name_func(mopool), | ||
| size_func(mopool), | ||
| properties_func(mopool), | ||
| uuid_func(mopool), | ||
| ", ".join(sorted(alert_func(pool_object_path, mopool))), | ||
| ) | ||
| for (pool_object_path, mopool) in pools_with_props | ||
| ] | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -279,11 +279,11 @@ class SizeTriple: | |||||||||||||||||
| Manage values in a size triple. | ||||||||||||||||||
| """ | ||||||||||||||||||
|
|
||||||||||||||||||
| def __init__(self, total: Range, used: Optional[Range]): | ||||||||||||||||||
| def __init__(self, total: Optional[Range], used: Optional[Range]): | ||||||||||||||||||
| self._total = total | ||||||||||||||||||
| self._used = used | ||||||||||||||||||
|
|
||||||||||||||||||
| def total(self) -> Range: | ||||||||||||||||||
| def total(self) -> Optional[Range]: | ||||||||||||||||||
| """ | ||||||||||||||||||
| Total. | ||||||||||||||||||
| """ | ||||||||||||||||||
|
|
@@ -299,4 +299,8 @@ def free(self) -> Optional[Range]: | |||||||||||||||||
| """ | ||||||||||||||||||
| Total - used. | ||||||||||||||||||
| """ | ||||||||||||||||||
| return None if self._used is None else self._total - self._used | ||||||||||||||||||
| return ( | ||||||||||||||||||
| None | ||||||||||||||||||
| if self._used is None or self.total is None | ||||||||||||||||||
| else self._total - self._used | ||||||||||||||||||
|
Comment on lines
+302
to
+305
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix the
🛠️ Suggested fix return (
None
- if self._used is None or self.total is None
+ if self._used is None or self._total is None
else self._total - self._used
)📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
| ) | ||||||||||||||||||
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.
Apply the same missing-property guard to
DefaultDetail.These wrappers only harden
DefaultTable.display().pool list --name/--uuidstill goes throughDefaultDetail._print_detail_view(), which directly readsName(),AvailableActions(), size fields, and other D-Bus properties, so missing fields will still terminate the detail path.🤖 Prompt for AI Agents