]>
git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/tests/test_pool.py
1 # -*- coding: utf-8 -*-
2 # pylint: disable=protected-access
8 import unittest
.mock
as mock
11 from ..controllers
.pool
import Pool
12 from ..controllers
.task
import Task
13 from ..tests
import ControllerTestCase
14 from ..tools
import NotificationQueue
, TaskManager
17 class MockTask(object):
20 def set_progress(self
, percentage
):
21 self
.percentages
.append(percentage
)
24 class PoolControllerTest(ControllerTestCase
):
26 def setup_server(cls
):
27 cls
.setup_controllers([Pool
, Task
])
29 @mock.patch('dashboard.services.progress.get_progress_tasks')
30 @mock.patch('dashboard.controllers.pool.Pool._get')
31 @mock.patch('dashboard.services.ceph_service.CephService.send_command')
32 def test_creation(self
, send_command
, _get
, get_progress_tasks
):
34 'pool_name': 'test-pool',
37 'pg_placement_num': 64,
38 'pg_placement_num_target': 63
40 'pool_name': 'test-pool',
43 'pg_placement_num': 64,
44 'pg_placement_num_target': 64
46 NotificationQueue
.start_queue()
49 def _send_cmd(*args
, **kwargs
): # pylint: disable=unused-argument
52 send_command
.side_effect
= _send_cmd
53 get_progress_tasks
.return_value
= [], []
55 self
._task
_post
('/api/pool', {
60 self
.assertStatus(201)
61 self
.assertEqual(_get
.call_count
, 2)
62 NotificationQueue
.stop()
64 @mock.patch('dashboard.controllers.pool.Pool._get')
65 def test_wait_for_pgs_without_waiting(self
, _get
):
67 'pool_name': 'test-pool',
70 'pg_placement_num': 32,
71 'pg_placement_num_target': 32
73 Pool
._wait
_for
_pgs
('test-pool')
74 self
.assertEqual(_get
.call_count
, 1)
76 @mock.patch('dashboard.controllers.pool.Pool._get')
77 def test_wait_for_pgs_with_waiting(self
, _get
):
79 orig_method
= TaskManager
.current_task
80 TaskManager
.current_task
= mock
.MagicMock()
81 TaskManager
.current_task
.return_value
= task
83 'pool_name': 'test-pool',
86 'pg_placement_num': 64,
87 'pg_placement_num_target': 64
89 'pool_name': 'test-pool',
92 'pg_placement_num': 62,
93 'pg_placement_num_target': 32
95 'pool_name': 'test-pool',
98 'pg_placement_num': 48,
99 'pg_placement_num_target': 32
101 'pool_name': 'test-pool',
104 'pg_placement_num': 33,
105 'pg_placement_num_target': 32
107 'pool_name': 'test-pool',
110 'pg_placement_num': 32,
111 'pg_placement_num_target': 32
113 'pool_name': 'test-pool',
116 'pg_placement_num': 32,
117 'pg_placement_num_target': 32
119 Pool
._wait
_for
_pgs
('test-pool')
120 self
.assertEqual(_get
.call_count
, 6)
121 self
.assertEqual(task
.percentages
, [0, 5, 50, 73, 98])
122 TaskManager
.current_task
= orig_method
124 @mock.patch('dashboard.controllers.osd.CephService.get_pool_list_with_stats')
125 @mock.patch('dashboard.controllers.osd.CephService.get_pool_list')
126 def test_pool_list(self
, get_pool_list
, get_pool_list_with_stats
):
127 get_pool_list
.return_value
= [{
130 'application_metadata': {
131 'test_key': 'test_metadata'
133 'pool_name': 'test_name'
135 mgr
.get
.side_effect
= lambda key
: {
139 'rule_name': 'test-rule'
144 mgr
.get
.assert_called_with('osd_map_crush')
145 self
.assertEqual(get_pool_list
.call_count
, 1)
147 get_pool_list_with_stats
.return_value
= get_pool_list
.return_value
148 Pool
._pool
_list
(attrs
='type', stats
='True')
149 self
.assertEqual(get_pool_list_with_stats
.call_count
, 1)
151 @mock.patch('dashboard.controllers.pool.Pool._get')
152 @mock.patch('dashboard.services.ceph_service.CephService.send_command')
153 def test_set_pool_name(self
, send_command
, _get
):
154 _get
.return_value
= {
156 'compression_min_blob_size': '1'
158 'application_metadata': ['data1', 'data2']
161 def _send_cmd(*args
, **kwargs
): # pylint: disable=unused-argument
164 send_command
.side_effect
= _send_cmd
165 NotificationQueue
.start_queue()
167 self
._task
_put
('/api/pool/test-pool', {
168 "flags": "ec_overwrites",
169 "application_metadata": ['data3', 'data2'],
170 "configuration": "test-conf",
171 "compression_mode": 'unset',
172 'compression_min_blob_size': '1',
173 'compression_max_blob_size': '1',
174 'compression_required_ratio': '1',
178 NotificationQueue
.stop()
179 self
.assertEqual(_get
.call_count
, 1)
180 self
.assertEqual(send_command
.call_count
, 10)