Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20823 from rjfd/wip-dashboard-pools
mgr/dashboard_v2: Pool controller Reviewed-by: Ricardo Marques <rimarques@suse.com> Reviewed-by: Sebastian Wagner <sebastian.wagner@suse.com>
- Loading branch information
Showing
6 changed files
with
168 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters