]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | # -*- coding: utf-8 -*- |
2 | # pylint: disable=dangerous-default-value,too-many-public-methods | |
3 | from __future__ import absolute_import | |
4 | ||
5 | import unittest | |
e306af50 TL |
6 | try: |
7 | import mock | |
8 | except ImportError: | |
9 | import unittest.mock as mock | |
9f95a23c | 10 | |
e306af50 | 11 | from ..services.rbd import get_image_spec, parse_image_spec, RbdConfiguration |
9f95a23c TL |
12 | |
13 | ||
14 | class RbdServiceTest(unittest.TestCase): | |
15 | ||
16 | def test_compose_image_spec(self): | |
17 | self.assertEqual(get_image_spec('mypool', 'myns', 'myimage'), 'mypool/myns/myimage') | |
18 | self.assertEqual(get_image_spec('mypool', None, 'myimage'), 'mypool/myimage') | |
19 | ||
20 | def test_parse_image_spec(self): | |
21 | self.assertEqual(parse_image_spec('mypool/myns/myimage'), ('mypool', 'myns', 'myimage')) | |
22 | self.assertEqual(parse_image_spec('mypool/myimage'), ('mypool', None, 'myimage')) | |
e306af50 TL |
23 | |
24 | @mock.patch('dashboard.services.rbd.RbdConfiguration._rbd.config_list') | |
25 | @mock.patch('dashboard.mgr.get') | |
26 | @mock.patch('dashboard.services.ceph_service.CephService.get_pool_list') | |
27 | def test_pool_rbd_configuration_with_different_pg_states(self, get_pool_list, get, config_list): | |
28 | get_pool_list.return_value = [{ | |
29 | 'pool_name': 'good-pool', | |
30 | 'pool': 1, | |
31 | }, { | |
32 | 'pool_name': 'bad-pool', | |
33 | 'pool': 2, | |
34 | }] | |
35 | get.return_value = { | |
36 | 'by_pool': { | |
37 | '1': {'active+clean': 32}, | |
38 | '2': {'creating+incomplete': 32}, | |
39 | } | |
40 | } | |
41 | config_list.return_value = [1, 2, 3] | |
42 | config = RbdConfiguration('bad-pool') | |
43 | self.assertEqual(config.list(), []) | |
44 | config = RbdConfiguration('good-pool') | |
45 | self.assertEqual(config.list(), [1, 2, 3]) |