From f8cff38a5a3e58cc1ab677fd8f8ba323be68e4c1 Mon Sep 17 00:00:00 2001 From: Pedro Gonzalez Gomez Date: Tue, 17 Dec 2024 21:08:55 +0100 Subject: [PATCH] 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 --- src/pybind/mgr/dashboard/controllers/smb.py | 25 ++++++++++++++++++++- src/pybind/mgr/dashboard/openapi.yaml | 2 +- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/pybind/mgr/dashboard/controllers/smb.py b/src/pybind/mgr/dashboard/controllers/smb.py index 97eff8c3dfec4..f2fcb2e565a6d 100644 --- a/src/pybind/mgr/dashboard/controllers/smb.py +++ b/src/pybind/mgr/dashboard/controllers/smb.py @@ -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') diff --git a/src/pybind/mgr/dashboard/openapi.yaml b/src/pybind/mgr/dashboard/openapi.yaml index c9cd5430ec01b..91bed6b563fe7 100644 --- a/src/pybind/mgr/dashboard/openapi.yaml +++ b/src/pybind/mgr/dashboard/openapi.yaml @@ -14564,7 +14564,7 @@ paths: trace. security: - jwt: [] - summary: Remove smb shares + summary: Remove an smb share tags: - SMB /api/summary: -- 2.39.5