From: John Mulligan Date: Thu, 2 May 2024 20:33:01 +0000 (-0400) Subject: mgr/smb: add result type for reporting resource validation errors X-Git-Tag: v20.0.0~1709^2~8 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d438ee9bcbb2d784cf6afedd77493af0cc9d2fec;p=ceph.git mgr/smb: add result type for reporting resource validation errors 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 --- diff --git a/src/pybind/mgr/smb/results.py b/src/pybind/mgr/smb/results.py index 0d9f9605e8ca..e6a2bb83e07b 100644 --- a/src/pybind/mgr/smb/results.py +++ b/src/pybind/mgr/smb/results.py @@ -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."""