From: Ricardo Dias Date: Fri, 9 Mar 2018 16:44:34 +0000 (+0000) Subject: mgr/dashboard: Pool controller implementation and tests X-Git-Tag: v13.0.2~15^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=3efc1a834eb965d9c35a767d4476d85db9cc9188;p=ceph.git mgr/dashboard: Pool controller implementation and tests Signed-off-by: Ricardo Dias --- diff --git a/qa/suites/rados/mgr/tasks/dashboard_v2.yaml b/qa/suites/rados/mgr/tasks/dashboard_v2.yaml index be3ffc62985a..cd5e347a8bb4 100644 --- a/qa/suites/rados/mgr/tasks/dashboard_v2.yaml +++ b/qa/suites/rados/mgr/tasks/dashboard_v2.yaml @@ -31,3 +31,4 @@ tasks: - tasks.mgr.dashboard_v2.test_summary - tasks.mgr.dashboard_v2.test_rgw - tasks.mgr.dashboard_v2.test_rbd + - tasks.mgr.dashboard_v2.test_pool diff --git a/qa/tasks/mgr/dashboard_v2/test_pool.py b/qa/tasks/mgr/dashboard_v2/test_pool.py new file mode 100644 index 000000000000..6852ddbb631a --- /dev/null +++ b/qa/tasks/mgr/dashboard_v2/test_pool.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- +from __future__ import absolute_import + +from .helper import DashboardTestCase, authenticate + + +class DashboardTest(DashboardTestCase): + @authenticate + def test_pool_list(self): + data = self._get("/api/pool") + self.assertStatus(200) + + cluster_pools = self.ceph_cluster.mon_manager.list_pools() + self.assertEqual(len(cluster_pools), len(data)) + for pool in data: + self.assertIn('pool_name', pool) + self.assertIn('type', pool) + self.assertIn('flags', pool) + self.assertIn('flags_names', pool) + self.assertNotIn('stats', pool) + self.assertIn(pool['pool_name'], cluster_pools) + + @authenticate + def test_pool_list_attrs(self): + data = self._get("/api/pool?attrs=type,flags") + self.assertStatus(200) + + cluster_pools = self.ceph_cluster.mon_manager.list_pools() + self.assertEqual(len(cluster_pools), len(data)) + for pool in data: + self.assertIn('pool_name', pool) + self.assertIn('type', pool) + self.assertIn('flags', pool) + self.assertNotIn('flags_names', pool) + self.assertNotIn('stats', pool) + self.assertIn(pool['pool_name'], cluster_pools) + + @authenticate + def test_pool_list_stats(self): + data = self._get("/api/pool?stats=true") + self.assertStatus(200) + + cluster_pools = self.ceph_cluster.mon_manager.list_pools() + self.assertEqual(len(cluster_pools), len(data)) + for pool in data: + self.assertIn('pool_name', pool) + self.assertIn('type', pool) + self.assertIn('flags', pool) + self.assertIn('stats', pool) + self.assertIn('flags_names', pool) + self.assertIn(pool['pool_name'], cluster_pools) + + @authenticate + def test_pool_get(self): + cluster_pools = self.ceph_cluster.mon_manager.list_pools() + pool = self._get("/api/pool/{}?stats=true&attrs=type,flags,stats" + .format(cluster_pools[0])) + self.assertEqual(pool['pool_name'], cluster_pools[0]) + self.assertIn('type', pool) + self.assertIn('flags', pool) + self.assertIn('stats', pool) + self.assertNotIn('flags_names', pool) diff --git a/src/pybind/mgr/dashboard_v2/controllers/pool.py b/src/pybind/mgr/dashboard_v2/controllers/pool.py new file mode 100644 index 000000000000..2eac9f50f881 --- /dev/null +++ b/src/pybind/mgr/dashboard_v2/controllers/pool.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +from __future__ import absolute_import + +from ..services.ceph_service import CephService +from ..tools import ApiController, RESTController, AuthRequired + + +@ApiController('pool') +@AuthRequired() +class Pool(RESTController): + + @classmethod + def _serialize_pool(cls, pool, attrs): + if not attrs or not isinstance(attrs, list): + return pool + + res = {} + for attr in attrs: + if attr not in pool: + continue + if attr == 'type': + res[attr] = {1: 'replicated', 3: 'erasure'}[pool[attr]] + else: + res[attr] = pool[attr] + + # pool_name is mandatory + res['pool_name'] = pool['pool_name'] + return res + + @staticmethod + def _str_to_bool(var): + if isinstance(var, bool): + return var + return var.lower() in ("true", "yes", "1", 1) + + def list(self, attrs=None, stats=False): + if attrs: + attrs = attrs.split(',') + + if self._str_to_bool(stats): + pools = CephService.get_pool_list_with_stats() + else: + pools = CephService.get_pool_list() + + return [self._serialize_pool(pool, attrs) for pool in pools] + + 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]