]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ansible.git/commitdiff
ceph-pool: pass pg_num for pg_autoscale_mode warn main
authorChristian Brandt <cbrandt@strato.de>
Tue, 16 Sep 2025 15:33:55 +0000 (17:33 +0200)
committerSeena Fallah <seenafallah@gmail.com>
Wed, 17 Sep 2025 19:55:23 +0000 (21:55 +0200)
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 <cbrandt@strato.de>
library/ceph_pool.py
tests/library/test_ceph_pool.py

index 734fdc7f58b17d4b85838a86aca1cb2dd01c0244..651f2fc6e9dbdd80f0c047e052c9290f635434be 100644 (file)
@@ -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']])
 
index 4c22e2bcc9b3e4761423ab84dd03b12919dd0421..b3501dceb9d8c74940f3c6396a783261e65ea7fa 100644 (file)
@@ -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',