mirror of
https://github.com/ceph/ceph
synced 2025-01-02 17:12:31 +00:00
Merge pull request #32234 from votdev/better_orch_exception
mgr/dashboard: Throw a more meaningful exception Reviewed-by: Sebastian Wagner <swagner@suse.com> Reviewed-by: Tatjana Dehler <tdehler@suse.com> Reviewed-by: Tiago Melo <tmelo@suse.com>
This commit is contained in:
commit
1c18ca31fd
@ -89,3 +89,17 @@ class HostControllerTest(DashboardTestCase):
|
||||
'path': str
|
||||
}))
|
||||
})))
|
||||
|
||||
|
||||
class HostControllerNoOrchestratorTest(DashboardTestCase):
|
||||
def test_host_create(self):
|
||||
self._post('/api/host?hostname=foo')
|
||||
self.assertStatus(503)
|
||||
self.assertError(code='orchestrator_status_unavailable',
|
||||
component='orchestrator')
|
||||
|
||||
def test_host_delete(self):
|
||||
self._delete('/api/host/bar')
|
||||
self.assertStatus(503)
|
||||
self.assertError(code='orchestrator_status_unavailable',
|
||||
component='orchestrator')
|
||||
|
@ -4,6 +4,7 @@ import copy
|
||||
|
||||
from mgr_util import merge_dicts
|
||||
from . import ApiController, RESTController, Task
|
||||
from .orchestrator import raise_if_no_orchestrator
|
||||
from .. import mgr
|
||||
from ..exceptions import DashboardException
|
||||
from ..security import Scope
|
||||
@ -66,15 +67,17 @@ class Host(RESTController):
|
||||
from_orchestrator = 'orchestrator' in _sources
|
||||
return get_hosts(from_ceph, from_orchestrator)
|
||||
|
||||
@host_task('add', {'hostname': '{hostname}'})
|
||||
@raise_if_no_orchestrator
|
||||
@handle_orchestrator_error('host')
|
||||
@host_task('add', {'hostname': '{hostname}'})
|
||||
def create(self, hostname):
|
||||
orch_client = OrchClient.instance()
|
||||
self._check_orchestrator_host_op(orch_client, hostname, True)
|
||||
orch_client.hosts.add(hostname)
|
||||
|
||||
@host_task('remove', {'hostname': '{hostname}'})
|
||||
@raise_if_no_orchestrator
|
||||
@handle_orchestrator_error('host')
|
||||
@host_task('remove', {'hostname': '{hostname}'})
|
||||
def delete(self, hostname):
|
||||
orch_client = OrchClient.instance()
|
||||
self._check_orchestrator_host_op(orch_client, hostname, False)
|
||||
@ -87,10 +90,6 @@ class Host(RESTController):
|
||||
:param add: True for adding host operation, False for removing host
|
||||
:raise DashboardException
|
||||
"""
|
||||
if not orch_client.available():
|
||||
raise DashboardException(code='orchestrator_status_unavailable',
|
||||
msg='Orchestrator is unavailable',
|
||||
component='orchestrator')
|
||||
host = orch_client.hosts.get(hostname)
|
||||
if add_host and host:
|
||||
raise DashboardException(
|
||||
|
@ -4,8 +4,6 @@ import os.path
|
||||
|
||||
import time
|
||||
|
||||
import cherrypy
|
||||
|
||||
try:
|
||||
from ceph.deployment.drive_group import DriveGroupSpec, DriveGroupValidationError
|
||||
except ImportError:
|
||||
@ -64,7 +62,10 @@ def raise_if_no_orchestrator(method):
|
||||
def inner(self, *args, **kwargs):
|
||||
orch = OrchClient.instance()
|
||||
if not orch.available():
|
||||
raise cherrypy.HTTPError(503)
|
||||
raise DashboardException(code='orchestrator_status_unavailable',
|
||||
msg='Orchestrator is unavailable',
|
||||
component='orchestrator',
|
||||
http_status_code=503)
|
||||
return method(self, *args, **kwargs)
|
||||
return inner
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user