summaryrefslogtreecommitdiffstats
path: root/src/pybind/mgr/pg_autoscaler/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/pybind/mgr/pg_autoscaler/tests')
-rw-r--r--src/pybind/mgr/pg_autoscaler/tests/__init__.py0
-rw-r--r--src/pybind/mgr/pg_autoscaler/tests/test_cal_final_pg_target.py676
-rw-r--r--src/pybind/mgr/pg_autoscaler/tests/test_cal_ratio.py37
-rw-r--r--src/pybind/mgr/pg_autoscaler/tests/test_overlapping_roots.py479
4 files changed, 1192 insertions, 0 deletions
diff --git a/src/pybind/mgr/pg_autoscaler/tests/__init__.py b/src/pybind/mgr/pg_autoscaler/tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/src/pybind/mgr/pg_autoscaler/tests/__init__.py
diff --git a/src/pybind/mgr/pg_autoscaler/tests/test_cal_final_pg_target.py b/src/pybind/mgr/pg_autoscaler/tests/test_cal_final_pg_target.py
new file mode 100644
index 000000000..655025bbe
--- /dev/null
+++ b/src/pybind/mgr/pg_autoscaler/tests/test_cal_final_pg_target.py
@@ -0,0 +1,676 @@
+# python unit test
+import unittest
+from tests import mock
+import pytest
+import json
+from pg_autoscaler import module
+
+
+class RootMapItem:
+
+ def __init__(self, pool_count, pg_target, pg_left):
+
+ self.pool_count = pool_count
+ self.pg_target = pg_target
+ self.pg_left = pg_left
+ self.pool_used = 0
+
+
+class TestPgAutoscaler(object):
+
+ def setup_method(self):
+ # a bunch of attributes for testing.
+ self.autoscaler = module.PgAutoscaler('module_name', 0, 0)
+
+ def helper_test(self, pools, root_map, bias, overlapped_roots):
+ # Here we simulate how _get_pool_pg_target() works.
+
+ bulk_pools = {}
+ even_pools = {}
+
+ # first pass
+ for pool_name, p in pools.items():
+ root_id = p['root_id']
+ if root_id in overlapped_roots:
+ # skip pools with overlapping roots
+ assert p['no_scale']
+ continue
+
+ final_ratio, pool_pg_target, final_pg_target = self.autoscaler._calc_final_pg_target(
+ p, pool_name, root_map,
+ p['root_id'], p['capacity_ratio'],
+ bias, even_pools, bulk_pools, 'first', p['bulk'])
+
+ if final_ratio == None:
+ # no final_ratio means current pool is an even pool
+ # and we do not have to do any assertion on it.
+ continue
+
+ assert p['expected_final_pg_target'] == final_pg_target
+ assert p['expected_final_ratio'] == final_ratio
+ assert not p['expected_bulk_pool'] and pool_name not in bulk_pools
+
+ # second pass
+ for pool_name, p in bulk_pools.items():
+ final_ratio, pool_pg_target, final_pg_target = self.autoscaler._calc_final_pg_target(
+ p, pool_name, root_map,
+ p['root_id'], p['capacity_ratio'],
+ bias, even_pools, bulk_pools, 'second', p['bulk'])
+
+ if final_ratio == None:
+ # no final_ratio means current pool is an even pool
+ # and we do not have to do any assertion on it.
+ continue
+
+ assert p['expected_final_pg_target'] == final_pg_target
+ assert p['expected_final_ratio'] == final_ratio
+ assert not p['even_pools'] and pool_name not in even_pools
+
+ #third pass
+ for pool_name, p in even_pools.items():
+ final_ratio, pool_pg_target, final_pg_target = self.autoscaler._calc_final_pg_target(
+ p, pool_name, root_map,
+ p['root_id'], p['capacity_ratio'],
+ bias, even_pools, bulk_pools, 'third', p['bulk'])
+
+ assert p['expected_final_pg_target'] == final_pg_target
+ assert p['expected_final_ratio'] == final_ratio
+ assert p['even_pools'] and pool_name in even_pools
+
+ def test_even_pools_one_meta_three_bulk(self):
+ pools = {
+
+ "meta_0": {
+
+ "pool": 0,
+ "pool_name": "meta_0",
+ "pg_num_target": 32,
+ "capacity_ratio": 0.2,
+ "root_id": 0,
+ "expected_final_pg_target": 64,
+ "expected_final_ratio": 0.2,
+ "expected_bulk_pool": False,
+ "even_pools": False,
+ "size": 1,
+ "no_scale": False,
+ "bulk": False,
+ },
+
+ "bulk_0": {
+
+ "pool": 1,
+ "pool_name": "bulk_0",
+ "pg_num_target": 32,
+ "capacity_ratio": 0.2,
+ "root_id": 0,
+ "expected_final_pg_target": 128,
+ "expected_final_ratio": 1/3,
+ "expected_bulk_pool": True,
+ "even_pools": True,
+ "size": 1,
+ "no_scale": False,
+ "bulk": True,
+ },
+
+ "bulk_1": {
+
+ "pool": 2,
+ "pool_name": "bulk_1",
+ "pg_num_target": 32,
+ "capacity_ratio": 0.2,
+ "root_id": 0,
+ "expected_final_pg_target": 128,
+ "expected_final_ratio": 1/3,
+ "expected_bulk_pool": True,
+ "even_pools": True,
+ "size": 1,
+ "no_scale": False,
+ "bulk": True,
+ },
+
+ "bulk_2": {
+
+ "pool": 3,
+ "pool_name": "bulk_2",
+ "pg_num_target": 32,
+ "capacity_ratio": 0.1,
+ "root_id": 0,
+ "expected_final_pg_target": 128,
+ "expected_final_ratio": 1/3,
+ "expected_bulk_pool": True,
+ "even_pools": True,
+ "size": 1,
+ "no_scale": False,
+ "bulk": True,
+ },
+
+ }
+
+ root_map = {
+
+ 0: RootMapItem(4, 400, 400),
+ 1: RootMapItem(4, 400, 400),
+
+ }
+
+ bias = 1
+ overlapped_roots = set()
+ self.helper_test(pools, root_map, bias, overlapped_roots)
+
+ def test_even_pools_two_meta_two_bulk(self):
+ pools = {
+
+ "meta0": {
+
+ "pool": 0,
+ "pool_name": "meta0",
+ "pg_num_target": 32,
+ "capacity_ratio": 0.2,
+ "root_id": 0,
+ "expected_final_pg_target": 64,
+ "expected_final_ratio": 0.2,
+ "expected_bulk_pool": False,
+ "even_pools": True,
+ "size": 1,
+ "no_scale": False,
+ "bulk": False,
+ },
+
+ "meta1": {
+
+ "pool": 1,
+ "pool_name": "meta1",
+ "pg_num_target": 32,
+ "capacity_ratio": 0.2,
+ "root_id": 0,
+ "expected_final_pg_target": 64,
+ "expected_final_ratio": 0.2,
+ "expected_bulk_pool": False,
+ "even_pools": True,
+ "size": 1,
+ "no_scale": False,
+ "bulk": False,
+ },
+
+ "bulk0": {
+
+ "pool": 2,
+ "pool_name": "bulk0",
+ "pg_num_target": 32,
+ "capacity_ratio": 0.2,
+ "root_id": 0,
+ "expected_final_pg_target": 128,
+ "expected_final_ratio": 0.5,
+ "expected_bulk_pool": True,
+ "even_pools": True,
+ "size": 1,
+ "no_scale": False,
+ "bulk": True,
+ },
+
+ "bulk1": {
+
+ "pool": 3,
+ "pool_name": "test3",
+ "pg_num_target": 32,
+ "capacity_ratio": 0.1,
+ "root_id": 0,
+ "expected_final_pg_target": 128,
+ "expected_final_ratio": 0.5,
+ "expected_bulk_pool": True,
+ "even_pools": True,
+ "size": 1,
+ "no_scale": False,
+ "bulk": True,
+ },
+
+ }
+
+ root_map = {
+
+ 0: RootMapItem(4, 400, 400),
+ 1: RootMapItem(4, 400, 400),
+
+ }
+
+ bias = 1
+ overlapped_roots = set()
+ self.helper_test(pools, root_map, bias, overlapped_roots)
+
+ def test_uneven_pools_one_meta_three_bulk(self):
+ pools = {
+
+ "meta0": {
+
+ "pool": 0,
+ "pool_name": "meta0",
+ "pg_num_target": 32,
+ "capacity_ratio": 0.1,
+ "root_id": 0,
+ "expected_final_pg_target": 32,
+ "expected_final_ratio": 0.1,
+ "expected_bulk_pool": False,
+ "even_pools": True,
+ "size": 1,
+ "no_scale": False,
+ "bulk": False,
+ },
+
+ "bulk0": {
+
+ "pool": 1,
+ "pool_name": "bulk0",
+ "pg_num_target": 32,
+ "capacity_ratio": 0.5,
+ "root_id": 0,
+ "expected_final_pg_target": 128,
+ "expected_final_ratio": 0.5,
+ "expected_bulk_pool": True,
+ "even_pools": False,
+ "size": 1,
+ "no_scale": False,
+ "bulk": True,
+ },
+
+ "bulk1": {
+
+ "pool": 2,
+ "pool_name": "bulk1",
+ "pg_num_target": 32,
+ "capacity_ratio": 0.1,
+ "root_id": 0,
+ "expected_final_pg_target": 64,
+ "expected_final_ratio": 0.5,
+ "expected_bulk_pool": True,
+ "even_pools": True,
+ "size": 1,
+ "no_scale": False,
+ "bulk": True,
+ },
+
+ "bulk2": {
+
+ "pool": 3,
+ "pool_name": "bulk2",
+ "pg_num_target": 32,
+ "capacity_ratio": 0.1,
+ "root_id": 0,
+ "expected_final_pg_target": 64,
+ "expected_final_ratio": 0.5,
+ "expected_bulk_pool": True,
+ "even_pools": True,
+ "size": 1,
+ "no_scale": False,
+ "bulk": True,
+ },
+
+ }
+
+ root_map = {
+
+ 0: RootMapItem(4, 400, 400),
+ 1: RootMapItem(4, 400, 400),
+
+ }
+
+ bias = 1
+ overlapped_roots = set()
+ self.helper_test(pools, root_map, bias, overlapped_roots)
+
+ def test_uneven_pools_two_meta_two_bulk(self):
+ pools = {
+
+ "meta0": {
+
+ "pool": 0,
+ "pool_name": "meta0",
+ "pg_num_target": 32,
+ "capacity_ratio": 0.1,
+ "root_id": 0,
+ "expected_final_pg_target": 32,
+ "expected_final_ratio": 0.1,
+ "expected_bulk_pool": False,
+ "even_pools": True,
+ "size": 1,
+ "no_scale": False,
+ "bulk": False,
+ },
+
+ "meta1": {
+
+ "pool": 1,
+ "pool_name": "meta1",
+ "pg_num_target": 32,
+ "capacity_ratio": 0.1,
+ "root_id": 0,
+ "expected_final_pg_target": 32,
+ "expected_final_ratio": 0.1,
+ "expected_bulk_pool": False,
+ "even_pools": False,
+ "size": 1,
+ "no_scale": False,
+ "bulk": False,
+ },
+
+ "bulk0": {
+
+ "pool": 2,
+ "pool_name": "bulk0",
+ "pg_num_target": 32,
+ "capacity_ratio": 0.5,
+ "root_id": 0,
+ "expected_final_pg_target": 128,
+ "expected_final_ratio": 0.5,
+ "expected_bulk_pool": True,
+ "even_pools": True,
+ "size": 1,
+ "no_scale": False,
+ "bulk": True,
+ },
+
+ "bulk1": {
+
+ "pool": 3,
+ "pool_name": "bulk1",
+ "pg_num_target": 32,
+ "capacity_ratio": 0.1,
+ "root_id": 0,
+ "expected_final_pg_target": 128,
+ "expected_final_ratio": 0.5,
+ "expected_bulk_pool": True,
+ "even_pools": True,
+ "size": 1,
+ "no_scale": False,
+ "bulk": True,
+ },
+
+ }
+
+ root_map = {
+
+ 0: RootMapItem(4, 400, 400),
+ 1: RootMapItem(4, 400, 400),
+
+ }
+
+ bias = 1
+ overlapped_roots = set()
+ self.helper_test(pools, root_map, bias, overlapped_roots)
+
+ def test_uneven_pools_with_diff_roots(self):
+ pools = {
+
+ "meta0": {
+
+ "pool": 0,
+ "pool_name": "meta0",
+ "pg_num_target": 32,
+ "capacity_ratio": 0.3,
+ "root_id": 0,
+ "expected_final_pg_target": 1024,
+ "expected_final_ratio": 0.3,
+ "expected_bulk_pool": False,
+ "even_pools": False,
+ "size": 1,
+ "no_scale": False,
+ "bulk": False,
+ },
+
+ "meta1": {
+
+ "pool": 1,
+ "pool_name": "meta1",
+ "pg_num_target": 32,
+ "capacity_ratio": 0.6,
+ "root_id": 1,
+ "expected_final_pg_target": 2048,
+ "expected_final_ratio": 0.6,
+ "expected_bulk_pool": False,
+ "even_pools": False,
+ "size": 1,
+ "no_scale": False,
+ "bulk": False,
+ },
+
+ "bulk2": {
+
+ "pool": 2,
+ "pool_name": "bulk2",
+ "pg_num_target": 32,
+ "capacity_ratio": 0.6,
+ "root_id": 0,
+ "expected_final_pg_target": 2048,
+ "expected_final_ratio": 0.6,
+ "expected_bulk_pool": True,
+ "even_pools": False,
+ "size": 1,
+ "no_scale": False,
+ "bulk": True,
+ },
+
+ "bulk3": {
+
+ "pool": 3,
+ "pool_name": "test3",
+ "pg_num_target": 32,
+ "capacity_ratio": 0.1,
+ "root_id": 0,
+ "expected_final_pg_target": 1024,
+ "expected_final_ratio": 1,
+ "expected_bulk_pool": True,
+ "even_pools": True,
+ "size": 1,
+ "no_scale": False,
+ "bulk": True,
+ },
+
+ "bulk4": {
+
+ "pool": 4,
+ "pool_name": "bulk4",
+ "pg_num_target": 32,
+ "capacity_ratio": 0.4,
+ "root_id": 1,
+ "expected_final_pg_target": 2048,
+ "expected_final_ratio": 1,
+ "expected_bulk_pool": True,
+ "even_pools": True,
+ "size": 1,
+ "no_scale": False,
+ "bulk": True,
+ },
+
+ }
+
+ root_map = {
+
+ 0: RootMapItem(3, 5000, 5000),
+ 1: RootMapItem(2, 5000, 5000),
+
+ }
+
+ bias = 1
+ overlapped_roots = set()
+ self.helper_test(pools, root_map, bias, overlapped_roots)
+
+ def test_even_pools_with_diff_roots(self):
+ pools = {
+
+ "meta0": {
+
+ "pool": 0,
+ "pool_name": "meta0",
+ "pg_num_target": 32,
+ "capacity_ratio": 0.4,
+ "root_id": 0,
+ "expected_final_pg_target": 2048,
+ "expected_final_ratio": 0.4,
+ "expected_bulk_pool": False,
+ "even_pools": False,
+ "size": 1,
+ "no_scale": False,
+ "bulk": False,
+ },
+
+ "meta1": {
+
+ "pool": 1,
+ "pool_name": "meta1",
+ "pg_num_target": 32,
+ "capacity_ratio": 0.6,
+ "root_id": 1,
+ "expected_final_pg_target": 2048,
+ "expected_final_ratio": 0.6,
+ "expected_bulk_pool": False,
+ "even_pools": False,
+ "size": 1,
+ "no_scale": False,
+ "bulk": False,
+ },
+
+ "bulk1": {
+
+ "pool": 2,
+ "pool_name": "bulk1",
+ "pg_num_target": 32,
+ "capacity_ratio": 0.2,
+ "root_id": 0,
+ "expected_final_pg_target": 1024,
+ "expected_final_ratio": 0.5,
+ "expected_bulk_pool": True,
+ "even_pools": True,
+ "size": 1,
+ "no_scale": False,
+ "bulk": True,
+ },
+
+ "bulk2": {
+
+ "pool": 3,
+ "pool_name": "bulk2",
+ "pg_num_target": 32,
+ "capacity_ratio": 0.1,
+ "root_id": 0,
+ "expected_final_pg_target": 1024,
+ "expected_final_ratio": 0.5,
+ "expected_bulk_pool": True,
+ "even_pools": True,
+ "size": 1,
+ "no_scale": False,
+ "bulk": True,
+ },
+
+ "bulk3": {
+
+ "pool": 4,
+ "pool_name": "bulk4",
+ "pg_num_target": 32,
+ "capacity_ratio": 0.25,
+ "root_id": 1,
+ "expected_final_pg_target": 2048,
+ "expected_final_ratio": 1,
+ "expected_bulk_pool": True,
+ "even_pools": True,
+ "size": 1,
+ "no_scale": False,
+ "bulk": True,
+ },
+
+ }
+
+ root_map = {
+
+ 0: RootMapItem(3, 5000, 5000),
+ 1: RootMapItem(2, 5000, 5000),
+
+ }
+
+ bias = 1
+ overlapped_roots = set()
+ self.helper_test(pools, root_map, bias, overlapped_roots)
+
+ def test_uneven_pools_with_overlapped_roots(self):
+ pools = {
+
+ "test0": {
+
+ "pool": 0,
+ "pool_name": "test0",
+ "pg_num_target": 32,
+ "capacity_ratio": 0.4,
+ "root_id": 0,
+ "expected_final_pg_target": 2048,
+ "expected_final_ratio": 0.4,
+ "even_pools": False,
+ "size": 1,
+ "no_scale": True,
+ },
+
+ "test1": {
+
+ "pool": 1,
+ "pool_name": "test1",
+ "pg_num_target": 32,
+ "capacity_ratio": 0.6,
+ "root_id": 1,
+ "expected_final_pg_target": 2048,
+ "expected_final_ratio": 0.6,
+ "even_pools": False,
+ "size": 1,
+ "no_scale": True,
+ },
+
+ "test2": {
+
+ "pool": 2,
+ "pool_name": "test2",
+ "pg_num_target": 32,
+ "capacity_ratio": 0.5,
+ "root_id": 0,
+ "expected_final_pg_target": 2048,
+ "expected_final_ratio": 0.5,
+ "even_pools": False,
+ "size": 1,
+ "no_scale": True,
+ },
+
+ "test3": {
+
+ "pool": 3,
+ "pool_name": "test3",
+ "pg_num_target": 32,
+ "capacity_ratio": 0.1,
+ "root_id": 0,
+ "expected_final_pg_target": 512,
+ "expected_final_ratio": 1,
+ "even_pools": True,
+ "size": 1,
+ "no_scale": True,
+ },
+
+ "test4": {
+
+ "pool": 4,
+ "pool_name": "test4",
+ "pg_num_target": 32,
+ "capacity_ratio": 0.4,
+ "root_id": 1,
+ "expected_final_pg_target": 2048,
+ "expected_final_ratio": 1,
+ "even_pools": True,
+ "size": 1,
+ "no_scale": True,
+ },
+
+ }
+
+ root_map = {
+
+ 0: RootMapItem(3, 5000, 5000),
+ 1: RootMapItem(2, 5000, 5000),
+
+ }
+
+ bias = 1
+ overlapped_roots = {0, 1}
+ self.helper_test(pools, root_map, bias, overlapped_roots)
diff --git a/src/pybind/mgr/pg_autoscaler/tests/test_cal_ratio.py b/src/pybind/mgr/pg_autoscaler/tests/test_cal_ratio.py
new file mode 100644
index 000000000..d96671360
--- /dev/null
+++ b/src/pybind/mgr/pg_autoscaler/tests/test_cal_ratio.py
@@ -0,0 +1,37 @@
+from pg_autoscaler import effective_target_ratio
+from pytest import approx
+
+
+def check_simple_ratio(target_ratio, tot_ratio):
+ etr = effective_target_ratio(target_ratio, tot_ratio, 0, 0)
+ assert (target_ratio / tot_ratio) == approx(etr)
+ return etr
+
+
+def test_simple():
+ etr1 = check_simple_ratio(0.2, 0.9)
+ etr2 = check_simple_ratio(2, 9)
+ etr3 = check_simple_ratio(20, 90)
+ assert etr1 == approx(etr2)
+ assert etr1 == approx(etr3)
+
+ etr = check_simple_ratio(0.9, 0.9)
+ assert etr == approx(1.0)
+ etr1 = check_simple_ratio(1, 2)
+ etr2 = check_simple_ratio(0.5, 1.0)
+ assert etr1 == approx(etr2)
+
+
+def test_total_bytes():
+ etr = effective_target_ratio(1, 10, 5, 10)
+ assert etr == approx(0.05)
+ etr = effective_target_ratio(0.1, 1, 5, 10)
+ assert etr == approx(0.05)
+ etr = effective_target_ratio(1, 1, 5, 10)
+ assert etr == approx(0.5)
+ etr = effective_target_ratio(1, 1, 0, 10)
+ assert etr == approx(1.0)
+ etr = effective_target_ratio(0, 1, 5, 10)
+ assert etr == approx(0.0)
+ etr = effective_target_ratio(1, 1, 10, 10)
+ assert etr == approx(0.0)
diff --git a/src/pybind/mgr/pg_autoscaler/tests/test_overlapping_roots.py b/src/pybind/mgr/pg_autoscaler/tests/test_overlapping_roots.py
new file mode 100644
index 000000000..009019707
--- /dev/null
+++ b/src/pybind/mgr/pg_autoscaler/tests/test_overlapping_roots.py
@@ -0,0 +1,479 @@
+# python unit test
+import unittest
+from tests import mock
+import pytest
+import json
+from pg_autoscaler import module
+
+
+class OSDMAP:
+ def __init__(self, pools):
+ self.pools = pools
+
+ def get_pools(self):
+ return self.pools
+
+ def pool_raw_used_rate(pool_id):
+ return 1
+
+
+class CRUSH:
+ def __init__(self, rules, osd_dic):
+ self.rules = rules
+ self.osd_dic = osd_dic
+
+ def get_rule_by_id(self, rule_id):
+ for rule in self.rules:
+ if rule['rule_id'] == rule_id:
+ return rule
+
+ return None
+
+ def get_rule_root(self, rule_name):
+ for rule in self.rules:
+ if rule['rule_name'] == rule_name:
+ return rule['root_id']
+
+ return None
+
+ def get_osds_under(self, root_id):
+ return self.osd_dic[root_id]
+
+
+class TestPgAutoscaler(object):
+
+ def setup_method(self):
+ # a bunch of attributes for testing.
+ self.autoscaler = module.PgAutoscaler('module_name', 0, 0)
+
+ def helper_test(self, osd_dic, rules, pools, expected_overlapped_roots):
+ result = {}
+ roots = []
+ overlapped_roots = set()
+ osdmap = OSDMAP(pools)
+ crush = CRUSH(rules, osd_dic)
+ roots, overlapped_roots = self.autoscaler.identify_subtrees_and_overlaps(osdmap,
+ crush, result, overlapped_roots, roots)
+ assert overlapped_roots == expected_overlapped_roots
+
+ def test_subtrees_and_overlaps(self):
+ osd_dic = {
+ -1: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
+ -40: [11, 12, 13, 14, 15],
+ -5: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
+ }
+
+ rules = [
+ {
+ "rule_id": 0,
+ "rule_name": "data",
+ "ruleset": 0,
+ "type": 1,
+ "min_size": 1,
+ "max_size": 10,
+ "root_id": -1,
+ },
+ {
+ "rule_id": 1,
+ "rule_name": "teuthology-data-ec",
+ "ruleset": 1,
+ "type": 3,
+ "min_size": 3,
+ "max_size": 6,
+ "root_id": -5,
+ },
+ {
+ "rule_id": 4,
+ "rule_name": "rep-ssd",
+ "ruleset": 4,
+ "type": 1,
+ "min_size": 1,
+ "max_size": 10,
+ "root_id": -40,
+ },
+ ]
+ pools = {
+ 0: {
+ "pool_name": "data",
+ "pg_num_target": 1024,
+ "size": 3,
+ "crush_rule": 0,
+ "capacity_ratio": 0.1624,
+ "options": {
+ "pg_num_min": 1024,
+ },
+ "expected_final_pg_target": 1024,
+ },
+ 1: {
+ "pool_name": "metadata",
+ "pg_num_target": 64,
+ "size": 3,
+ "crush_rule": 4,
+ "capacity_ratio": 0.0144,
+ "options": {
+ "pg_num_min": 64,
+ },
+ "expected_final_pg_target": 64,
+ },
+ 4: {
+ "pool_name": "libvirt-pool",
+ "pg_num_target": 32,
+ "size": 3,
+ "crush_rule": 0,
+ "capacity_ratio": 0.0001,
+ "options": {},
+ "expected_final_pg_target": 128,
+ },
+ 93: {
+ "pool_name": ".rgw.root",
+ "pg_num_target": 32,
+ "size": 3,
+ "crush_rule": 4,
+ "capacity_ratio": 0,
+ "options": {},
+ "expected_final_pg_target": 32,
+ },
+ 94: {
+ "pool_name": "default.rgw.control",
+ "pg_num_target": 32,
+ "size": 3,
+ "crush_rule": 4,
+ "capacity_ratio": 0,
+ "options": {},
+ "expected_final_pg_target": 32,
+ },
+ 95: {
+ "pool_name": "default.rgw.meta",
+ "pg_num_target": 32,
+ "size": 3,
+ "crush_rule": 4,
+ "capacity_ratio": 0,
+ "options": {},
+ "expected_final_pg_target": 32,
+ },
+ 96: {
+ "pool_name": "default.rgw.log",
+ "pg_num_target": 32,
+ "size": 3,
+ "crush_rule": 4,
+ "capacity_ratio": 0,
+ "options": {},
+ "expected_final_pg_target": 32,
+ },
+ 97: {
+ "pool_name": "default.rgw.buckets.index",
+ "pg_num_target": 32,
+ "size": 3,
+ "crush_rule": 4,
+ "capacity_ratio": 0.0002,
+ "options": {},
+ "expected_final_pg_target": 32,
+ },
+ 98: {
+ "pool_name": "default.rgw.buckets.data",
+ "pg_num_target": 32,
+ "size": 3,
+ "crush_rule": 0,
+ "capacity_ratio": 0.0457,
+ "options": {},
+ "expected_final_pg_target": 128,
+ },
+ 99: {
+ "pool_name": "default.rgw.buckets.non-ec",
+ "pg_num_target": 32,
+ "size": 3,
+ "crush_rule": 0,
+ "capacity_ratio": 0,
+ "options": {},
+ "expected_final_pg_target": 32,
+ },
+ 100: {
+ "pool_name": "device_health_metrics",
+ "pg_num_target": 1,
+ "size": 3,
+ "crush_rule": 0,
+ "capacity_ratio": 0,
+ "options": {
+ "pg_num_min": 1
+ },
+ "expected_final_pg_target": 1,
+ },
+ 113: {
+ "pool_name": "cephfs.teuthology.meta",
+ "pg_num_target": 64,
+ "size": 3,
+ "crush_rule": 4,
+ "capacity_ratio": 0.1389,
+ "options": {
+ "pg_autoscale_bias": 4,
+ "pg_num_min": 64,
+ },
+ "expected_final_pg_target": 512,
+ },
+ 114: {
+ "pool_name": "cephfs.teuthology.data",
+ "pg_num_target": 256,
+ "size": 3,
+ "crush_rule": 0,
+ "capacity_ratio": 0.0006,
+ "options": {
+ "pg_num_min": 128,
+ },
+ "expected_final_pg_target": 1024,
+ "expected_final_pg_target": 256,
+ },
+ 117: {
+ "pool_name": "cephfs.scratch.meta",
+ "pg_num_target": 32,
+ "size": 3,
+ "crush_rule": 4,
+ "capacity_ratio": 0.0027,
+ "options": {
+ "pg_autoscale_bias": 4,
+ "pg_num_min": 16,
+ },
+ "expected_final_pg_target": 64,
+ },
+ 118: {
+ "pool_name": "cephfs.scratch.data",
+ "pg_num_target": 32,
+ "size": 3,
+ "crush_rule": 0,
+ "capacity_ratio": 0.0027,
+ "options": {},
+ "expected_final_pg_target": 128,
+ },
+ 119: {
+ "pool_name": "cephfs.teuthology.data-ec",
+ "pg_num_target": 1024,
+ "size": 6,
+ "crush_rule": 1,
+ "capacity_ratio": 0.8490,
+ "options": {
+ "pg_num_min": 1024
+ },
+ "expected_final_pg_target": 1024,
+ },
+ 121: {
+ "pool_name": "cephsqlite",
+ "pg_num_target": 32,
+ "size": 3,
+ "crush_rule": 4,
+ "capacity_ratio": 0,
+ "options": {},
+ "expected_final_pg_target": 128,
+ },
+ }
+ expected_overlapped_roots = {-40, -1, -5}
+ self.helper_test(osd_dic, rules, pools, expected_overlapped_roots)
+
+ def test_no_overlaps(self):
+ osd_dic = {
+ -1: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
+ -40: [11, 12, 13, 14, 15],
+ -5: [16, 17, 18],
+ }
+
+ rules = [
+ {
+ "rule_id": 0,
+ "rule_name": "data",
+ "ruleset": 0,
+ "type": 1,
+ "min_size": 1,
+ "max_size": 10,
+ "root_id": -1,
+ },
+ {
+ "rule_id": 1,
+ "rule_name": "teuthology-data-ec",
+ "ruleset": 1,
+ "type": 3,
+ "min_size": 3,
+ "max_size": 6,
+ "root_id": -5,
+ },
+ {
+ "rule_id": 4,
+ "rule_name": "rep-ssd",
+ "ruleset": 4,
+ "type": 1,
+ "min_size": 1,
+ "max_size": 10,
+ "root_id": -40,
+ },
+ ]
+ pools = {
+ 0: {
+ "pool_name": "data",
+ "pg_num_target": 1024,
+ "size": 3,
+ "crush_rule": 0,
+ "capacity_ratio": 0.1624,
+ "options": {
+ "pg_num_min": 1024,
+ },
+ "expected_final_pg_target": 1024,
+ },
+ 1: {
+ "pool_name": "metadata",
+ "pg_num_target": 64,
+ "size": 3,
+ "crush_rule": 4,
+ "capacity_ratio": 0.0144,
+ "options": {
+ "pg_num_min": 64,
+ },
+ "expected_final_pg_target": 64,
+ },
+ 4: {
+ "pool_name": "libvirt-pool",
+ "pg_num_target": 32,
+ "size": 3,
+ "crush_rule": 0,
+ "capacity_ratio": 0.0001,
+ "options": {},
+ "expected_final_pg_target": 128,
+ },
+ 93: {
+ "pool_name": ".rgw.root",
+ "pg_num_target": 32,
+ "size": 3,
+ "crush_rule": 4,
+ "capacity_ratio": 0,
+ "options": {},
+ "expected_final_pg_target": 32,
+ },
+ 94: {
+ "pool_name": "default.rgw.control",
+ "pg_num_target": 32,
+ "size": 3,
+ "crush_rule": 4,
+ "capacity_ratio": 0,
+ "options": {},
+ "expected_final_pg_target": 32,
+ },
+ 95: {
+ "pool_name": "default.rgw.meta",
+ "pg_num_target": 32,
+ "size": 3,
+ "crush_rule": 4,
+ "capacity_ratio": 0,
+ "options": {},
+ "expected_final_pg_target": 32,
+ },
+ 96: {
+ "pool_name": "default.rgw.log",
+ "pg_num_target": 32,
+ "size": 3,
+ "crush_rule": 4,
+ "capacity_ratio": 0,
+ "options": {},
+ "expected_final_pg_target": 32,
+ },
+ 97: {
+ "pool_name": "default.rgw.buckets.index",
+ "pg_num_target": 32,
+ "size": 3,
+ "crush_rule": 4,
+ "capacity_ratio": 0.0002,
+ "options": {},
+ "expected_final_pg_target": 32,
+ },
+ 98: {
+ "pool_name": "default.rgw.buckets.data",
+ "pg_num_target": 32,
+ "size": 3,
+ "crush_rule": 0,
+ "capacity_ratio": 0.0457,
+ "options": {},
+ "expected_final_pg_target": 128,
+ },
+ 99: {
+ "pool_name": "default.rgw.buckets.non-ec",
+ "pg_num_target": 32,
+ "size": 3,
+ "crush_rule": 0,
+ "capacity_ratio": 0,
+ "options": {},
+ "expected_final_pg_target": 32,
+ },
+ 100: {
+ "pool_name": "device_health_metrics",
+ "pg_num_target": 1,
+ "size": 3,
+ "crush_rule": 0,
+ "capacity_ratio": 0,
+ "options": {
+ "pg_num_min": 1
+ },
+ "expected_final_pg_target": 1,
+ },
+ 113: {
+ "pool_name": "cephfs.teuthology.meta",
+ "pg_num_target": 64,
+ "size": 3,
+ "crush_rule": 4,
+ "capacity_ratio": 0.1389,
+ "options": {
+ "pg_autoscale_bias": 4,
+ "pg_num_min": 64,
+ },
+ "expected_final_pg_target": 512,
+ },
+ 114: {
+ "pool_name": "cephfs.teuthology.data",
+ "pg_num_target": 256,
+ "size": 3,
+ "crush_rule": 0,
+ "capacity_ratio": 0.0006,
+ "options": {
+ "pg_num_min": 128,
+ },
+ "expected_final_pg_target": 1024,
+ "expected_final_pg_target": 256,
+ },
+ 117: {
+ "pool_name": "cephfs.scratch.meta",
+ "pg_num_target": 32,
+ "size": 3,
+ "crush_rule": 4,
+ "capacity_ratio": 0.0027,
+ "options": {
+ "pg_autoscale_bias": 4,
+ "pg_num_min": 16,
+ },
+ "expected_final_pg_target": 64,
+ },
+ 118: {
+ "pool_name": "cephfs.scratch.data",
+ "pg_num_target": 32,
+ "size": 3,
+ "crush_rule": 0,
+ "capacity_ratio": 0.0027,
+ "options": {},
+ "expected_final_pg_target": 128,
+ },
+ 119: {
+ "pool_name": "cephfs.teuthology.data-ec",
+ "pg_num_target": 1024,
+ "size": 6,
+ "crush_rule": 1,
+ "capacity_ratio": 0.8490,
+ "options": {
+ "pg_num_min": 1024
+ },
+ "expected_final_pg_target": 1024,
+ },
+ 121: {
+ "pool_name": "cephsqlite",
+ "pg_num_target": 32,
+ "size": 3,
+ "crush_rule": 4,
+ "capacity_ratio": 0,
+ "options": {},
+ "expected_final_pg_target": 128,
+ },
+ }
+ expected_overlapped_roots = set()
+ self.helper_test(osd_dic, rules, pools, expected_overlapped_roots)