mirror of https://github.com/ceph/ceph-ansible.git
ceph-pool: add support updating crush rule of the pool
Support updating crush rule of the pool via crush rule name. Signed-off-by: Seena Fallah <seenafallah@gmail.com>pull/7601/head
parent
be9b458524
commit
d6ac0cc120
|
@ -219,6 +219,28 @@ def get_application_pool(cluster,
|
||||||
return cmd
|
return cmd
|
||||||
|
|
||||||
|
|
||||||
|
def get_crush_rule_pool(cluster,
|
||||||
|
name,
|
||||||
|
user,
|
||||||
|
user_key,
|
||||||
|
output_format='json',
|
||||||
|
container_image=None):
|
||||||
|
'''
|
||||||
|
Get crush rule type on a given pool
|
||||||
|
'''
|
||||||
|
|
||||||
|
args = ['get', name, 'crush_rule', '-f', output_format]
|
||||||
|
|
||||||
|
cmd = generate_cmd(sub_cmd=['osd', 'pool'],
|
||||||
|
args=args,
|
||||||
|
cluster=cluster,
|
||||||
|
user=user,
|
||||||
|
user_key=user_key,
|
||||||
|
container_image=container_image)
|
||||||
|
|
||||||
|
return cmd
|
||||||
|
|
||||||
|
|
||||||
def enable_application_pool(cluster,
|
def enable_application_pool(cluster,
|
||||||
name,
|
name,
|
||||||
application,
|
application,
|
||||||
|
@ -317,6 +339,12 @@ def get_pool_details(module,
|
||||||
user, # noqa: E501
|
user, # noqa: E501
|
||||||
user_key, # noqa: E501
|
user_key, # noqa: E501
|
||||||
container_image=container_image)) # noqa: E501
|
container_image=container_image)) # noqa: E501
|
||||||
|
_rc, _cmd, crush_rule, _err = exec_command(module,
|
||||||
|
get_crush_rule_pool(cluster, # noqa: E501
|
||||||
|
name, # noqa: E501
|
||||||
|
user, # noqa: E501
|
||||||
|
user_key, # noqa: E501
|
||||||
|
container_image=container_image)) # noqa: E501
|
||||||
|
|
||||||
# This is a trick because "target_size_ratio" isn't present at the same
|
# This is a trick because "target_size_ratio" isn't present at the same
|
||||||
# level in the dict
|
# level in the dict
|
||||||
|
@ -343,6 +371,8 @@ def get_pool_details(module,
|
||||||
else:
|
else:
|
||||||
out['application'] = application[0]
|
out['application'] = application[0]
|
||||||
|
|
||||||
|
out['crush_rule'] = json.loads(crush_rule.strip())['crush_rule']
|
||||||
|
|
||||||
return rc, cmd, out, err
|
return rc, cmd, out, err
|
||||||
|
|
||||||
|
|
||||||
|
@ -353,7 +383,8 @@ def compare_pool_config(user_pool_config, running_pool_details):
|
||||||
|
|
||||||
delta = {}
|
delta = {}
|
||||||
filter_keys = ['pg_num', 'pg_placement_num', 'size',
|
filter_keys = ['pg_num', 'pg_placement_num', 'size',
|
||||||
'pg_autoscale_mode', 'target_size_ratio']
|
'pg_autoscale_mode', 'target_size_ratio',
|
||||||
|
'crush_rule']
|
||||||
for key in filter_keys:
|
for key in filter_keys:
|
||||||
if (str(running_pool_details[key]) != user_pool_config[key]['value'] and # noqa: E501
|
if (str(running_pool_details[key]) != user_pool_config[key]['value'] and # noqa: E501
|
||||||
user_pool_config[key]['value']):
|
user_pool_config[key]['value']):
|
||||||
|
@ -599,6 +630,8 @@ def run_module():
|
||||||
keyring_filename = cluster + '.' + user + '.keyring'
|
keyring_filename = cluster + '.' + user + '.keyring'
|
||||||
user_key = os.path.join("/etc/ceph/", keyring_filename)
|
user_key = os.path.join("/etc/ceph/", keyring_filename)
|
||||||
|
|
||||||
|
diff = dict(before="", after="")
|
||||||
|
|
||||||
if state == "present":
|
if state == "present":
|
||||||
rc, cmd, out, err = exec_command(module,
|
rc, cmd, out, err = exec_command(module,
|
||||||
check_pool_exist(cluster,
|
check_pool_exist(cluster,
|
||||||
|
@ -625,6 +658,12 @@ def run_module():
|
||||||
if details['pg_autoscale_mode'] == 'on':
|
if details['pg_autoscale_mode'] == 'on':
|
||||||
delta.pop('pg_num', None)
|
delta.pop('pg_num', None)
|
||||||
delta.pop('pgp_num', None)
|
delta.pop('pgp_num', None)
|
||||||
|
if not module.params.get('rule_name'):
|
||||||
|
delta.pop('crush_rule', None)
|
||||||
|
|
||||||
|
for key in delta.keys():
|
||||||
|
diff['before'] += "{}: {}\n".format(key, details[key])
|
||||||
|
diff['after'] += "{}: {}\n".format(key, delta[key]['value'])
|
||||||
|
|
||||||
changed = len(delta) > 0
|
changed = len(delta) > 0
|
||||||
if changed and not module.check_mode:
|
if changed and not module.check_mode:
|
||||||
|
@ -687,7 +726,7 @@ def run_module():
|
||||||
container_image=container_image)) # noqa: E501
|
container_image=container_image)) # noqa: E501
|
||||||
|
|
||||||
exit_module(module=module, out=out, rc=rc, cmd=cmd, err=err, startd=startd,
|
exit_module(module=module, out=out, rc=rc, cmd=cmd, err=err, startd=startd,
|
||||||
changed=changed)
|
changed=changed, diff=diff)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
|
@ -248,6 +248,42 @@ class TestCephPoolModule(object):
|
||||||
|
|
||||||
assert cmd == expected_command
|
assert cmd == expected_command
|
||||||
|
|
||||||
|
def test_get_crush_rule_pool(self):
|
||||||
|
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',
|
||||||
|
'client.admin',
|
||||||
|
'-k',
|
||||||
|
'/etc/ceph/ceph.client.admin.keyring',
|
||||||
|
'--cluster',
|
||||||
|
'ceph',
|
||||||
|
'osd',
|
||||||
|
'pool',
|
||||||
|
'get',
|
||||||
|
self.fake_user_pool_config['pool_name']['value'],
|
||||||
|
'crush_rule',
|
||||||
|
'-f',
|
||||||
|
'json'
|
||||||
|
]
|
||||||
|
|
||||||
|
cmd = ceph_pool.get_crush_rule_pool(fake_cluster_name,
|
||||||
|
self.fake_user_pool_config['pool_name']['value'],
|
||||||
|
fake_user, fake_user_key, 'json',
|
||||||
|
container_image=fake_container_image_name)
|
||||||
|
|
||||||
|
assert cmd == expected_command
|
||||||
|
|
||||||
def test_enable_application_pool(self):
|
def test_enable_application_pool(self):
|
||||||
expected_command = [
|
expected_command = [
|
||||||
'podman',
|
'podman',
|
||||||
|
|
Loading…
Reference in New Issue