self.assertIsInstance(data, dict)
self.assertIsNotNone(data)
+
+ @authenticate
+ def test_cephfs_mds_counters_wrong(self):
+ data = self._get("/api/cephfs/mds_counters/baadbaad")
+ self.assertStatus(400)
+ self.assertJsonBody({
+ "component": 'cephfs',
+ "code": "invalid_cephfs_id",
+ "detail": "Invalid cephfs id baadbaad"
+ })
+
cls._ceph_cmd(['osd', 'pool', 'delete', name, name, '--yes-i-really-really-mean-it'])
cls._ceph_cmd(['osd', 'erasure-code-profile', 'rm', 'ecprofile'])
-
-
-
@authenticate
def test_pool_list(self):
data = self._get("/api/pool")
for data in pools:
self._pool_create(data)
+ @authenticate
+ def test_pool_create_fail(self):
+ data = {'pool_type': u'replicated', 'rule_name': u'dnf', 'pg_num': u'8', 'pool': u'sadfs'}
+ self._post('/api/pool/', data)
+ self.assertStatus(400)
+ self.assertJsonBody({
+ 'component': 'pool',
+ 'code': "2",
+ 'detail': "specified rule dnf doesn't exist"
+ })
+
@authenticate
def test_pool_info(self):
info_data = self._get("/api/pool/_info")
import cherrypy
+from ..exceptions import DashboardException
from . import ApiController, AuthRequired, BaseController
from .. import mgr
from ..services.ceph_service import CephService
try:
return int(fs_id)
except ValueError:
- raise cherrypy.HTTPError(400, "Invalid cephfs id {}".format(fs_id))
+ raise DashboardException(code='invalid_cephfs_id',
+ msg="Invalid cephfs id {}".format(fs_id),
+ component='cephfs')
def _get_mds_names(self, filesystem_id=None):
names = []
# -*- coding: utf-8 -*-
from __future__ import absolute_import
-import json
-
-from mgr_module import CommandResult
-
from . import ApiController, AuthRequired, RESTController
-from .. import logger, mgr
+from .. import mgr
from ..services.ceph_service import CephService
+from ..services.exception import handle_send_command_error
@ApiController('osd')
osds[str(osd['id'])] = osd
return osds
+ @handle_send_command_error('osd')
def get(self, svc_id):
- result = CommandResult('')
- mgr.send_command(result, 'osd', svc_id,
- json.dumps({
- 'prefix': 'perf histogram dump',
- }),
- '')
- r, outb, outs = result.wait()
- if r != 0:
- logger.warning('Failed to load histogram for OSD %s', svc_id)
- logger.debug(outs)
- histogram = outs
- else:
- histogram = json.loads(outb)
+ histogram = CephService.send_command('osd', srv_spec=svc_id, prefix='perf histogram dump')
return {
'osd_map': self.get_osd_map()[svc_id],
'osd_metadata': mgr.get_metadata('osd', svc_id),
from . import ApiController, RESTController, AuthRequired
from .. import mgr
from ..services.ceph_service import CephService
+from ..services.exception import handle_send_command_error
@ApiController('pool')
def get(self, pool_name, attrs=None, stats=False):
pools = self.list(attrs, stats)
- return [pool for pool in pools if pool['pool_name'] == pool_name][0]
+ pool = [pool for pool in pools if pool['pool_name'] == pool_name]
+ if not pool:
+ return cherrypy.NotFound('No such pool')
+ return pool[0]
+ @handle_send_command_error('pool')
def delete(self, pool_name):
return CephService.send_command('mon', 'osd pool delete', pool=pool_name, pool2=pool_name,
sure='--yes-i-really-really-mean-it')
+ @handle_send_command_error('pool')
def create(self, pool, pg_num, pool_type, erasure_code_profile=None, flags=None,
application_metadata=None, rule_name=None, **kwargs):
ecp = erasure_code_profile if erasure_code_profile else None
from .. import logger, mgr
from ..services.ceph_service import CephService
from ..tools import ViewCache
+from ..services.exception import handle_rbd_error
@ViewCache()
mirror_mode = rbdctx.mirror_mode_get(ioctx)
except: # noqa pylint: disable=W0702
logger.exception("Failed to query mirror mode %s", pool_name)
+ mirror_mode = None
stats = {}
if mirror_mode == rbd.RBD_MIRROR_MODE_DISABLED:
@cherrypy.expose
@cherrypy.tools.json_out()
+ @handle_rbd_error()
def __call__(self):
status, content_data = self._get_content_data()
return {'status': status, 'content_data': content_data}
pass
except: # noqa pylint: disable=W0702
logger.exception("Failed to list mirror image status %s", pool_name)
+ raise
return data
pool_names = [pool['pool_name'] for pool in CephService.get_pool_list('rbd')]
_, data = get_daemons_and_pools()
- if isinstance(data, Exception):
- logger.exception("Failed to get rbd-mirror daemons list")
- raise type(data)(str(data))
daemons = data.get('daemons', [])
pool_stats = data.get('pools', {})
}
service = CephService.get_service('rgw', svc_id)
if not service:
- return daemon
+ raise cherrypy.NotFound('Service rgw {} is not available'.format(svc_id))
metadata = service['metadata']
status = service['status']
import cherrypy
+from .. import mgr
from . import AuthRequired, ApiController, BaseController
-from .. import logger, mgr
from ..controllers.rbd_mirroring import get_daemons_and_pools
+from ..tools import ViewCacheNoDataException
from ..services.ceph_service import CephService
from ..tools import TaskManager
]
def _rbd_mirroring(self):
- _, data = get_daemons_and_pools()
+ try:
+ _, data = get_daemons_and_pools()
+ except ViewCacheNoDataException:
+ return {}
- if isinstance(data, Exception):
- logger.exception("Failed to get rbd-mirror daemons and pools")
- raise type(data)(str(data))
- else:
- daemons = data.get('daemons', [])
- pools = data.get('pools', {})
+ daemons = data.get('daemons', [])
+ pools = data.get('pools', {})
warnings = 0
errors = 0