]> git.apps.os.sepia.ceph.com Git - ceph-ansible.git/commitdiff
library/ceph_ec_profile.py: Support CRUSH device class
authorBenoît Knecht <bknecht@protonmail.ch>
Tue, 26 Oct 2021 13:49:33 +0000 (15:49 +0200)
committerGuillaume Abrioux <gabrioux@redhat.com>
Wed, 1 Dec 2021 07:39:14 +0000 (08:39 +0100)
The `crush_device_class` option of the `ceph_ec_profile` module was documented
but not implemented.

This commit adds it and ensures its value is updated on the corresponding EC
profile.

Signed-off-by: Benoît Knecht <bknecht@protonmail.ch>
library/ceph_ec_profile.py
tests/library/test_ceph_ec_profile.py

index 183d2c5d0ec83d7efbf9bdf8896b6bc3054f3a44..c37b7b612c652824dc284ebb3919793cb0c652cd 100644 (file)
@@ -121,7 +121,7 @@ def get_profile(module, name, cluster='ceph', container_image=None):
     return cmd
 
 
-def create_profile(module, name, k, m, stripe_unit, cluster='ceph', force=False, container_image=None):  # noqa: E501
+def create_profile(module, name, k, m, stripe_unit, crush_device_class, cluster='ceph', force=False, container_image=None):  # noqa: E501
     '''
     Create a profile
     '''
@@ -129,6 +129,8 @@ def create_profile(module, name, k, m, stripe_unit, cluster='ceph', force=False,
     args = ['set', name, 'k={}'.format(k), 'm={}'.format(m)]
     if stripe_unit:
         args.append('stripe_unit={}'.format(stripe_unit))
+    if crush_device_class:
+        args.append('crush-device-class={}'.format(crush_device_class))
     if force:
         args.append('--force')
 
@@ -164,6 +166,7 @@ def run_module():
         stripe_unit=dict(type='str', required=False),
         k=dict(type='str', required=False),
         m=dict(type='str', required=False),
+        crush_device_class=dict(type='str', required=False, default=''),
     )
 
     module = AnsibleModule(
@@ -179,6 +182,7 @@ def run_module():
     stripe_unit = module.params.get('stripe_unit')
     k = module.params.get('k')
     m = module.params.get('m')
+    crush_device_class = module.params.get('crush_device_class')
 
     if module.check_mode:
         module.exit_json(
@@ -205,13 +209,15 @@ def run_module():
             current_profile = json.loads(out)
             if current_profile['k'] != k or \
                current_profile['m'] != m or \
-               current_profile.get('stripe_unit', stripe_unit) != stripe_unit:
+               current_profile.get('stripe_unit', stripe_unit) != stripe_unit or \
+               current_profile.get('crush-device-class', crush_device_class) != crush_device_class:
                 rc, cmd, out, err = exec_command(module,
                                                  create_profile(module,
                                                                 name,
                                                                 k,
                                                                 m,
                                                                 stripe_unit,
+                                                                crush_device_class,  # noqa: E501
                                                                 cluster,
                                                                 force=True, container_image=container_image))  # noqa: E501
                 changed = True
@@ -222,6 +228,7 @@ def run_module():
                                                                     k,
                                                                     m,
                                                                     stripe_unit,  # noqa: E501
+                                                                    crush_device_class,  # noqa: E501
                                                                     cluster,
                                                                     container_image=container_image))  # noqa: E501
             if rc == 0:
index 00c6e13170e64460aa3e7594fd35d9a9f26fb186..955148f5722b63dfbb884d52497414a467660c89 100644 (file)
@@ -28,11 +28,15 @@ class TestCephEcProfile(object):
 
         assert ceph_ec_profile.get_profile(self.fake_module, self.fake_name) == expected_cmd
 
-    @pytest.mark.parametrize("stripe_unit,force", [(False, False),
-                                                   (32, True),
-                                                   (False, True),
-                                                   (32, False)])
-    def test_create_profile(self, stripe_unit, force):
+    @pytest.mark.parametrize("stripe_unit,crush_device_class,force", [(False, None, False),
+                                                                      (32, None, True),
+                                                                      (False, None, True),
+                                                                      (32, None, False),
+                                                                      (False, 'hdd', False),
+                                                                      (32, 'ssd', True),
+                                                                      (False, 'nvme', True),
+                                                                      (32, 'hdd', False)])
+    def test_create_profile(self, stripe_unit, crush_device_class, force):
         expected_cmd = [
             self.fake_binary,
             '-n', 'client.admin',
@@ -44,6 +48,8 @@ class TestCephEcProfile(object):
         ]
         if stripe_unit:
             expected_cmd.append('stripe_unit={}'.format(stripe_unit))
+        if crush_device_class:
+            expected_cmd.append('crush-device-class={}'.format(crush_device_class))
         if force:
             expected_cmd.append('--force')
 
@@ -52,6 +58,7 @@ class TestCephEcProfile(object):
                                               self.fake_k,
                                               self.fake_m,
                                               stripe_unit,
+                                              crush_device_class,
                                               self.fake_cluster,
                                               force) == expected_cmd