ceph_ec_profile: support new parameters

This commit adds the support of `crush_root` and `crush_device_class`
parameter in the `ceph_ec_profile` module.

Signed-off-by: Guillaume Abrioux <gabrioux@redhat.com>
guits-create-ec-profile
Guillaume Abrioux 2020-12-14 11:02:08 +01:00
parent c9e8b5f6e9
commit 8429ee6e8c
2 changed files with 39 additions and 7 deletions

View 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):
def create_profile(module, name, k, m, stripe_unit, crush_root, crush_device_class, cluster='ceph', force=False, container_image=None):
'''
Create a profile
'''
@ -129,6 +129,10 @@ 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_root:
args.append('crush-root={}'.format(crush_root))
if crush_device_class:
args.append('crush-device-class={}'.format(crush_device_class))
if force:
args.append('--force')
@ -162,6 +166,8 @@ def run_module():
state=dict(type='str', required=False,
choices=['present', 'absent'], default='present'),
stripe_unit=dict(type='str', required=False),
crush_root=dict(type='str', required=False),
crush_device_class=dict(type='str', required=False),
k=dict(type='str', required=False),
m=dict(type='str', required=False),
)
@ -177,6 +183,8 @@ def run_module():
cluster = module.params.get('cluster')
state = module.params.get('state')
stripe_unit = module.params.get('stripe_unit')
crush_root = module.params.get('crush_root')
crush_device_class = module.params.get('crush_device_class')
k = module.params.get('k')
m = module.params.get('m')
@ -204,13 +212,17 @@ 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_root', crush_root) != crush_root 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_root,
crush_device_class,
cluster,
force=True, container_image=container_image))
changed = True
@ -221,6 +233,8 @@ def run_module():
k,
m,
stripe_unit,
crush_root,
crush_device_class,
cluster,
container_image=container_image))
if rc == 0:

View File

@ -28,11 +28,23 @@ 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_root,crush_device_class,force", [(8192, None, None, True),
(8192, None, None, False),
(8192, None, 'hdd', True),
(8192, None, 'hdd', False),
(8192, 'hdd', None, True),
(8192, 'hdd', None, False),
(8192, 'hdd', 'hdd', True),
(8192, 'hdd', 'hdd', False),
(None, None, None, True),
(None, None, None, False),
(None, None, 'hdd', True),
(None, None, 'hdd', False),
(None, 'hdd', None, True),
(None, 'hdd', None, False),
(None, 'hdd', 'hdd', True),
(None, 'hdd', 'hdd', False)])
def test_create_profile(self, stripe_unit, crush_root, crush_device_class, force):
expected_cmd = [
self.fake_binary,
'-n', 'client.admin',
@ -44,6 +56,10 @@ class TestCephEcProfile(object):
]
if stripe_unit:
expected_cmd.append('stripe_unit={}'.format(stripe_unit))
if crush_root:
expected_cmd.append('crush-root={}'.format(crush_root))
if crush_device_class:
expected_cmd.append('crush-device-class={}'.format(crush_device_class))
if force:
expected_cmd.append('--force')
@ -52,6 +68,8 @@ class TestCephEcProfile(object):
self.fake_k,
self.fake_m,
stripe_unit,
crush_root,
crush_device_class,
self.fake_cluster,
force) == expected_cmd