]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: create OrchSecretNotFound exception type
authorAdam King <adking@redhat.com>
Mon, 8 Jul 2024 21:08:00 +0000 (17:08 -0400)
committerAdam King <adking@redhat.com>
Fri, 12 Jul 2024 13:09:40 +0000 (09:09 -0400)
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 <adking@redhat.com>
(cherry picked from commit 91e7328b033cec89641b53ec29cef14715970aec)

src/pybind/mgr/cephadm/inventory.py
src/pybind/mgr/cephadm/module.py

index 221918d25c7328f518d81fbbd9a027be4efbaf16..ca7a8e8988561d2ad26d2dee79a07c742e87f439 100644 (file)
@@ -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.
index 8af13722001a79d0726a63ac915380c0fc805ef6..bebd6361a27cf96aa00723832651829fd46bfea2 100644 (file)
@@ -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