From: Kiefer Chang Date: Tue, 18 Jun 2019 07:44:03 +0000 (+0800) Subject: mgr/dashboard: support pool quotas in backend X-Git-Tag: v15.1.0~2312^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f57a3aae011948c89be02e8cfce85cc19a07775f;p=ceph.git mgr/dashboard: support pool quotas in backend Fixes: https://tracker.ceph.com/issues/36559 Signed-off-by: Kiefer Chang --- diff --git a/qa/tasks/mgr/dashboard/test_pool.py b/qa/tasks/mgr/dashboard/test_pool.py index 2dd0153c3ca3..d76546d03cc8 100644 --- a/qa/tasks/mgr/dashboard/test_pool.py +++ b/qa/tasks/mgr/dashboard/test_pool.py @@ -269,6 +269,40 @@ class PoolTest(DashboardTestCase): self._task_delete("/api/pool/" + pool['pool']) self.assertStatus(204) + def test_pool_create_with_quotas(self): + pools = [ + { + 'pool_data': { + 'pool': 'dashboard_pool_quota1', + 'pg_num': '10', + 'pool_type': 'replicated', + }, + 'pool_quotas_to_check': { + 'quota_max_objects': 0, + 'quota_max_bytes': 0, + } + }, + { + 'pool_data': { + 'pool': 'dashboard_pool_quota2', + 'pg_num': '10', + 'pool_type': 'replicated', + 'quota_max_objects': 1024, + 'quota_max_bytes': 1000, + }, + 'pool_quotas_to_check': { + 'quota_max_objects': 1024, + 'quota_max_bytes': 1000, + } + } + ] + + for pool in pools: + pool_name = pool['pool_data']['pool'] + with self.__create_pool(pool_name, pool['pool_data']): + self._validate_pool_properties(pool['pool_quotas_to_check'], + self._get_pool(pool_name)) + def test_pool_update_metadata(self): pool_name = 'pool_update_metadata' with self.__create_pool(pool_name): @@ -339,6 +373,17 @@ class PoolTest(DashboardTestCase): 'compression_required_ratio': None, }, self._get_pool(pool_name)) + def test_pool_update_quotas(self): + pool_name = 'pool_update_quotas' + with self.__create_pool(pool_name): + properties = { + 'quota_max_objects': 1024, + 'quota_max_bytes': 1000, + } + self._task_put('/api/pool/' + pool_name, properties) + time.sleep(5) + self._validate_pool_properties(properties, self._get_pool(pool_name)) + def test_pool_create_fail(self): data = {'pool_type': u'replicated', 'rule_name': u'dnf', 'pg_num': u'8', 'pool': u'sadfs'} self._task_post('/api/pool/', data) diff --git a/src/pybind/mgr/dashboard/controllers/pool.py b/src/pybind/mgr/dashboard/controllers/pool.py index 5732674b01a2..5edfb91bba4b 100644 --- a/src/pybind/mgr/dashboard/controllers/pool.py +++ b/src/pybind/mgr/dashboard/controllers/pool.py @@ -119,6 +119,11 @@ class Pool(RESTController): def set_key(key, value): CephService.send_command('mon', 'osd pool set', pool=pool, var=key, val=str(value)) + quotas = {} + quotas['max_objects'] = kwargs.pop('quota_max_objects', None) + quotas['max_bytes'] = kwargs.pop('quota_max_bytes', None) + self._set_quotas(pool, quotas) + for key, value in kwargs.items(): if key == 'pool': update_name = True @@ -130,6 +135,12 @@ class Pool(RESTController): if update_name: CephService.send_command('mon', 'osd pool rename', srcpool=pool, destpool=destpool) + def _set_quotas(self, pool, quotas): + for field, value in quotas.items(): + if value is not None: + CephService.send_command('mon', 'osd pool set-quota', + pool=pool, field=field, val=str(value)) + def _handle_update_compression_args(self, options, kwargs): if kwargs.get('compression_mode') == 'unset' and options is not None: def reset_arg(arg, value):