From: Aashish Sharma Date: Mon, 25 Jul 2022 08:18:39 +0000 (+0530) Subject: mgr/dashboard: Show error on creating service with duplicate service id X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=168e94416b0f6757ee2b7c268106cd1356618d41;p=ceph.git mgr/dashboard: Show error on creating service with duplicate service id Resolves: rhbz#2064850 Fixes: https://tracker.ceph.com/issues/56689 Signed-off-by: Aashish Sharma (cherry picked from commit 07cfd44193f6ebd552d13325858e8b5b5c131bfb) (cherry picked from commit 3afb825a683bea24b691fc6887ba8923469ff440) --- diff --git a/src/pybind/mgr/dashboard/controllers/service.py b/src/pybind/mgr/dashboard/controllers/service.py index d3ba882a1d926..afe684302b160 100644 --- a/src/pybind/mgr/dashboard/controllers/service.py +++ b/src/pybind/mgr/dashboard/controllers/service.py @@ -3,12 +3,11 @@ from typing import Dict, List, Optional import cherrypy from ceph.deployment.service_spec import ServiceSpec -from ..exceptions import DashboardException from ..security import Scope -from ..services.exception import handle_orchestrator_error +from ..services.exception import handle_custom_error, handle_orchestrator_error from ..services.orchestrator import OrchClient, OrchFeature from . import APIDoc, APIRouter, CreatePermission, DeletePermission, Endpoint, \ - ReadPermission, RESTController, Task + ReadPermission, RESTController, Task, UpdatePermission from .orchestrator import raise_if_no_orchestrator @@ -50,6 +49,7 @@ class Service(RESTController): return [d.to_dict() for d in daemons] @CreatePermission + @handle_custom_error('service', exceptions=(ValueError, TypeError)) @raise_if_no_orchestrator([OrchFeature.SERVICE_CREATE]) @handle_orchestrator_error('service') @service_task('create', {'service_name': '{service_name}'}) @@ -59,11 +59,22 @@ class Service(RESTController): :param service_name: The service name, e.g. 'alertmanager'. :return: None """ - try: - orch = OrchClient.instance() - orch.services.apply(service_spec) - except (ValueError, TypeError) as e: - raise DashboardException(e, component='service') + + OrchClient.instance().services.apply(service_spec, no_overwrite=True) + + @UpdatePermission + @handle_custom_error('service', exceptions=(ValueError, TypeError)) + @raise_if_no_orchestrator([OrchFeature.SERVICE_CREATE]) + @handle_orchestrator_error('service') + @service_task('edit', {'service_name': '{service_name}'}) + def set(self, service_spec: Dict, service_name: str): # pylint: disable=W0613 + """ + :param service_spec: The service specification as JSON. + :param service_name: The service name, e.g. 'alertmanager'. + :return: None + """ + + OrchClient.instance().services.apply(service_spec, no_overwrite=False) @DeletePermission @raise_if_no_orchestrator([OrchFeature.SERVICE_DELETE]) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.html b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.html index 35f61965710e4..c9cdc70b0ccec 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.html @@ -17,7 +17,8 @@