From 91e7328b033cec89641b53ec29cef14715970aec Mon Sep 17 00:00:00 2001 From: Adam King Date: Mon, 8 Jul 2024 17:08:00 -0400 Subject: [PATCH] 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 --- src/pybind/mgr/cephadm/inventory.py | 20 ++++++++++++++++++++ src/pybind/mgr/cephadm/module.py | 15 +++------------ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/pybind/mgr/cephadm/inventory.py b/src/pybind/mgr/cephadm/inventory.py index dc27f9f4fc7a4..b736807e893b1 100644 --- a/src/pybind/mgr/cephadm/inventory.py +++ b/src/pybind/mgr/cephadm/inventory.py @@ -48,6 +48,26 @@ class HostCacheStatus(enum.Enum): devices = 'devices' +class OrchSecretNotFound(OrchestratorError): + def __init__( + self, + message: Optional[str] = '', + entity: Optional[str] = '', + service_name: Optional[str] = '', + hostname: Optional[str] = '' + ): + if not message: + message = f'No secret found for entity {entity}' + if service_name: + message += f' with service name {service_name}' + if hostname: + message += f' with hostname {hostname}' + super().__init__(message) + self.entity = entity + self.service_name = service_name + self.hostname = hostname + + class Inventory: """ The inventory stores a HostSpec for all hosts persistently. diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 1def94e75630b..62da122df06ac 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -87,6 +87,7 @@ from .inventory import ( TunedProfileStore, NodeProxyCache, CertKeyStore, + OrchSecretNotFound, ) from .upgrade import CephadmUpgrade from .template import TemplateMgr @@ -3148,12 +3149,7 @@ Then run the following: ) -> str: cert = self.cert_key_store.get_cert(entity, service_name or '', hostname or '') if not cert: - err_msg = f'No cert found for entity {entity}' - if service_name: - err_msg += f' with service name {service_name}' - if hostname: - err_msg += f' with hostname {hostname}' - raise OrchestratorError(err_msg) + raise OrchSecretNotFound(entity=entity, service_name=service_name, hostname=hostname) return cert @handle_orch_error @@ -3165,12 +3161,7 @@ Then run the following: ) -> str: key = self.cert_key_store.get_key(entity, service_name or '', hostname or '') if not key: - err_msg = f'No key found for entity {entity}' - if service_name: - err_msg += f' with service name {service_name}' - if hostname: - err_msg += f' with hostname {hostname}' - raise OrchestratorError(err_msg) + raise OrchSecretNotFound(entity=entity, service_name=service_name, hostname=hostname) return key @handle_orch_error -- 2.39.5