]>
git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/pg_autoscaler/tests/test_cal_final_pg_target.py
d8ba83d111af42a63ec2377040055ba32a6bc34d
6 from pg_autoscaler
import module
11 def __init__(self
, pool_count
, pg_target
, pg_left
):
13 self
.pool_count
= pool_count
14 self
.pg_target
= pg_target
15 self
.pg_left
= pg_left
19 class TestPgAutoscaler(object):
22 # a bunch of attributes for testing.
23 self
.autoscaler
= module
.PgAutoscaler('module_name', 0, 0)
25 def helper_test(self
, pools
, root_map
, bias
, overlapped_roots
):
26 # Here we simulate how _get_pool_pg_target() works.
32 for pool_name
, p
in pools
.items():
33 root_id
= p
['root_id']
34 if root_id
in overlapped_roots
:
35 # skip pools with overlapping roots
39 final_ratio
, pool_pg_target
, final_pg_target
= self
.autoscaler
._calc
_final
_pg
_target
(
40 p
, pool_name
, root_map
,
41 p
['root_id'], p
['capacity_ratio'],
42 bias
, even_pools
, bulk_pools
, 'first', p
['bulk'])
44 if final_ratio
== None:
45 # no final_ratio means current pool is an even pool
46 # and we do not have to do any assertion on it.
49 assert p
['expected_final_pg_target'] == final_pg_target
50 assert p
['expected_final_ratio'] == final_ratio
51 assert not p
['expected_bulk_pool'] and pool_name
not in bulk_pools
54 for pool_name
, p
in bulk_pools
.items():
55 final_ratio
, pool_pg_target
, final_pg_target
= self
.autoscaler
._calc
_final
_pg
_target
(
56 p
, pool_name
, root_map
,
57 p
['root_id'], p
['capacity_ratio'],
58 bias
, even_pools
, bulk_pools
, 'second', p
['bulk'])
60 if final_ratio
== None:
61 # no final_ratio means current pool is an even pool
62 # and we do not have to do any assertion on it.
65 assert p
['expected_final_pg_target'] == final_pg_target
66 assert p
['expected_final_ratio'] == final_ratio
67 assert not p
['even_pools'] and pool_name
not in even_pools
70 for pool_name
, p
in even_pools
.items():
71 final_ratio
, pool_pg_target
, final_pg_target
= self
.autoscaler
._calc
_final
_pg
_target
(
72 p
, pool_name
, root_map
,
73 p
['root_id'], p
['capacity_ratio'],
74 bias
, even_pools
, bulk_pools
, 'third', p
['bulk'])
76 assert p
['expected_final_pg_target'] == final_pg_target
77 assert p
['expected_final_ratio'] == final_ratio
78 assert p
['even_pools'] and pool_name
in even_pools
80 def test_even_pools_one_meta_three_bulk(self
):
86 "pool_name": "meta_0",
88 "capacity_ratio": 0.2,
90 "expected_final_pg_target": 64,
91 "expected_final_ratio": 0.2,
92 "expected_bulk_pool": False,
102 "pool_name": "bulk_0",
104 "capacity_ratio": 0.2,
106 "expected_final_pg_target": 128,
107 "expected_final_ratio": 1/3,
108 "expected_bulk_pool": True,
118 "pool_name": "bulk_1",
120 "capacity_ratio": 0.2,
122 "expected_final_pg_target": 128,
123 "expected_final_ratio": 1/3,
124 "expected_bulk_pool": True,
134 "pool_name": "bulk_2",
136 "capacity_ratio": 0.1,
138 "expected_final_pg_target": 128,
139 "expected_final_ratio": 1/3,
140 "expected_bulk_pool": True,
151 0: RootMapItem(4, 400, 400),
152 1: RootMapItem(4, 400, 400),
157 overlapped_roots
= set()
158 self
.helper_test(pools
, root_map
, bias
, overlapped_roots
)
160 def test_even_pools_two_meta_two_bulk(self
):
166 "pool_name": "meta0",
168 "capacity_ratio": 0.2,
170 "expected_final_pg_target": 64,
171 "expected_final_ratio": 0.2,
172 "expected_bulk_pool": False,
182 "pool_name": "meta1",
184 "capacity_ratio": 0.2,
186 "expected_final_pg_target": 64,
187 "expected_final_ratio": 0.2,
188 "expected_bulk_pool": False,
198 "pool_name": "bulk0",
200 "capacity_ratio": 0.2,
202 "expected_final_pg_target": 128,
203 "expected_final_ratio": 0.5,
204 "expected_bulk_pool": True,
214 "pool_name": "test3",
216 "capacity_ratio": 0.1,
218 "expected_final_pg_target": 128,
219 "expected_final_ratio": 0.5,
220 "expected_bulk_pool": True,
231 0: RootMapItem(4, 400, 400),
232 1: RootMapItem(4, 400, 400),
237 overlapped_roots
= set()
238 self
.helper_test(pools
, root_map
, bias
, overlapped_roots
)
240 def test_uneven_pools_one_meta_three_bulk(self
):
246 "pool_name": "meta0",
248 "capacity_ratio": 0.1,
250 "expected_final_pg_target": 32,
251 "expected_final_ratio": 0.1,
252 "expected_bulk_pool": False,
262 "pool_name": "bulk0",
264 "capacity_ratio": 0.5,
266 "expected_final_pg_target": 128,
267 "expected_final_ratio": 0.5,
268 "expected_bulk_pool": True,
278 "pool_name": "bulk1",
280 "capacity_ratio": 0.1,
282 "expected_final_pg_target": 64,
283 "expected_final_ratio": 0.5,
284 "expected_bulk_pool": True,
294 "pool_name": "bulk2",
296 "capacity_ratio": 0.1,
298 "expected_final_pg_target": 64,
299 "expected_final_ratio": 0.5,
300 "expected_bulk_pool": True,
311 0: RootMapItem(4, 400, 400),
312 1: RootMapItem(4, 400, 400),
317 overlapped_roots
= set()
318 self
.helper_test(pools
, root_map
, bias
, overlapped_roots
)
320 def test_uneven_pools_two_meta_two_bulk(self
):
326 "pool_name": "meta0",
328 "capacity_ratio": 0.1,
330 "expected_final_pg_target": 32,
331 "expected_final_ratio": 0.1,
332 "expected_bulk_pool": False,
342 "pool_name": "meta1",
344 "capacity_ratio": 0.1,
346 "expected_final_pg_target": 32,
347 "expected_final_ratio": 0.1,
348 "expected_bulk_pool": False,
358 "pool_name": "bulk0",
360 "capacity_ratio": 0.5,
362 "expected_final_pg_target": 128,
363 "expected_final_ratio": 0.5,
364 "expected_bulk_pool": True,
374 "pool_name": "bulk1",
376 "capacity_ratio": 0.1,
378 "expected_final_pg_target": 128,
379 "expected_final_ratio": 0.5,
380 "expected_bulk_pool": True,
391 0: RootMapItem(4, 400, 400),
392 1: RootMapItem(4, 400, 400),
397 overlapped_roots
= set()
398 self
.helper_test(pools
, root_map
, bias
, overlapped_roots
)
400 def test_uneven_pools_with_diff_roots(self
):
406 "pool_name": "meta0",
408 "capacity_ratio": 0.3,
410 "expected_final_pg_target": 1024,
411 "expected_final_ratio": 0.3,
412 "expected_bulk_pool": False,
422 "pool_name": "meta1",
424 "capacity_ratio": 0.6,
426 "expected_final_pg_target": 2048,
427 "expected_final_ratio": 0.6,
428 "expected_bulk_pool": False,
438 "pool_name": "bulk2",
440 "capacity_ratio": 0.6,
442 "expected_final_pg_target": 2048,
443 "expected_final_ratio": 0.6,
444 "expected_bulk_pool": True,
454 "pool_name": "test3",
456 "capacity_ratio": 0.1,
458 "expected_final_pg_target": 1024,
459 "expected_final_ratio": 1,
460 "expected_bulk_pool": True,
470 "pool_name": "bulk4",
472 "capacity_ratio": 0.4,
474 "expected_final_pg_target": 2048,
475 "expected_final_ratio": 1,
476 "expected_bulk_pool": True,
487 0: RootMapItem(3, 5000, 5000),
488 1: RootMapItem(2, 5000, 5000),
493 overlapped_roots
= set()
494 self
.helper_test(pools
, root_map
, bias
, overlapped_roots
)
496 def test_even_pools_with_diff_roots(self
):
502 "pool_name": "meta0",
504 "capacity_ratio": 0.4,
506 "expected_final_pg_target": 2048,
507 "expected_final_ratio": 0.4,
508 "expected_bulk_pool": False,
518 "pool_name": "meta1",
520 "capacity_ratio": 0.6,
522 "expected_final_pg_target": 2048,
523 "expected_final_ratio": 0.6,
524 "expected_bulk_pool": False,
534 "pool_name": "bulk1",
536 "capacity_ratio": 0.2,
538 "expected_final_pg_target": 1024,
539 "expected_final_ratio": 0.5,
540 "expected_bulk_pool": True,
550 "pool_name": "bulk2",
552 "capacity_ratio": 0.1,
554 "expected_final_pg_target": 1024,
555 "expected_final_ratio": 0.5,
556 "expected_bulk_pool": True,
566 "pool_name": "bulk4",
568 "capacity_ratio": 0.25,
570 "expected_final_pg_target": 2048,
571 "expected_final_ratio": 1,
572 "expected_bulk_pool": True,
583 0: RootMapItem(3, 5000, 5000),
584 1: RootMapItem(2, 5000, 5000),
589 overlapped_roots
= set()
590 self
.helper_test(pools
, root_map
, bias
, overlapped_roots
)
592 def test_uneven_pools_with_overlapped_roots(self
):
598 "pool_name": "test0",
600 "capacity_ratio": 0.4,
602 "expected_final_pg_target": 2048,
603 "expected_final_ratio": 0.4,
612 "pool_name": "test1",
614 "capacity_ratio": 0.6,
616 "expected_final_pg_target": 2048,
617 "expected_final_ratio": 0.6,
626 "pool_name": "test2",
628 "capacity_ratio": 0.5,
630 "expected_final_pg_target": 2048,
631 "expected_final_ratio": 0.5,
640 "pool_name": "test3",
642 "capacity_ratio": 0.1,
644 "expected_final_pg_target": 512,
645 "expected_final_ratio": 1,
654 "pool_name": "test4",
656 "capacity_ratio": 0.4,
658 "expected_final_pg_target": 2048,
659 "expected_final_ratio": 1,
669 0: RootMapItem(3, 5000, 5000),
670 1: RootMapItem(2, 5000, 5000),
675 overlapped_roots
= {0, 1}
676 self
.helper_test(pools
, root_map
, bias
, overlapped_roots
)