]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard_v2: Renamed `block_pool` controller to `rbd`
authorSebastian Wagner <sebastian.wagner@suse.com>
Thu, 15 Feb 2018 14:51:53 +0000 (15:51 +0100)
committerRicardo Dias <rdias@suse.com>
Mon, 5 Mar 2018 13:07:10 +0000 (13:07 +0000)
* Simplified the API
* Fixed and improved the rbd controller tests.

Signed-off-by: Sebastian Wagner <sebastian.wagner@suse.com>
src/pybind/mgr/dashboard_v2/controllers/block_pool.py [deleted file]
src/pybind/mgr/dashboard_v2/controllers/rbd.py [new file with mode: 0644]
src/pybind/mgr/dashboard_v2/frontend/src/app/shared/services/pool.service.ts
src/pybind/mgr/dashboard_v2/tests/test_block_pool.py [deleted file]
src/pybind/mgr/dashboard_v2/tests/test_rbd.py [new file with mode: 0644]
src/pybind/mgr/dashboard_v2/tox.ini

diff --git a/src/pybind/mgr/dashboard_v2/controllers/block_pool.py b/src/pybind/mgr/dashboard_v2/controllers/block_pool.py
deleted file mode 100644 (file)
index c62f350..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-# -*- coding: utf-8 -*-
-from __future__ import absolute_import
-
-import cherrypy
-import rbd
-
-from ..tools import ApiController, AuthRequired, BaseController, ViewCache
-
-
-@ApiController('block_pool')
-@AuthRequired()
-class BlockPool(BaseController):
-
-    def __init__(self):
-        self.rbd = None
-
-    def _format_bitmask(self, features):
-        RBD_FEATURES_NAME_MAPPING = {
-            rbd.RBD_FEATURE_LAYERING: "layering",
-            rbd.RBD_FEATURE_STRIPINGV2: "striping",
-            rbd.RBD_FEATURE_EXCLUSIVE_LOCK: "exclusive-lock",
-            rbd.RBD_FEATURE_OBJECT_MAP: "object-map",
-            rbd.RBD_FEATURE_FAST_DIFF: "fast-diff",
-            rbd.RBD_FEATURE_DEEP_FLATTEN: "deep-flatten",
-            rbd.RBD_FEATURE_JOURNALING: "journaling",
-            rbd.RBD_FEATURE_DATA_POOL: "data-pool",
-            rbd.RBD_FEATURE_OPERATIONS: "operations",
-        }
-        names = [val for key, val in RBD_FEATURES_NAME_MAPPING.items()
-                 if key & features == key]
-        return ', '.join(sorted(names))
-
-    @ViewCache()
-    def _rbd_list(self, pool_name):
-        ioctx = self.mgr.rados.open_ioctx(pool_name)
-        self.rbd = rbd.RBD()
-        names = self.rbd.list(ioctx)
-        result = []
-        for name in names:
-            i = rbd.Image(ioctx, name)
-            stat = i.stat()
-            stat['name'] = name
-            features = i.features()
-            stat['features'] = features
-            stat['features_name'] = self._format_bitmask(features)
-
-            try:
-                parent_info = i.parent_info()
-                parent = "{}@{}".format(parent_info[0], parent_info[1])
-                if parent_info[0] != pool_name:
-                    parent = "{}/{}".format(parent_info[0], parent)
-                stat['parent'] = parent
-            except rbd.ImageNotFound:
-                pass
-            result.append(stat)
-        return result
-
-    @cherrypy.expose
-    @cherrypy.tools.json_out()
-    def rbd_pool_data(self, pool_name):
-        # pylint: disable=unbalanced-tuple-unpacking
-        status, value = self._rbd_list(pool_name)
-        if status == ViewCache.VALUE_EXCEPTION:
-            raise value
-        return {'status': status, 'value': value}
diff --git a/src/pybind/mgr/dashboard_v2/controllers/rbd.py b/src/pybind/mgr/dashboard_v2/controllers/rbd.py
new file mode 100644 (file)
index 0000000..dd03d57
--- /dev/null
@@ -0,0 +1,69 @@
+# -*- coding: utf-8 -*-
+from __future__ import absolute_import
+
+import rbd
+
+from ..tools import ApiController, AuthRequired, RESTController, ViewCache
+
+
+@ApiController('rbd')
+@AuthRequired()
+class Rbd(RESTController):
+
+    def __init__(self):
+        self.rbd = None
+
+    @staticmethod
+    def _format_bitmask(features):
+        """
+        Formats the bitmask:
+
+        >>> Rbd._format_bitmask(45)
+        'deep-flatten, exclusive-lock, layering, object-map'
+        """
+        RBD_FEATURES_NAME_MAPPING = {
+            rbd.RBD_FEATURE_LAYERING: "layering",
+            rbd.RBD_FEATURE_STRIPINGV2: "striping",
+            rbd.RBD_FEATURE_EXCLUSIVE_LOCK: "exclusive-lock",
+            rbd.RBD_FEATURE_OBJECT_MAP: "object-map",
+            rbd.RBD_FEATURE_FAST_DIFF: "fast-diff",
+            rbd.RBD_FEATURE_DEEP_FLATTEN: "deep-flatten",
+            rbd.RBD_FEATURE_JOURNALING: "journaling",
+            rbd.RBD_FEATURE_DATA_POOL: "data-pool",
+            rbd.RBD_FEATURE_OPERATIONS: "operations",
+        }
+        names = [val for key, val in RBD_FEATURES_NAME_MAPPING.items()
+                 if key & features == key]
+        return ', '.join(sorted(names))
+
+    @ViewCache()
+    def _rbd_list(self, pool_name):
+        ioctx = self.mgr.rados.open_ioctx(pool_name)
+        self.rbd = rbd.RBD()
+        names = self.rbd.list(ioctx)
+        result = []
+        for name in names:
+            i = rbd.Image(ioctx, name)
+            stat = i.stat()
+            stat['name'] = name
+            features = i.features()
+            stat['features'] = features
+            stat['features_name'] = self._format_bitmask(features)
+
+            try:
+                parent_info = i.parent_info()
+                parent = "{}@{}".format(parent_info[0], parent_info[1])
+                if parent_info[0] != pool_name:
+                    parent = "{}/{}".format(parent_info[0], parent)
+                stat['parent'] = parent
+            except rbd.ImageNotFound:
+                pass
+            result.append(stat)
+        return result
+
+    def get(self, pool_name):
+        # pylint: disable=unbalanced-tuple-unpacking
+        status, value = self._rbd_list(pool_name)
+        if status == ViewCache.VALUE_EXCEPTION:
+            raise value
+        return {'status': status, 'value': value}
index 1f404f7219728b7ba3c95d5adaf3b5fbc108276d..f92ed166da8a3070902885146e659748cbdad83b 100644 (file)
@@ -8,7 +8,7 @@ export class PoolService {
   }
 
   rbdPoolImages(pool) {
-    return this.http.get(`/api/block_pool/rbd_pool_data/${pool}`).toPromise().then((resp: any) => {
+    return this.http.get(`/api/rbd/${pool}`).toPromise().then((resp: any) => {
       return resp;
     });
   }
diff --git a/src/pybind/mgr/dashboard_v2/tests/test_block_pool.py b/src/pybind/mgr/dashboard_v2/tests/test_block_pool.py
deleted file mode 100644 (file)
index cc914f2..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-# -*- coding: utf-8 -*-
-
-from __future__ import absolute_import
-
-from .helper import ControllerTestCase, authenticate
-
-
-class BlockPoolTest(ControllerTestCase):
-
-    @classmethod
-    def setUpClass(cls):
-        cls._ceph_cmd(['osd', 'pool', 'create', 'rbd', '100', '100'])
-        cls._ceph_cmd(['osd', 'pool', 'application', 'enable', 'rbd', 'rbd'])
-        cls._rbd_cmd(['create', '--size=1G', 'img1'])
-        cls._rbd_cmd(['create', '--size=2G', 'img2'])
-
-    @classmethod
-    def tearDownClass(cls):
-        cls._ceph_cmd(['osd', 'pool', 'delete', 'rbd', '--yes-i-really-really-mean-it'])
-
-    @authenticate
-    def test_list(self):
-        data = self._get('/api/block_pool/rbd_pool_data/rbd')
-        self.assertStatus(200)
-
-        img1 = data['value'][0]
-        self.assertEqual(img1['name'], 'img1')
-        self.assertEqual(img1['size'], 1073741824)
-        self.assertEqual(img1['num_objs'], 256)
-        self.assertEqual(img1['obj_size'], 4194304)
-        self.assertEqual(img1['features_name'],
-                         'deep-flatten, exclusive-lock, fast-diff, layering, object-map')
-
-        img2 = data['value'][1]
-        self.assertEqual(img2['name'], 'img2')
-        self.assertEqual(img2['size'], 2147483648)
-        self.assertEqual(img2['num_objs'], 512)
-        self.assertEqual(img2['obj_size'], 4194304)
-        self.assertEqual(img2['features_name'],
-                         'deep-flatten, exclusive-lock, fast-diff, layering, object-map')
diff --git a/src/pybind/mgr/dashboard_v2/tests/test_rbd.py b/src/pybind/mgr/dashboard_v2/tests/test_rbd.py
new file mode 100644 (file)
index 0000000..2ebcd2f
--- /dev/null
@@ -0,0 +1,40 @@
+# -*- coding: utf-8 -*-
+
+from __future__ import absolute_import
+
+from .helper import ControllerTestCase, authenticate
+
+
+class RbdTest(ControllerTestCase):
+
+    @classmethod
+    def setUpClass(cls):
+        cls._ceph_cmd(['osd', 'pool', 'create', 'rbd', '100', '100'])
+        cls._ceph_cmd(['osd', 'pool', 'application', 'enable', 'rbd', 'rbd'])
+        cls._rbd_cmd(['create', '--size=1G', 'img1'])
+        cls._rbd_cmd(['create', '--size=2G', 'img2'])
+
+    @classmethod
+    def tearDownClass(cls):
+        cls._ceph_cmd(['osd', 'pool', 'delete', 'rbd', '--yes-i-really-really-mean-it'])
+
+    @authenticate
+    def test_list(self):
+        data = self._get('/api/rbd/rbd')
+        self.assertStatus(200)
+
+        img1 = data['value'][0]
+        self.assertEqual(img1['name'], 'img1')
+        self.assertEqual(img1['size'], 1073741824)
+        self.assertEqual(img1['num_objs'], 256)
+        self.assertEqual(img1['obj_size'], 4194304)
+        self.assertEqual(img1['features_name'],
+                         'deep-flatten, exclusive-lock, fast-diff, layering, object-map')
+
+        img2 = data['value'][1]
+        self.assertEqual(img2['name'], 'img2')
+        self.assertEqual(img2['size'], 2147483648)
+        self.assertEqual(img2['num_objs'], 512)
+        self.assertEqual(img2['obj_size'], 4194304)
+        self.assertEqual(img2['features_name'],
+                         'deep-flatten, exclusive-lock, fast-diff, layering, object-map')
index 3d1ad27e68c144fea2b28ccd5fafbd9d81fb24aa..d4650d1995bd5bbef37fccfc97a1f11c40cc96f8 100644 (file)
@@ -13,7 +13,7 @@ setenv=
     PATH = {toxinidir}/../../../../build/bin:$PATH
     DASHBOARD_V2_PORT=9865
 commands=
-    {envbindir}/py.test --cov=. --cov-report= --junitxml=junit.{envname}.xml tests/
+    {envbindir}/py.test --cov=. --cov-report= --junitxml=junit.{envname}.xml --doctest-modules controllers/rbd.py tests/
 
 [testenv:cov-init]
 setenv =