27
27
from .._error_codes import (
28
28
PoolAllocSpaceErrorCode ,
29
29
PoolDeviceSizeChangeCode ,
30
- PoolMaintenanceErrorCode ,
30
+ PoolEncryptionErrorCode ,
31
+ PoolErrorCodeType ,
31
32
)
32
33
from .._errors import StratisCliResourceNotFoundError
33
34
from .._stratisd_constants import MetadataVersion , PoolActionAvailability
@@ -56,6 +57,17 @@ def _metadata_version(mopool) -> Optional[MetadataVersion]:
56
57
return None
57
58
58
59
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
+
59
71
# This method is only used with legacy pools
60
72
def _non_existent_or_inconsistent_to_str (
61
73
value ,
@@ -133,13 +145,7 @@ def __init__(self, devs):
133
145
"""
134
146
(self .increased , self .decreased ) = DefaultAlerts ._pools_with_changed_devs (devs )
135
147
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 ]:
143
149
"""
144
150
Return error code objects for a pool.
145
151
@@ -158,10 +164,30 @@ def alert_codes(
158
164
pool_object_path , self .increased , self .decreased
159
165
)
160
166
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
+
161
186
return (
162
187
availability_error_codes
163
188
+ no_alloc_space_error_codes
164
189
+ device_size_changed_codes
190
+ + pool_encryption_error_codes
165
191
)
166
192
167
193
@staticmethod
0 commit comments