]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/smb: convert failures to create a valid resource into error results
authorJohn Mulligan <jmulligan@redhat.com>
Thu, 2 May 2024 20:40:53 +0000 (16:40 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Mon, 17 Jun 2024 15:16:59 +0000 (11:16 -0400)
Convert failures to create a valid resource into error results that can
be reported back to the caller like the other error result types
generated by actually attempting to apply the resources.

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

index 34bab3c82a046fa4d9aa8c66379b368187a810de..d8133a59c478960c4fc843606fdbfb3e2df9c59d 100644 (file)
@@ -63,7 +63,14 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule):
         """Create, update, or remove smb configuration resources based on YAML
         or JSON specs
         """
-        return self._handler.apply(resources.load_text(inbuf))
+        try:
+            return self._handler.apply(resources.load_text(inbuf))
+        except resources.InvalidResourceError as err:
+            # convert the exception into a result and return it as the only
+            # item in the result group
+            return results.ResultGroup(
+                [results.InvalidResourceResult(err.resource_data, str(err))]
+            )
 
     @cli.SMBCommand('cluster ls', perm='r')
     def cluster_ls(self) -> List[str]: