# -*- 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")
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)
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)