From e6c1056ad5adb563c0f72514f27cea43a3cc02ba Mon Sep 17 00:00:00 2001 From: Sebastian Wagner Date: Wed, 21 Mar 2018 17:15:29 +0100 Subject: [PATCH] mgr/dashboard: Add create() to Pool controller Also: * Added tests. * Renamed `DashboardTest` to `PoolTest`. * Added `delete()`. Signed-off-by: Sebastian Wagner --- qa/tasks/mgr/dashboard/test_pool.py | 80 +++++++++++++++++++- src/pybind/mgr/dashboard/HACKING.rst | 2 +- src/pybind/mgr/dashboard/controllers/pool.py | 24 ++++++ 3 files changed, 104 insertions(+), 2 deletions(-) diff --git a/qa/tasks/mgr/dashboard/test_pool.py b/qa/tasks/mgr/dashboard/test_pool.py index 6852ddbb631..5e4f2bd7f2a 100644 --- a/qa/tasks/mgr/dashboard/test_pool.py +++ b/qa/tasks/mgr/dashboard/test_pool.py @@ -1,10 +1,24 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import +import logging + from .helper import DashboardTestCase, authenticate +log = logging.getLogger(__name__) + + +class PoolTest(DashboardTestCase): + @classmethod + def tearDownClass(cls): + super(PoolTest, cls).tearDownClass() + for name in ['dashboard_pool1', 'dashboard_pool2', 'dashboard_pool3']: + cls._ceph_cmd(['osd', 'pool', 'delete', name, name, '--yes-i-really-really-mean-it']) + cls._ceph_cmd(['osd', 'erasure-code-profile', 'rm', 'ecprofile']) + + + -class DashboardTest(DashboardTestCase): @authenticate def test_pool_list(self): data = self._get("/api/pool") @@ -60,3 +74,67 @@ class DashboardTest(DashboardTestCase): self.assertIn('flags', pool) self.assertIn('stats', pool) self.assertNotIn('flags_names', pool) + + @authenticate + def _pool_create(self, data): + try: + self._post('/api/pool/', data) + self.assertStatus(201) + + pool = self._get("/api/pool/" + data['pool']) + self.assertStatus(200) + try: + for k, v in data.items(): + if k == 'pool_type': + self.assertEqual(pool['type'], data['pool_type']) + elif k == 'pg_num': + self.assertEqual(pool[k], int(v), '{}: {} != {}'.format(k, pool[k], v)) + elif k == 'application_metadata': + self.assertEqual(pool[k], + {name: {} for name in data['application_metadata'].split(',')}) + elif k == 'pool': + self.assertEqual(pool['pool_name'], v) + elif k in ['compression_mode', 'compression_algorithm', + 'compression_max_blob_size']: + self.assertEqual(pool['options'][k], data[k]) + elif k == 'compression_required_ratio': + self.assertEqual(pool['options'][k], float(data[k])) + else: + self.assertEqual(pool[k], v, '{}: {} != {}'.format(k, pool[k], v)) + + except Exception: + log.exception("test_pool_create: pool=%s", pool) + raise + + self._delete("/api/pool/" + data['pool']) + self.assertStatus(204) + except Exception: + log.exception("test_pool_create: data=%s", data) + raise + + def test_pool_create(self): + self._ceph_cmd(['osd', 'crush', 'rule', 'create-erasure', 'ecrule']) + self._ceph_cmd( + ['osd', 'erasure-code-profile', 'set', 'ecprofile', 'crush-failure-domain=osd']) + pools = [{ + 'pool': 'dashboard_pool1', + 'pg_num': '10', + 'pool_type': 'replicated', + 'application_metadata': 'rbd', + }, { + 'pool': 'dashboard_pool2', + 'pg_num': '10', + 'pool_type': 'erasure', + 'erasure_code_profile': 'ecprofile', + 'crush_rule': 'ecrule', + }, { + 'pool': 'dashboard_pool3', + 'pg_num': '10', + 'pool_type': 'replicated', + 'compression_algorithm': 'zstd', + 'compression_mode': 'aggressive', + 'compression_max_blob_size': 10000000, + 'compression_required_ratio': '0.8', + }] + for data in pools: + self._pool_create(data) diff --git a/src/pybind/mgr/dashboard/HACKING.rst b/src/pybind/mgr/dashboard/HACKING.rst index be6ac6fb667..76d2dbe6015 100644 --- a/src/pybind/mgr/dashboard/HACKING.rst +++ b/src/pybind/mgr/dashboard/HACKING.rst @@ -212,7 +212,7 @@ Start all dashboard tests by running:: Or, start one or multiple specific tests by specifying the test name:: - $ ./run-backend-api-tests.sh tasks.mgr.dashboard.test_pool.DashboardTest + $ ./run-backend-api-tests.sh tasks.mgr.dashboard.test_pool.PoolTest Or, ``source`` the script and run the tests manually:: diff --git a/src/pybind/mgr/dashboard/controllers/pool.py b/src/pybind/mgr/dashboard/controllers/pool.py index 2eac9f50f88..19f53b7731d 100644 --- a/src/pybind/mgr/dashboard/controllers/pool.py +++ b/src/pybind/mgr/dashboard/controllers/pool.py @@ -47,3 +47,27 @@ class Pool(RESTController): 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] + + 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') + + # pylint: disable=too-many-arguments, too-many-locals + @RESTController.args_from_json + 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 + CephService.send_command('mon', 'osd pool create', pool=pool, pg_num=int(pg_num), + pgp_num=int(pg_num), pool_type=pool_type, erasure_code_profile=ecp, + rule=rule_name) + + if flags and 'ec_overwrites' in flags: + CephService.send_command('mon', 'osd pool set', pool=pool, var='allow_ec_overwrites', + val='true') + + if application_metadata: + for app in application_metadata.split(','): + CephService.send_command('mon', 'osd pool application enable', pool=pool, app=app) + + for key, value in kwargs.items(): + CephService.send_command('mon', 'osd pool set', pool=pool, var=key, val=value) -- 2.39.5