From d438ee9bcbb2d784cf6afedd77493af0cc9d2fec Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Thu, 2 May 2024 16:33:01 -0400 Subject: [PATCH] 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 --- src/pybind/mgr/smb/results.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/pybind/mgr/smb/results.py b/src/pybind/mgr/smb/results.py index 0d9f9605e8c..e6a2bb83e07 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.""" -- 2.39.5