Skip to content

Commit 863964d

Browse files
authored
Merge pull request ceph#61123 from rhcs-dashboard/raise-smb-msg-exception
mgr/dashboard: smb raise exception for unsucessful resource update Reviewed-by: Afreen Misbah <[email protected]>
2 parents ffb4b94 + f8cff38 commit 863964d

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={
@@ -181,8 +203,9 @@ def list(self, cluster_id: str = '') -> List[Share]:
181203
[f'{self._resource}.{cluster_id}' if cluster_id else self._resource])
182204
return res['resources'] if 'resources' in res else res
183205

206+
@raise_on_failure
184207
@DeletePermission
185-
@EndpointDoc("Remove smb shares",
208+
@EndpointDoc("Remove an smb share",
186209
parameters={
187210
'cluster_id': (str, 'Unique identifier for the cluster'),
188211
'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
@@ -14939,7 +14939,7 @@ paths:
1493914939
trace.
1494014940
security:
1494114941
- jwt: []
14942-
summary: Remove smb shares
14942+
summary: Remove an smb share
1494314943
tags:
1494414944
- SMB
1494514945
/api/summary:

0 commit comments

Comments
 (0)