]> 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)
committerNizamudeen A <nia@redhat.com>
Tue, 9 Jul 2024 09:50:17 +0000 (15:20 +0530)
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>
src/pybind/mgr/cephadm/inventory.py
src/pybind/mgr/cephadm/module.py

index dc27f9f4fc7a4b0a6689e8cb0b9464a08550b2e7..b736807e893b1ab818f0ec0bf467151b82dc05fa 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 1def94e75630bbb1fa25ff883f6278c4f7ba33c2..62da122df06ac3f27e2cf538995ebef389ec13fc 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