]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | # -*- coding: utf-8 -*- |
2 | from __future__ import absolute_import | |
3 | ||
f6b5b4d7 | 4 | from .helper import DashboardTestCase, JObj |
11fdf7f2 TL |
5 | |
6 | ||
7 | class PerfCountersControllerTest(DashboardTestCase): | |
8 | ||
9 | def test_perf_counters_list(self): | |
10 | data = self._get('/api/perf_counters') | |
11 | self.assertStatus(200) | |
12 | ||
13 | self.assertIsInstance(data, dict) | |
14 | for mon in self.mons(): | |
15 | self.assertIn('mon.{}'.format(mon), data) | |
16 | ||
17 | osds = self.ceph_cluster.mon_manager.get_osd_dump() | |
18 | for osd in osds: | |
19 | self.assertIn('osd.{}'.format(osd['osd']), data) | |
20 | ||
21 | def _validate_perf(self, srv_id, srv_type, data, allow_empty): | |
22 | self.assertIsInstance(data, dict) | |
23 | self.assertEqual(srv_type, data['service']['type']) | |
24 | self.assertEqual(str(srv_id), data['service']['id']) | |
25 | self.assertIsInstance(data['counters'], list) | |
26 | if not allow_empty: | |
27 | self.assertGreater(len(data['counters']), 0) | |
28 | for counter in data['counters'][0:1]: | |
29 | self.assertIsInstance(counter, dict) | |
30 | self.assertIn('description', counter) | |
31 | self.assertIn('name', counter) | |
32 | self.assertIn('unit', counter) | |
33 | self.assertIn('value', counter) | |
34 | ||
35 | def test_perf_counters_mon_get(self): | |
36 | mon = self.mons()[0] | |
37 | data = self._get('/api/perf_counters/mon/{}'.format(mon)) | |
38 | self.assertStatus(200) | |
39 | self._validate_perf(mon, 'mon', data, allow_empty=False) | |
40 | ||
41 | def test_perf_counters_mgr_get(self): | |
1911f103 | 42 | mgr = list(self.mgr_cluster.mgr_ids)[0] |
11fdf7f2 TL |
43 | data = self._get('/api/perf_counters/mgr/{}'.format(mgr)) |
44 | self.assertStatus(200) | |
45 | self._validate_perf(mgr, 'mgr', data, allow_empty=False) | |
46 | ||
47 | def test_perf_counters_mds_get(self): | |
48 | for mds in self.mds_cluster.mds_ids: | |
49 | data = self._get('/api/perf_counters/mds/{}'.format(mds)) | |
50 | self.assertStatus(200) | |
51 | self._validate_perf(mds, 'mds', data, allow_empty=True) | |
52 | ||
53 | def test_perf_counters_osd_get(self): | |
54 | for osd in self.ceph_cluster.mon_manager.get_osd_dump(): | |
55 | osd = osd['osd'] | |
56 | data = self._get('/api/perf_counters/osd/{}'.format(osd)) | |
57 | self.assertStatus(200) | |
58 | self._validate_perf(osd, 'osd', data, allow_empty=False) | |
59 | ||
60 | def test_perf_counters_not_found(self): | |
61 | osds = self.ceph_cluster.mon_manager.get_osd_dump() | |
62 | unused_id = int(list(map(lambda o: o['osd'], osds)).pop()) + 1 | |
63 | ||
64 | self._get('/api/perf_counters/osd/{}'.format(unused_id)) | |
65 | self.assertStatus(404) | |
66 | schema = JObj(sub_elems={ | |
67 | 'status': str, | |
11fdf7f2 | 68 | 'detail': str, |
92f5a8d4 | 69 | }, allow_unknown=True) |
11fdf7f2 TL |
70 | self.assertEqual(self._resp.json()['detail'], "'osd.{}' not found".format(unused_id)) |
71 | self.assertSchemaBody(schema) |