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