Skip to content

Commit f8cff38

Browse files
committed
mgr/dashboard: smb raise exception for unsucessful resource update
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 <[email protected]>
1 parent 856b47f commit f8cff38

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/pybind/mgr/dashboard/controllers/smb.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import json
55
import logging
6+
from functools import wraps
67
from typing import List
78

89
from smb.enums import Intent
@@ -88,6 +89,26 @@
8889
}
8990

9091

92+
def raise_on_failure(func):
93+
@wraps(func)
94+
def wrapper(*args, **kwargs):
95+
result = func(*args, **kwargs)
96+
97+
if isinstance(result, dict) and result.get('success') is False:
98+
msg = 'Operation failed'
99+
100+
# Extracts the result msg from either of two possible response structures:
101+
if 'results' in result:
102+
msg = result['results'][0].get('msg', msg)
103+
elif 'msg' in result:
104+
msg = result['msg']
105+
raise DashboardException(msg=msg, component='smb')
106+
107+
return result
108+
109+
return wrapper
110+
111+
91112
@APIRouter('/smb/cluster', Scope.SMB)
92113
@APIDoc("SMB Cluster Management API", "SMB")
93114
class SMBCluster(RESTController):
@@ -115,6 +136,7 @@ def get(self, cluster_id: str) -> Cluster:
115136
"""
116137
return mgr.remote('smb', 'show', [f'{self._resource}.{cluster_id}'])
117138

139+
@raise_on_failure
118140
@CreatePermission
119141
@EndpointDoc("Create smb cluster",
120142
parameters={
@@ -163,8 +185,9 @@ def list(self, cluster_id: str = '') -> List[Share]:
163185
[f'{self._resource}.{cluster_id}' if cluster_id else self._resource])
164186
return res['resources'] if 'resources' in res else res
165187

188+
@raise_on_failure
166189
@DeletePermission
167-
@EndpointDoc("Remove smb shares",
190+
@EndpointDoc("Remove an smb share",
168191
parameters={
169192
'cluster_id': (str, 'Unique identifier for the cluster'),
170193
'share_id': (str, 'Unique identifier for the share')

src/pybind/mgr/dashboard/openapi.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14564,7 +14564,7 @@ paths:
1456414564
trace.
1456514565
security:
1456614566
- jwt: []
14567-
summary: Remove smb shares
14567+
summary: Remove an smb share
1456814568
tags:
1456914569
- SMB
1457014570
/api/summary:

0 commit comments

Comments
 (0)