From f4d3b23555042bfdd6cd0df81b28ed16d66ef94b Mon Sep 17 00:00:00 2001 From: Tiago Melo Date: Tue, 8 May 2018 16:16:29 +0100 Subject: [PATCH] mgr/dashboard: Refactor CephFS controller Signed-off-by: Tiago Melo --- qa/tasks/mgr/dashboard/test_cephfs.py | 23 ++++++++++++----- .../mgr/dashboard/controllers/cephfs.py | 25 +++++++++++-------- .../src/app/shared/api/cephfs.service.ts | 10 +++++--- 3 files changed, 38 insertions(+), 20 deletions(-) diff --git a/qa/tasks/mgr/dashboard/test_cephfs.py b/qa/tasks/mgr/dashboard/test_cephfs.py index 351b8745ee1..9560a957d25 100644 --- a/qa/tasks/mgr/dashboard/test_cephfs.py +++ b/qa/tasks/mgr/dashboard/test_cephfs.py @@ -10,16 +10,16 @@ class CephfsTest(DashboardTestCase): @authenticate def test_cephfs_clients(self): fs_id = self.fs.get_namespace_id() - data = self._get("/api/cephfs/clients/{}".format(fs_id)) + data = self._get("/api/cephfs/{}/clients".format(fs_id)) self.assertStatus(200) self.assertIn('status', data) self.assertIn('data', data) @authenticate - def test_cephfs_data(self): + def test_cephfs_get(self): fs_id = self.fs.get_namespace_id() - data = self._get("/api/cephfs/data/{}/".format(fs_id)) + data = self._get("/api/cephfs/{}/".format(fs_id)) self.assertStatus(200) self.assertIn('cephfs', data) @@ -32,7 +32,7 @@ class CephfsTest(DashboardTestCase): @authenticate def test_cephfs_mds_counters(self): fs_id = self.fs.get_namespace_id() - data = self._get("/api/cephfs/mds_counters/{}".format(fs_id)) + data = self._get("/api/cephfs/{}/mds_counters".format(fs_id)) self.assertStatus(200) self.assertIsInstance(data, dict) @@ -40,11 +40,22 @@ class CephfsTest(DashboardTestCase): @authenticate def test_cephfs_mds_counters_wrong(self): - data = self._get("/api/cephfs/mds_counters/baadbaad") + self._get("/api/cephfs/baadbaad/mds_counters") self.assertStatus(400) self.assertJsonBody({ "component": 'cephfs', "code": "invalid_cephfs_id", - "detail": "Invalid cephfs id baadbaad" + "detail": "Invalid cephfs ID baadbaad" }) + @authenticate + def test_cephfs_list(self): + data = self._get("/api/cephfs/") + self.assertStatus(200) + self.assertIsInstance(data, list) + + cephfs = data[0] + self.assertIn('id', cephfs) + self.assertIn('mdsmap', cephfs) + self.assertIsNotNone(cephfs['id']) + self.assertIsNotNone(cephfs['mdsmap']) diff --git a/src/pybind/mgr/dashboard/controllers/cephfs.py b/src/pybind/mgr/dashboard/controllers/cephfs.py index 40f367850ff..b6cc36d21c9 100644 --- a/src/pybind/mgr/dashboard/controllers/cephfs.py +++ b/src/pybind/mgr/dashboard/controllers/cephfs.py @@ -6,7 +6,7 @@ from collections import defaultdict import cherrypy from ..exceptions import DashboardException -from . import ApiController, AuthRequired, Endpoint, BaseController +from . import ApiController, AuthRequired, RESTController from .. import mgr from ..services.ceph_service import CephService from ..tools import ViewCache @@ -14,7 +14,7 @@ from ..tools import ViewCache @ApiController('/cephfs') @AuthRequired() -class CephFS(BaseController): +class CephFS(RESTController): def __init__(self): super(CephFS, self).__init__() @@ -22,19 +22,22 @@ class CephFS(BaseController): # dict is FSCID self.cephfs_clients = {} - @Endpoint() + def list(self): + fsmap = mgr.get("fs_map") + return fsmap['filesystems'] + + def get(self, fs_id): + fs_id = self.fs_id_to_int(fs_id) + + return self.fs_status(fs_id) + + @RESTController.Resource('GET') def clients(self, fs_id): fs_id = self.fs_id_to_int(fs_id) return self._clients(fs_id) - @Endpoint() - def data(self, fs_id): - fs_id = self.fs_id_to_int(fs_id) - - return self.fs_status(fs_id) - - @Endpoint() + @RESTController.Resource('GET') def mds_counters(self, fs_id): """ Result format: map of daemon name to map of counter to list of datapoints @@ -79,7 +82,7 @@ class CephFS(BaseController): return int(fs_id) except ValueError: raise DashboardException(code='invalid_cephfs_id', - msg="Invalid cephfs id {}".format(fs_id), + msg="Invalid cephfs ID {}".format(fs_id), component='cephfs') def _get_mds_names(self, filesystem_id=None): diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/cephfs.service.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/cephfs.service.ts index a5c4994da45..81d2521779a 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/cephfs.service.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/cephfs.service.ts @@ -7,15 +7,19 @@ export class CephfsService { constructor(private http: HttpClient) {} + list() { + return this.http.get(`${this.baseURL}`); + } + getCephfs(id) { - return this.http.get(`${this.baseURL}/data/${id}`); + return this.http.get(`${this.baseURL}/${id}`); } getClients(id) { - return this.http.get(`${this.baseURL}/clients/${id}`); + return this.http.get(`${this.baseURL}/${id}/clients`); } getMdsCounters(id) { - return this.http.get(`${this.baseURL}/mds_counters/${id}`); + return this.http.get(`${this.baseURL}/${id}/mds_counters`); } }