]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Add create() to Pool controller
authorSebastian Wagner <sebastian.wagner@suse.com>
Wed, 21 Mar 2018 16:15:29 +0000 (17:15 +0100)
committerSebastian Wagner <sebastian.wagner@suse.com>
Fri, 23 Mar 2018 15:40:18 +0000 (16:40 +0100)
Also:

* Added tests.
* Renamed `DashboardTest` to `PoolTest`.
* Added `delete()`.

Signed-off-by: Sebastian Wagner <sebastian.wagner@suse.com>
qa/tasks/mgr/dashboard/test_pool.py
src/pybind/mgr/dashboard/HACKING.rst
src/pybind/mgr/dashboard/controllers/pool.py

index 6852ddbb631a6dd9897dd281c81a0e046a749096..5e4f2bd7f2a5cac0ddc79978897d788b3e998a07 100644 (file)
@@ -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)
index be6ac6fb667c31c1546cc825d53f7cca996f7893..76d2dbe60158afdb782851952a0c6ac680af0a3c 100644 (file)
@@ -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::
 
index 2eac9f50f8818ad767f1fa225d61e023df0898c8..19f53b7731d2984e1eb8e1d93d9580f04210fd03 100644 (file)
@@ -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)