]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: smb raise exception for unsucessful resource update 61123/head
authorPedro Gonzalez Gomez <pegonzal@redhat.com>
Tue, 17 Dec 2024 20:08:55 +0000 (21:08 +0100)
committerPedro Gonzalez Gomez <pegonzal@redhat.com>
Tue, 28 Jan 2025 16:06:24 +0000 (17:06 +0100)
Adds a decorator to raise a DashboardException with the msg error of an unsucessful smb resource update

Fixes: https://tracker.ceph.com/issues/69286
Signed-off-by: Pedro Gonzalez Gomez <pegonzal@redhat.com>
src/pybind/mgr/dashboard/controllers/smb.py
src/pybind/mgr/dashboard/openapi.yaml

index 97eff8c3dfec43ebda277fde0f410dbfe3b07b37..f2fcb2e565a6db67b638f159962ccec57bc86195 100644 (file)
@@ -3,6 +3,7 @@
 
 import json
 import logging
+from functools import wraps
 from typing import List
 
 from smb.enums import Intent
@@ -88,6 +89,26 @@ SHARE_SCHEMA = {
 }
 
 
+def raise_on_failure(func):
+    @wraps(func)
+    def wrapper(*args, **kwargs):
+        result = func(*args, **kwargs)
+
+        if isinstance(result, dict) and result.get('success') is False:
+            msg = 'Operation failed'
+
+            # Extracts the result msg from either of two possible response structures:
+            if 'results' in result:
+                msg = result['results'][0].get('msg', msg)
+            elif 'msg' in result:
+                msg = result['msg']
+            raise DashboardException(msg=msg, component='smb')
+
+        return result
+
+    return wrapper
+
+
 @APIRouter('/smb/cluster', Scope.SMB)
 @APIDoc("SMB Cluster Management API", "SMB")
 class SMBCluster(RESTController):
@@ -115,6 +136,7 @@ class SMBCluster(RESTController):
         """
         return mgr.remote('smb', 'show', [f'{self._resource}.{cluster_id}'])
 
+    @raise_on_failure
     @CreatePermission
     @EndpointDoc("Create smb cluster",
                  parameters={
@@ -163,8 +185,9 @@ class SMBShare(RESTController):
             [f'{self._resource}.{cluster_id}' if cluster_id else self._resource])
         return res['resources'] if 'resources' in res else res
 
+    @raise_on_failure
     @DeletePermission
-    @EndpointDoc("Remove smb shares",
+    @EndpointDoc("Remove an smb share",
                  parameters={
                      'cluster_id': (str, 'Unique identifier for the cluster'),
                      'share_id': (str, 'Unique identifier for the share')
index c9cd5430ec01bd409bae51b7a06a978f4808c06a..91bed6b563fe7260f8832b219180303ac863ec62 100644 (file)
@@ -14564,7 +14564,7 @@ paths:
             trace.
       security:
       - jwt: []
-      summary: Remove smb shares
+      summary: Remove an smb share
       tags:
       - SMB
   /api/summary: