]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/smb: make InvalidResourceError based on ErrorResponseBase
authorJohn Mulligan <jmulligan@redhat.com>
Wed, 8 May 2024 17:39:30 +0000 (13:39 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Mon, 24 Jun 2024 12:41:08 +0000 (08:41 -0400)
Make InvalidResourceError based on ErrorResponseBase as well as
ValueError for consistency with the InvalidInputError class and in the
case it ever fails to be wrapped by a Response type.

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

index ea6b6585cd925c432e21ffe04cf20103594aafe5..7ef25f4f0a22e7e2807377ffc4823878d62c129f 100644 (file)
@@ -37,11 +37,22 @@ def _present(data: Simplified) -> bool:
     return _get_intent(data) == Intent.PRESENT
 
 
-class InvalidResourceError(ValueError):
+class InvalidResourceError(ValueError, ErrorResponseBase):
     def __init__(self, msg: str, data: Simplified) -> None:
         super().__init__(msg)
         self.resource_data = data
 
+    def to_simplified(self) -> Simplified:
+        return {
+            'resource': self.resource_data,
+            'msg': str(self),
+            'success': False,
+        }
+
+    def format_response(self) -> Tuple[int, str, str]:
+        data = json.dumps(self.to_simplified())
+        return -errno.EINVAL, data, "Invalid resource"
+
     @classmethod
     def wrap(cls, err: Exception, data: Simplified) -> Exception:
         if isinstance(err, ValueError) and not isinstance(