]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Refactor CephFS controller
authorTiago Melo <tmelo@suse.com>
Tue, 8 May 2018 15:16:29 +0000 (16:16 +0100)
committerTiago Melo <tmelo@suse.com>
Thu, 31 May 2018 21:50:43 +0000 (22:50 +0100)
Signed-off-by: Tiago Melo <tmelo@suse.com>
qa/tasks/mgr/dashboard/test_cephfs.py
src/pybind/mgr/dashboard/controllers/cephfs.py
src/pybind/mgr/dashboard/frontend/src/app/shared/api/cephfs.service.ts

index 351b8745ee18984527b7a646d225016fcd714640..9560a957d256fb36bbc6a2a39b75440c5e319a39 100644 (file)
@@ -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'])
index 40f367850fff904a0c0e9bc83efd1b8a9bdeb39c..b6cc36d21c959e3b3e3bb61427626291ccbb68fd 100644 (file)
@@ -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 clients(self, fs_id):
+    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._clients(fs_id)
+        return self.fs_status(fs_id)
 
-    @Endpoint()
-    def data(self, fs_id):
+    @RESTController.Resource('GET')
+    def clients(self, fs_id):
         fs_id = self.fs_id_to_int(fs_id)
 
-        return self.fs_status(fs_id)
+        return self._clients(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):
index a5c4994da451a1cf0ec86d81762ebf44477051f4..81d2521779a85e1ca5a99a354a70af66c55afa45 100644 (file)
@@ -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`);
   }
 }