]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/tests/test_pool.py
import 15.2.0 Octopus source
[ceph.git] / ceph / src / pybind / mgr / dashboard / tests / test_pool.py
1 # -*- coding: utf-8 -*-
2 # pylint: disable=protected-access
3 import time
4 try:
5 import mock
6 except ImportError:
7 import unittest.mock as mock
8
9 from . import ControllerTestCase
10 from ..controllers.pool import Pool
11 from ..controllers.task import Task
12 from ..tools import NotificationQueue, TaskManager
13
14
15 class MockTask(object):
16 percentages = []
17
18 def set_progress(self, percentage):
19 self.percentages.append(percentage)
20
21
22 class PoolControllerTest(ControllerTestCase):
23 @classmethod
24 def setup_server(cls):
25 Task._cp_config['tools.authenticate.on'] = False
26 Pool._cp_config['tools.authenticate.on'] = False
27 cls.setup_controllers([Pool, Task])
28
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):
33 _get.side_effect = [{
34 'pool_name': 'test-pool',
35 'pg_num': 64,
36 'pg_num_target': 63,
37 'pg_placement_num': 64,
38 'pg_placement_num_target': 63
39 }, {
40 'pool_name': 'test-pool',
41 'pg_num': 64,
42 'pg_num_target': 64,
43 'pg_placement_num': 64,
44 'pg_placement_num_target': 64
45 }]
46 NotificationQueue.start_queue()
47 TaskManager.init()
48
49 def _send_cmd(*args, **kwargs): # pylint: disable=unused-argument
50 time.sleep(3)
51
52 send_command.side_effect = _send_cmd
53 get_progress_tasks.return_value = [], []
54
55 self._task_post('/api/pool', {
56 'pool': 'test-pool',
57 'pool_type': 1,
58 'pg_num': 64
59 }, 10)
60 self.assertStatus(201)
61 self.assertEqual(_get.call_count, 2)
62 NotificationQueue.stop()
63
64 @mock.patch('dashboard.controllers.pool.Pool._get')
65 def test_wait_for_pgs_without_waiting(self, _get):
66 _get.side_effect = [{
67 'pool_name': 'test-pool',
68 'pg_num': 32,
69 'pg_num_target': 32,
70 'pg_placement_num': 32,
71 'pg_placement_num_target': 32
72 }]
73 Pool._wait_for_pgs('test-pool')
74 self.assertEqual(_get.call_count, 1)
75
76 @mock.patch('dashboard.controllers.pool.Pool._get')
77 def test_wait_for_pgs_with_waiting(self, _get):
78 task = MockTask()
79 orig_method = TaskManager.current_task
80 TaskManager.current_task = mock.MagicMock()
81 TaskManager.current_task.return_value = task
82 _get.side_effect = [{
83 'pool_name': 'test-pool',
84 'pg_num': 64,
85 'pg_num_target': 32,
86 'pg_placement_num': 64,
87 'pg_placement_num_target': 64
88 }, {
89 'pool_name': 'test-pool',
90 'pg_num': 63,
91 'pg_num_target': 32,
92 'pg_placement_num': 62,
93 'pg_placement_num_target': 32
94 }, {
95 'pool_name': 'test-pool',
96 'pg_num': 48,
97 'pg_num_target': 32,
98 'pg_placement_num': 48,
99 'pg_placement_num_target': 32
100 }, {
101 'pool_name': 'test-pool',
102 'pg_num': 48,
103 'pg_num_target': 32,
104 'pg_placement_num': 33,
105 'pg_placement_num_target': 32
106 }, {
107 'pool_name': 'test-pool',
108 'pg_num': 33,
109 'pg_num_target': 32,
110 'pg_placement_num': 32,
111 'pg_placement_num_target': 32
112 }, {
113 'pool_name': 'test-pool',
114 'pg_num': 32,
115 'pg_num_target': 32,
116 'pg_placement_num': 32,
117 'pg_placement_num_target': 32
118 }]
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