From 1a613004e3fb3804f26a60369cec32ef9255bd2d Mon Sep 17 00:00:00 2001 From: Christian Brandt Date: Tue, 16 Sep 2025 17:33:55 +0200 Subject: [PATCH] ceph-pool: pass pg_num for pg_autoscale_mode warn The pg_autoscale_mode parameter has three possible values 'on', 'off', and 'warn'. In case of 'warn' it should be possible to pass the number of placement groups (pg_num) to the create_pool function. Nothing is lost by allowing this. The health check will still warn if the value needs adjustment. The evaluation of target_size_ratio works as before. Add a test iterating through possible value combinations of the parameters target_size_ratio, pg_num and pg_autoscale_mode. Signed-off-by: Christian Brandt (cherry picked from commit 31ad2a336c2cfe0963d5352eb42b51914ba08e24) --- library/ceph_pool.py | 6 ++-- tests/library/test_ceph_pool.py | 60 +++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/library/ceph_pool.py b/library/ceph_pool.py index 734fdc7f5..651f2fc6e 100644 --- a/library/ceph_pool.py +++ b/library/ceph_pool.py @@ -441,13 +441,15 @@ def create_pool(cluster, args = ['create', user_pool_config['pool_name']['value'], user_pool_config['type']['value']] - if user_pool_config['pg_autoscale_mode']['value'] == 'off': + pg_autoscale_mode = user_pool_config['pg_autoscale_mode']['value'] + if pg_autoscale_mode in ['off', 'warn']: args.extend(['--pg_num', user_pool_config['pg_num']['value'], '--pgp_num', user_pool_config['pgp_num']['value'] or user_pool_config['pg_num']['value']]) - elif user_pool_config['target_size_ratio']['value']: + + if pg_autoscale_mode in ['on', 'warn'] and user_pool_config['target_size_ratio']['value']: args.extend(['--target_size_ratio', user_pool_config['target_size_ratio']['value']]) diff --git a/tests/library/test_ceph_pool.py b/tests/library/test_ceph_pool.py index 4c22e2bcc..b3501dceb 100644 --- a/tests/library/test_ceph_pool.py +++ b/tests/library/test_ceph_pool.py @@ -669,6 +669,66 @@ class TestCephPoolModule(object): assert cmd == expected_command + @pytest.mark.parametrize("target_size_ratio", ['', '0.3']) + @pytest.mark.parametrize("pg_num", ['0', '32']) + @pytest.mark.parametrize("pg_autoscale_mode", ["on", "off", "warn"]) + def test_create_pool_autoscale_pgnum_targetsize(self, pg_autoscale_mode, pg_num, target_size_ratio): + self.fake_user_pool_config['type']['value'] = 'erasure' + self.fake_user_pool_config['erasure_profile']['value'] = 'erasure-default' + self.fake_user_pool_config['crush_rule']['value'] = 'erasure_rule' + self.fake_user_pool_config['pg_autoscale_mode']['value'] = pg_autoscale_mode + self.fake_user_pool_config['pg_num']['value'] = pg_num + self.fake_user_pool_config['pgp_num']['value'] = pg_num + self.fake_user_pool_config['target_size_ratio']['value'] = target_size_ratio + + expected_command = [ + 'podman', + 'run', + '--rm', + '--net=host', + '-v', + '/etc/ceph:/etc/ceph:z', + '-v', + '/var/lib/ceph/:/var/lib/ceph/:z', + '-v', + '/var/log/ceph/:/var/log/ceph/:z', + '--entrypoint=ceph', + fake_container_image_name, + '-n', + fake_user, + '-k', + fake_user_key, + '--cluster', + fake_cluster_name, + 'osd', + 'pool', + 'create', + self.fake_user_pool_config['pool_name']['value'], + self.fake_user_pool_config['type']['value'], + ] + + if pg_autoscale_mode in ['off', 'warn']: + expected_command.extend(['--pg_num', pg_num]) + expected_command.extend(['--pgp_num', pg_num]) + + if pg_autoscale_mode in ['on', 'warn'] and target_size_ratio: + expected_command.extend(['--target_size_ratio', target_size_ratio]) + + expected_command.extend([ + self.fake_user_pool_config['erasure_profile']['value'], + self.fake_user_pool_config['crush_rule']['value'], + '--expected_num_objects', + self.fake_user_pool_config['expected_num_objects']['value'], + '--autoscale-mode', + self.fake_user_pool_config['pg_autoscale_mode']['value'] + ]) + + cmd = ceph_pool.create_pool(fake_cluster_name, + fake_user, fake_user_key, self.fake_user_pool_config, + container_image=fake_container_image_name) + + assert cmd == expected_command + def test_remove_pool(self): expected_command = [ 'podman', -- 2.39.5