Skip to content

Commit 91e7328

Browse files
adk3798nizamial09
authored andcommitted
mgr/cephadm: create OrchSecretNotFound exception type
This exception type is made to handle the formatting of errors where we try to find a cert/key in the cert/key store and can't Signed-off-by: Adam King <[email protected]>
1 parent ebcb198 commit 91e7328

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

src/pybind/mgr/cephadm/inventory.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,26 @@ class HostCacheStatus(enum.Enum):
4848
devices = 'devices'
4949

5050

51+
class OrchSecretNotFound(OrchestratorError):
52+
def __init__(
53+
self,
54+
message: Optional[str] = '',
55+
entity: Optional[str] = '',
56+
service_name: Optional[str] = '',
57+
hostname: Optional[str] = ''
58+
):
59+
if not message:
60+
message = f'No secret found for entity {entity}'
61+
if service_name:
62+
message += f' with service name {service_name}'
63+
if hostname:
64+
message += f' with hostname {hostname}'
65+
super().__init__(message)
66+
self.entity = entity
67+
self.service_name = service_name
68+
self.hostname = hostname
69+
70+
5171
class Inventory:
5272
"""
5373
The inventory stores a HostSpec for all hosts persistently.

src/pybind/mgr/cephadm/module.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
TunedProfileStore,
8888
NodeProxyCache,
8989
CertKeyStore,
90+
OrchSecretNotFound,
9091
)
9192
from .upgrade import CephadmUpgrade
9293
from .template import TemplateMgr
@@ -3148,12 +3149,7 @@ def cert_store_get_cert(
31483149
) -> str:
31493150
cert = self.cert_key_store.get_cert(entity, service_name or '', hostname or '')
31503151
if not cert:
3151-
err_msg = f'No cert found for entity {entity}'
3152-
if service_name:
3153-
err_msg += f' with service name {service_name}'
3154-
if hostname:
3155-
err_msg += f' with hostname {hostname}'
3156-
raise OrchestratorError(err_msg)
3152+
raise OrchSecretNotFound(entity=entity, service_name=service_name, hostname=hostname)
31573153
return cert
31583154

31593155
@handle_orch_error
@@ -3165,12 +3161,7 @@ def cert_store_get_key(
31653161
) -> str:
31663162
key = self.cert_key_store.get_key(entity, service_name or '', hostname or '')
31673163
if not key:
3168-
err_msg = f'No key found for entity {entity}'
3169-
if service_name:
3170-
err_msg += f' with service name {service_name}'
3171-
if hostname:
3172-
err_msg += f' with hostname {hostname}'
3173-
raise OrchestratorError(err_msg)
3164+
raise OrchSecretNotFound(entity=entity, service_name=service_name, hostname=hostname)
31743165
return key
31753166

31763167
@handle_orch_error

0 commit comments

Comments
 (0)