]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/smb: add result type for reporting resource validation errors
authorJohn Mulligan <jmulligan@redhat.com>
Thu, 2 May 2024 20:33:01 +0000 (16:33 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Mon, 17 Jun 2024 15:16:59 +0000 (11:16 -0400)
This error type can not take a real resource object because the resource
object could not be constructed from the data. Use the raw data for
reporting the error result.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/pybind/mgr/smb/results.py

index 0d9f9605e8ca892b062f9427dcd94118fc1e8a97..e6a2bb83e07b80a097147a5badc728e56f4805f5 100644 (file)
@@ -56,6 +56,29 @@ class ErrorResult(Result, Exception):
         super().__init__(src, success=False, msg=msg, status=status)
 
 
+class InvalidResourceResult(Result):
+    def __init__(
+        self,
+        resource_data: Simplified,
+        msg: str = '',
+        status: Optional[Simplified] = None,
+    ) -> None:
+        self.resource_data = resource_data
+        self.success = False
+        self.msg = msg
+        self.status = status
+
+    def to_simplified(self) -> Simplified:
+        ds: Simplified = {}
+        ds['resource'] = self.resource_data
+        ds['success'] = self.success
+        if self.msg:
+            ds['msg'] = self.msg
+        if self.status:
+            ds.update(self.status)
+        return ds
+
+
 class ResultGroup:
     """Result of applying multiple smb resource updates to the system."""