Skip to content

Commit 5c743aa

Browse files
committed
Calculate encryption codes for pool
Signed-off-by: mulhern <[email protected]>
1 parent 8278782 commit 5c743aa

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

src/stratis_cli/_actions/_list_pool.py

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
from .._error_codes import (
2828
PoolAllocSpaceErrorCode,
2929
PoolDeviceSizeChangeCode,
30-
PoolMaintenanceErrorCode,
30+
PoolEncryptionErrorCode,
31+
PoolErrorCodeType,
3132
)
3233
from .._errors import StratisCliResourceNotFoundError
3334
from .._stratisd_constants import MetadataVersion, PoolActionAvailability
@@ -56,6 +57,17 @@ def _metadata_version(mopool) -> Optional[MetadataVersion]:
5657
return None
5758

5859

60+
def _volume_key_loaded(mopool) -> Union[tuple[bool, bool], tuple[bool, str]]:
61+
"""
62+
The string result is an error message indicating that the volume key
63+
state is unknown.
64+
"""
65+
result = mopool.VolumeKeyLoaded()
66+
if isinstance(result, int):
67+
return (True, bool(result))
68+
return (False, str(result)) # pragma: no cover
69+
70+
5971
# This method is only used with legacy pools
6072
def _non_existent_or_inconsistent_to_str(
6173
value,
@@ -133,13 +145,7 @@ def __init__(self, devs):
133145
"""
134146
(self.increased, self.decreased) = DefaultAlerts._pools_with_changed_devs(devs)
135147

136-
def alert_codes(
137-
self, pool_object_path, mopool
138-
) -> List[
139-
Union[
140-
PoolAllocSpaceErrorCode, PoolDeviceSizeChangeCode, PoolMaintenanceErrorCode
141-
]
142-
]:
148+
def alert_codes(self, pool_object_path, mopool) -> List[PoolErrorCodeType]:
143149
"""
144150
Return error code objects for a pool.
145151
@@ -158,10 +164,30 @@ def alert_codes(
158164
pool_object_path, self.increased, self.decreased
159165
)
160166

167+
metadata_version = _metadata_version(mopool)
168+
169+
(vkl_is_bool, volume_key_loaded) = _volume_key_loaded(mopool)
170+
171+
pool_encryption_error_codes = (
172+
[PoolEncryptionErrorCode.VOLUME_KEY_NOT_LOADED]
173+
if metadata_version is MetadataVersion.V2
174+
and mopool.Encrypted()
175+
and vkl_is_bool
176+
and not volume_key_loaded
177+
else []
178+
) + (
179+
[PoolEncryptionErrorCode.VOLUME_KEY_STATUS_UNKNOWN]
180+
if metadata_version is MetadataVersion.V2
181+
and mopool.Encrypted()
182+
and not vkl_is_bool
183+
else []
184+
)
185+
161186
return (
162187
availability_error_codes
163188
+ no_alloc_space_error_codes
164189
+ device_size_changed_codes
190+
+ pool_encryption_error_codes
165191
)
166192

167193
@staticmethod

0 commit comments

Comments
 (0)